Worktree sessions report the wrong branch in the system prompt
Summary
When a Claude Code session is started inside a git worktree, the system prompt gitStatus block reports a Current branch that doesn't match the worktree actual checked-out branch.
What it reports instead: the branch the main clone happened to be on at the moment the worktree was created. That value gets frozen into the worktree session metadata and never updated.
Repro
Any Claude Code session whose cwd is inside a git worktree directory exhibits this. The gitStatus block reports the main clone branch (the one checked out in the original repo directory) as Current branch, instead of the worktree actual HEAD.
Evidence from JSONL
The session state file at the per-project projects directory records two distinct branch fields in the worktree-state record:
- worktreeBranch: actual checkout in the worktree (correct)
- originalBranch: branch checked out in the main clone at worktree-creation time (frozen snapshot)
The per-message gitBranch field, and the system-prompt gitStatus Current branch line, both source from originalBranch instead of the live worktree HEAD.
Expected
The harness should ask git directly what branch the worktree is on, every time it builds the system prompt. Right now it is reading the answer from a value saved when the worktree was first created -- that value never updates.
Why it matters
Agents trust the system-prompt header as ground truth. When it is wrong:
- An agent may believe an active scope is in flight when it is not, and skip the kickoff step.
- An agent may push to or operate on a branch that has already been merged.
- The mismatch is silent -- no warning.
Diagnosis trail with full JSONL evidence: karyandrew/second-brain#301
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗