claude-code - 💡(How to fix) Fix [BUG] PR shortcut indicator shows ghost branch from deleted worktree, persists across full restart (Windows) [1 comments, 2 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#53123Fetched 2026-04-26 05:23:48
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

Fix Action

Fix / Workaround

Reproduction

  1. A previous Claude Code agent dispatch created an isolated worktree (claude/<adjective-name> branch + .claude/worktrees/<name>/ directory).
  2. The worktree got torn down externally (directory removed, branch deleted, no .git/worktrees/ metadata leftover).
  3. On next claude --resume, the hook fires:

    The git worktree at D:\Proyectos\BuildCalc Pro.claude\worktrees\practical-austin was deleted. This session now operates on the origin repository at D:\Proyectos\BuildCalc Pro.

  4. Despite operating on origin (verified by pwd, git branch --show-current, both reporting master), the TUI PR shortcut indicator renders master ← claude/practical-austin +1 -0 [Create PR].
  5. Survives Ctrl+C + relaunch and full process kill + relaunch from origin path.

Workaround tried None confirmed. Starting a brand-new session (no --resume/-c) is likely the only escape hatch but loses conversation context.

Code Example

master ← claude/practical-austin   +1 -0   [Create PR]
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report
  • I am using the latest version of Claude Code (2.1.81)

What's Wrong?

Summary After a Claude Code-managed git worktree is deleted (via the system's worktree teardown — confirmed by the SessionStart:resume hook message "The git worktree at <path> was deleted. This session now operates on the origin repository at <origin>"), the TUI's PR shortcut indicator continues to show the deleted worktree's branch name as if it were the current branch:

master ← claude/practical-austin   +1 -0   [Create PR]

The branch does not exist anywhere on disk.

Environment

  • Claude Code version: 2.1.81
  • OS: Windows 11
  • Shell: PowerShell 5.1 (also reproduced via Git Bash for git ops)
  • Repo: standard single-worktree git repo, branch master

Reproduction

  1. A previous Claude Code agent dispatch created an isolated worktree (claude/<adjective-name> branch + .claude/worktrees/<name>/ directory).
  2. The worktree got torn down externally (directory removed, branch deleted, no .git/worktrees/ metadata leftover).
  3. On next claude --resume, the hook fires:

    The git worktree at D:\Proyectos\BuildCalc Pro.claude\worktrees\practical-austin was deleted. This session now operates on the origin repository at D:\Proyectos\BuildCalc Pro.

  4. Despite operating on origin (verified by pwd, git branch --show-current, both reporting master), the TUI PR shortcut indicator renders master ← claude/practical-austin +1 -0 [Create PR].
  5. Survives Ctrl+C + relaunch and full process kill + relaunch from origin path.

Expected behavior After worktree teardown, the PR shortcut indicator should either:

  • Re-detect git state from on-disk .git/HEAD and show the actual current branch (master), or
  • Hide entirely if no comparison branch is detectable.

Actual behavior The indicator persists indefinitely with the now-non-existent branch. Clicking "Create PR" would presumably attempt to operate on a branch that doesn't exist (not tested to avoid pollution).

Verification that the branch is gone

  • git symbolic-ref HEADrefs/heads/master
  • cat .git/HEADref: refs/heads/master
  • git show-ref | grep practical-austin → empty
  • ls .git/refs/heads/claude/ → only other adjective-name branches, no practical-austin
  • .git/worktrees/ directory does not exist (no orphan worktree metadata)
  • .git/packed-refs does not contain it
  • git reflog --all | grep practical-austin → empty
  • Worktree directory .claude/worktrees/practical-austin/ has been deleted
  • Removed the stale ~/.claude.json project entry for the worktree path → no effect on the indicator
  • grep -rln "practical-austin" ~/.claude/ returns only backups/.claude.json.backup.* and historical session JSONLs (no live config files)

Diagnostic hypothesis The active session sub-directory contains only the tool-results/ hook output (no session metadata yet). The historical worktree session JSONL at ~/.claude/projects/D--Proyectos-BuildCalc-Pro--claude-worktrees-<name>/<session-id>.jsonl still has "gitBranch":"claude/<name>" baked into every entry. Plausible cause: TUI reads cached gitBranch from a session-metadata index (e.g., sessions-index.json referenced in #25032) rather than from live git symbolic-ref HEAD.

Workaround tried None confirmed. Starting a brand-new session (no --resume/-c) is likely the only escape hatch but loses conversation context.

Related

  • #25032 (sessions-index.json staleness)
  • #48270 (claude --resume picks stale branch — different angle, same area)
  • #26725 (stale worktrees never cleaned up)

extent analysis

TL;DR

The most likely fix is to update the session metadata index to reflect the current branch after a worktree is deleted.

Guidance

  • Investigate the session-metadata index (e.g., sessions-index.json) to see if it's caching the outdated gitBranch value.
  • Verify that the gitBranch value in the historical worktree session JSONL files is updated to reflect the current branch (master) after the worktree is deleted.
  • Check if the TUI is using the cached gitBranch value from the session-metadata index instead of querying the live git symbolic-ref HEAD value.
  • Consider implementing a mechanism to update the session-metadata index when a worktree is deleted to prevent stale branch information.

Example

No code snippet is provided as the issue is more related to the internal workings of the Claude Code tool and its interaction with Git.

Notes

The issue seems to be related to the caching of session metadata and the TUI not updating to reflect the current branch after a worktree is deleted. The provided diagnostic hypothesis and related issues suggest that this is a known problem area.

Recommendation

Apply a workaround by starting a brand-new session (no --resume/-c) to lose conversation context, as this is the only confirmed escape hatch. A more permanent fix would require updating the session metadata index to reflect the current branch after a worktree is deleted.

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