feat: add pre-spawn freshness hook to auto-fetch main before agent spawn #197
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ldraney/claude-custom!197
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "193-pre-spawn-freshness-hook"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds a PreToolUse hook that automatically fetches and fast-forwards local main before every agent spawn, preventing worktrees from branching off stale code. Best-effort only -- never blocks.
Changes
hooks/pre-spawn-freshness.sh-- new hook that detects the repo remote (forgejo preferred, origin fallback), fetches main, and fast-forwards viagit update-refif local is behindsettings.json-- registers the hook on the Task matcher, beforecheck-agent-spawn.shTest Plan
promptfield): exits 0 silently/tmp): exits 0 silently[pre-spawn-freshness] Updated local main to <sha>echo '{"tool_input":{"prompt":"test","subagent_type":"dev"},"cwd":"/home/ldraney/claude-custom"}' | bash hooks/pre-spawn-freshness.shReview Checklist
Related Notes
Related
Closes #193
PR #197 Review
DOMAIN REVIEW
Tech stack: Bash hooks for Claude Code PreToolUse system, JSON configuration (settings.json).
Hook quality (pre-spawn-freshness.sh):
INPUT=$(cat),jqparsing,set -euo pipefail, fail-open exit 0 on every non-applicable or error path.forgejoremote name, fall back toorigin) is not a DRY violation withforgejo-helper.sh. The helper detects Forgejo by URL hostname for API access; this hook detects by remote name for fetch targeting. Different concerns.merge-base --is-ancestorguard (line 58) prevents force-updates on diverged history. Theupdate-refcall with the old-value CAS parameter (line 62) prevents TOCTOU races. This is notably more robust than the existingpost-merge-rebase.shandpost-mcp-merge-rebase.sh, which both lack the ancestor check and CAS old-value.settings.json change:
Taskmatcher, beforecheck-agent-spawn.sh. Ordering is correct: freshness must happen before spawn validation so the agent branches from up-to-date main.BLOCKERS
None.
NITS
Existing hooks would benefit from the same robustness:
post-merge-rebase.sh(line 61) andpost-mcp-merge-rebase.sh(line 57) both callupdate-refwithout the ancestor check or old-value CAS that this new hook correctly includes. Not in scope for this PR, but worth a follow-up ticket to backport the safety pattern. (File paths:/home/ldraney/claude-custom/hooks/post-merge-rebase.sh,/home/ldraney/claude-custom/hooks/post-mcp-merge-rebase.sh.)Existing post-merge hooks hardcode
origin: Bothpost-merge-rebase.shandpost-mcp-merge-rebase.shhardcodeoriginas the remote. This new hook's forgejo-preferred remote detection pattern would improve those hooks too. Again, out of scope -- just noting the improvement opportunity.Minor: stderr log uses Unicode em dash: Line 6 comment uses a Unicode em dash (
—). Harmless but inconsistent with hooks likecheck-agent-spawn.shwhich use ASCII dashes. Not worth changing.SOP COMPLIANCE
193-pre-spawn-freshness-hookfollows{issue-num}-{kebab-slug}Closes #193PROCESS OBSERVATIONS
VERDICT: APPROVED
5d7f650784tob116da1dd8