[Bug] Subagents report canonical paths instead of worktree paths, causing edits to land in wrong tree

Resolved 💬 2 comments Opened Jun 20, 2026 by garrettmc Closed Jun 24, 2026

Bug Description
Title: Subagents report canonical (main-tree) absolute paths when running in a git worktree, causing edits to land in the wrong tree

Environment: Claude Code launched with the worktree argument; CWD correctly set to .../.claude/worktrees/<name>. Repo has a main checkout and a linked worktree on a separate branch.

What happened:

  1. Session was correctly anchored to the worktree (CWD, git branch, env all pointed at the worktree).
  2. An Explore subagent was spawned to locate code. It reported findings as absolute paths into the main checkout (/Users/.../<repo>/src/...), not the worktree path and not repo-relative paths — apparently realpath/canonical-resolved.
  3. Acting on those paths, Edit/Write modified files in the main tree instead of the worktree. No error surfaced because both paths are valid files.
  4. Tests run via an absolute path also resolved to the main tree and passed, giving no signal the edits were misplaced.
  5. The mistake was only caught because the user noticed git status in the worktree showed no changes.

Expected: When the session runs in a worktree, subagents should anchor their reported paths to the worktree root (or report repo-relative paths), so downstream edits stay within the intended tree.

Impact: Silent cross-tree edits. The worktree isolation feature's main guarantee — that work stays in the isolated copy — is broken when subagents are involved. Easy to miss; no tool-level error.

Suggested fixes (any of):

  • Have subagents inherit and report against the worktree path rather than the canonical repo path.
  • Surface a warning when an Edit/Write target falls outside the active worktree.
  • Prefer repo-relative path reporting from subagents.

Environment Info

  • Platform: darwin
  • Terminal: iTerm.app
  • Version: 2.1.169
  • Feedback ID: b4198892-6765-4da6-bf5a-e321f7dacd83

Errors

[]

View original on GitHub ↗

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