claude-code - 💡(How to fix) Fix gitStatus context reports wrong branch when launched with -w <worktree> [2 comments, 3 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#54072Fetched 2026-04-28 06:39:58
View on GitHub
Comments
2
Participants
3
Timeline
5
Reactions
0
Timeline (top)
labeled ×3commented ×2
RAW_BUFFERClick to expand / collapse

When launching Claude Code with claude -w <worktree-name>, the session's CWD is correctly set to the worktree directory, but the gitStatus snapshot in the initial system context reports the branch of the main checkout rather than the worktree's branch.

Repro:

  1. In a repo with a worktree (e.g. .claude/worktrees/my-worktree) checked out to branch B, with the main checkout on branch A.
  2. Launch claude -w my-worktree.
  3. Ask Claude what branch it's on — it will answer with A (from the stale gitStatus snapshot).
  4. Running git branch --show-current correctly reports B.

Expected: gitStatus reflects the branch of the worktree the session was launched into.

Impact: Claude answers questions about current branch state incorrectly until it runs a git command, since it trusts the initial snapshot.

extent analysis

TL;DR

Update the gitStatus snapshot to reflect the worktree's branch after launching Claude Code with a specific worktree.

Guidance

  • Verify that the gitStatus snapshot is being updated correctly after running a git command, as this is when Claude starts reporting the correct branch.
  • Check if there's an option to refresh the gitStatus snapshot manually after launching Claude Code with a worktree.
  • Investigate how Claude Code initializes the gitStatus snapshot and see if it can be modified to use the worktree's branch instead of the main checkout's branch.
  • Consider running a git command immediately after launching Claude Code to force an update of the gitStatus snapshot.

Example

No code snippet is provided as the issue does not contain enough information about the implementation details of Claude Code.

Notes

The issue seems to be related to how Claude Code initializes its gitStatus snapshot. Without more information about the implementation, it's difficult to provide a definitive fix.

Recommendation

Apply a workaround by running a git command immediately after launching Claude Code to force an update of the gitStatus snapshot, as this is when Claude starts reporting the correct branch.

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 gitStatus context reports wrong branch when launched with -w <worktree> [2 comments, 3 participants]