gitBranch session metadata not refreshed after working directory changes

Resolved 💬 4 comments Opened Jan 23, 2026 by corylanou Closed Jan 27, 2026

Summary

The gitBranch session metadata is captured once at session initialization and never refreshed when the working directory changes. This causes Claude to receive stale branch context even when working in a different git worktree.

Reproduction Steps

  1. Start a Claude Code session in a git repo on main branch
  2. Use a skill/command that creates a new git worktree and changes directory into it (e.g., git worktree add ../my-feature feature-branch && cd ../my-feature)
  3. Continue working in the session
  4. Observe that Claude makes commits to main instead of the feature branch

Evidence from Session Transcripts

Session 1 (ea466951):

Total entries with "gitBranch":"main": 409
Entries with cwd in worktree:          399 (97%)
Entries with cwd in main repo:          10

Session 2 (7a40a9ef):

Total entries with "gitBranch":"main": 704
Entries with cwd in worktree:           34
Entries with cwd in main repo:         670

Example metadata showing the mismatch:

{
  "cwd": "/path/to/repo-issue-1032-feature-branch",
  "gitBranch": "main",
  "version": "2.1.17",
  "timestamp": "2026-01-23T15:13:09.409Z"
}

The cwd correctly shows the worktree directory, but gitBranch still reports "main".

Expected Behavior

gitBranch should be re-evaluated after:

  • cd commands that change to a different git repository/worktree
  • git checkout / git switch commands
  • git worktree add commands
  • Any bash command that could change git context

Impact

  • Severity: High - Users relying on worktree workflows have changes committed to wrong branches
  • This is a regression - the same workflows were working correctly before
  • Users have no reliable workaround other than manually verifying branch before every commit

Environment

  • Claude Code version: 2.1.17
  • Platform: macOS (Darwin 25.1.0)
  • Workflow: Using custom skills that create worktrees via /go-workflow:start-issue

Additional Context

The debug logs show the terminal prompt changing correctly when entering the worktree, but the session metadata (gitBranch) is never updated to reflect the new git context.

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗