Context compaction loses absolute paths, causing wrong directory operations after compaction

Resolved 💬 3 comments Opened Feb 1, 2026 by apokamo Closed Feb 5, 2026

Bug Description

When working in a git worktree with absolute paths, context compaction converts these paths to relative paths in the summary. After compaction, since Bash cwd resets to the original working directory, subsequent file operations target the wrong directory.

Steps to Reproduce

  1. Start Claude Code in main repository (e.g., /home/user/project)
  2. Create and switch to a git worktree (e.g., /home/user/project-fix-123)
  3. Perform file operations using absolute worktree paths
  4. Continue working until context compaction occurs
  5. After compaction, file operations target main repository instead of worktree

Expected Behavior

Context compaction summary should preserve absolute paths, especially when they differ from the current working directory.

Actual Behavior

The compaction summary converts absolute paths to relative paths:

Before compaction (line 340 of transcript):

Read file: /home/user/project-fix-123/apps/api/module/mapper.py

After compaction (line 345 - summary):

Was implementing in `apps/api/module/mapper.py`
Edit `apps/api/module/mapper.py` to add...

After compaction (line 350+):

Read file: /home/user/project/apps/api/module/mapper.py  # Wrong path!

The worktree absolute path /home/user/project-fix-123/ is completely lost in the summary.

Impact

  • Code changes applied to wrong branch (main instead of feature branch)
  • Commits made to wrong repository
  • Significant token waste from having to redo work
  • Potential for accidentally pushing wrong changes

Environment

  • Claude Code version: 2.1.29
  • OS: Linux (WSL2)
  • Model: claude-opus-4-5-20251101

Workaround

Added explicit instructions in custom skill files to always use absolute paths, but this doesn't prevent the compaction summary from losing path information.

Evidence

Full transcript available showing the path switch after compaction. The transcript clearly shows:

  1. Correct worktree path used before compaction
  2. Summary generated without absolute path
  3. Wrong main path used after compaction

Additional Context

This issue was more frequent in earlier versions but still occurs. The combination of:

  1. Bash cwd resetting after each command
  2. Context compaction losing absolute paths

Creates a particularly problematic failure mode for worktree-based workflows.

View original on GitHub ↗

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