claude-code - 💡(How to fix) Fix Worktree archive prompt's git status check races SessionEnd hooks [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#57763Fetched 2026-05-11 03:26:03
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×4

Root Cause

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.

Fix Action

Fix / Workaround

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.

RAW_BUFFERClick to expand / collapse

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

  1. Worktree on a multi-vault setup with a SessionEnd hook that stages + commits worktree files identical to main.
  2. Edit a tracked worktree file, then revert via git checkout (or have an external sync produce a byte-identical copy).
  3. 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

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Worktree archive prompt's git status check races SessionEnd hooks [1 participants]