Worktree archive prompt's git status check races SessionEnd hooks
Problem
When archiving a worktree, the "N uncommitted changes will be permanently discarded" prompt runs a git status check BEFORE the SessionEnd hook chain fires. SessionEnd hooks designed to clean up byte-identical-to-main duplicates (or any pre-archive tidy work) never get the chance to run before the user sees the warning.
Concrete failure: I have a reconcile-worktree-shared.py SessionEnd hook that auto-stages and commits worktree files that are byte-identical to a sibling main vault. After every session, the worktree should look clean. Instead, the archive prompt always shows files as uncommitted, because the prompt's status check runs before SessionEnd fires.
Workaround I shipped: register the same cleanup as a Stop hook so it fires every assistant turn. Works, but it runs git status continuously even when the user has no intent to archive. Expensive on large worktrees, and the Stop hook still has its own race window between turns.
Expected
SessionEnd hooks should fire BEFORE the archive prompt's git status check. Then the prompt only warns about real drift, not transient duplicates.
Why it matters
False-positive archive warnings train the eye to dismiss them. The day a real loss occurs (genuine uncommitted work the user forgot about), the warning gets the same dismissive click. The fix is precise: drain the cleanup queue first, then check for actual loss.
Possible additions
A new hook event scoped to archive specifically (PreArchive?) would let users place cleanup logic exactly at the right moment without paying the per-turn Stop-hook cost. SessionEnd is too broad for some cleanup work; Stop is too frequent.
Repro
- Worktree on a multi-vault setup with a SessionEnd hook that stages + commits worktree files identical to main.
- Edit a tracked worktree file, then revert via git checkout (or have an external sync produce a byte-identical copy).
- Try to archive. Warning fires, even though SessionEnd would have cleaned the index entry.
Environment
- Claude Code 2.1.128, macOS
- Worktree set up via
worktree.baseRef: head
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗