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

  1. Start a Claude Code session inside a git worktree (e.g., .claude/worktrees/exciting-antonelli/)
  2. The git status header correctly shows the worktree branch: Current branch: claude/exciting-antonelli
  3. Work until the context window fills and the conversation is compacted/summarized
  4. After compaction, the continuation message shows Primary working directory: /Users/.../Projects/AAT (the project root, not the worktree)
  5. 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 main that should have been on claude/exciting-antonelli

Environment

  • Claude Code CLI
  • macOS Darwin 25.3.0
  • Git worktrees via .claude/worktrees/
  • Model: claude-opus-4-6

View original on GitHub ↗

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