Context compaction resets working directory, losing worktree state
Resolved 💬 5 comments Opened Feb 23, 2026 by gdavis1361 Closed Mar 25, 2026
Bug Description
When a conversation runs out of context and gets compacted/summarized for continuation, the working directory resets to the project root instead of preserving the worktree path. This causes all subsequent edits to land on the wrong branch.
Steps to Reproduce
- Start a Claude Code session inside a git worktree (e.g.,
.claude/worktrees/exciting-antonelli/) - The git status header correctly shows the worktree branch:
Current branch: claude/exciting-antonelli - Work until the context window fills and the conversation is compacted/summarized
- After compaction, the continuation message shows
Primary working directory: /Users/.../Projects/AAT(the project root, not the worktree) - All subsequent tool calls (Read, Edit, Write, Bash) operate against the project root on
main, not the worktree branch
Expected Behavior
After context compaction, the working directory should remain at the worktree path that was active when compaction occurred. The gitStatus in the continuation should reflect the worktree branch, not the main branch.
Actual Behavior
The working directory silently resets to the project root. The gitStatus shows main branch. All edits land on the wrong branch with no warning.
Impact
- Edits intended for a feature branch land on
main - The user doesn't realize the branch switch happened (no visible indicator)
- Changes have to be manually moved between branches after the fact
- In our case, ~6 files were edited on
mainthat should have been onclaude/exciting-antonelli
Environment
- Claude Code CLI
- macOS Darwin 25.3.0
- Git worktrees via
.claude/worktrees/ - Model: claude-opus-4-6
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗