[BUG] PR shortcut indicator shows ghost branch from deleted worktree, persists across full restart (Windows)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report
- [x] 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
- A previous Claude Code agent dispatch created an isolated worktree (
claude/<adjective-name>branch +.claude/worktrees/<name>/directory). - The worktree got torn down externally (directory removed, branch deleted, no
.git/worktrees/metadata leftover). - 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.
- Despite operating on origin (verified by
pwd,git branch --show-current, both reportingmaster), the TUI PR shortcut indicator rendersmaster ← claude/practical-austin +1 -0 [Create PR]. - 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/HEADand 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 HEAD→refs/heads/mastercat .git/HEAD→ref: refs/heads/mastergit show-ref | grep practical-austin→ emptyls .git/refs/heads/claude/→ only other adjective-name branches, nopractical-austin.git/worktrees/directory does not exist (no orphan worktree metadata).git/packed-refsdoes not contain itgit reflog --all | grep practical-austin→ empty- Worktree directory
.claude/worktrees/practical-austin/has been deleted - Removed the stale
~/.claude.jsonproject entry for the worktree path → no effect on the indicator grep -rln "practical-austin" ~/.claude/returns onlybackups/.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)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗