[BUG] Subagents / Explore use stale isolated worktree instead of parent repo HEAD

Resolved 💬 4 comments Opened Apr 16, 2026 by Cloud370 Closed May 25, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When launching a subagent or Explore from a local git repository, the subagent's default repository view can be an isolated worktree under .claude/worktrees/... that is based on an older baseline instead of the parent session's current local branch HEAD.

In both reproductions below, the parent session was on a local branch ahead of origin/main, but the subagent's default repo view was pinned to the older origin/main baseline. As a result, the subagent appears to inspect the current repo while actually analyzing older code.

What Should Happen?

A subagent launched from a local repository should either analyze the parent session's current local repo state, or clearly indicate that it is analyzing a different isolated baseline and which commit that baseline corresponds to.

Acceptable solutions could include:

  1. The subagent inherits the parent session's current local branch HEAD
  2. There is a supported option to launch the subagent from the parent session's current HEAD
  3. There is a supported option to disable repo isolation for read-only exploration/review
  4. Claude Code clearly warns that the subagent is analyzing an isolated baseline and shows which commit it is based on

At minimum, the tool should not appear to inspect the current repo while actually analyzing a stale baseline.

Error Messages/Logs

Observed current-machine subagent default repo view:

pwd: /home/sean/cloud/.claude/worktrees/agent-af1352ff
repo root: /home/sean/cloud/.claude/worktrees/agent-af1352ff
branch: worktree-agent-af1352ff
HEAD: 2c23a99ce13cce5014a654016ffb76977aa3ebe2
origin/main: 2c23a99ce13cce5014a654016ffb76977aa3ebe2
README.md line 5: Baseline line 5 from origin main.
subagent_probe_20260416_X91K.txt: absent
uncommitted changes: none

Absolute-path reads from the same subagent:

/home/sean/cloud/README.md -> line 5: Local line 5 from parent branch HEAD.
/home/sean/cloud/subagent_probe_20260416_X91K.txt -> exists

Steps to Reproduce

  1. Create a local git repo and a local bare origin.
  2. Commit a baseline README.md and push it to origin/main.
  3. Make a second local commit on main without pushing it.
  4. Ensure the local branch is ahead of origin/main.
  5. Make README.md line 5 differ between local HEAD and origin/main.
  6. Add a probe file that exists only in the newer local commit.
  7. In the parent session, confirm:
  • repo root
  • current branch
  • HEAD
  • origin/main
  • README.md line 5
  • probe file exists
  1. Launch an Explore subagent and ask it to report:
  • its cwd / repo root
  • current branch
  • HEAD
  • origin/main
  • README.md line 5 from its own default repo view
  • whether the probe file exists in its own default repo view
  • whether it has uncommitted changes
  1. Ask the same subagent to read the parent repo files by absolute path.

Reproduction A: current machine

Parent session:

repo root: /home/sean/cloud
branch: main
HEAD: 96d416a65687f3e72e8e45445ad923325727312c
origin/main: 2c23a99ce13cce5014a654016ffb76977aa3ebe2
README.md line 5: Local line 5 from parent branch HEAD.
subagent_probe_20260416_X91K.txt: present

Subagent default repo view:

repo root: /home/sean/cloud/.claude/worktrees/agent-af1352ff
branch: worktree-agent-af1352ff
HEAD: 2c23a99ce13cce5014a654016ffb76977aa3ebe2
origin/main: 2c23a99ce13cce5014a654016ffb76977aa3ebe2
README.md line 5: Baseline line 5 from origin main.
subagent_probe_20260416_X91K.txt: absent
uncommitted changes: none

Reproduction B: second machine

Parent session:

repo root: /home/cloud/Code/fix-cc-bug
branch: main
HEAD: 11a7f47cec4f67acc03ef6329daaebc7a6c7b8c5
origin/main: 9ec525c3055d57bee81bfe5081b4069060f49f27
README.md line 5: Local line 5 from parent branch HEAD.
subagent_probe_20260416_X91K.txt: present

Subagent default repo view:

repo root: /home/cloud/Code/fix-cc-bug/.claude/worktrees/agent-a45af8a4
branch: worktree-agent-a45af8a4
HEAD: 9ec525c3055d57bee81bfe5081b4069060f49f27
origin/main: 9ec525c3055d57bee81bfe5081b4069060f49f27
README.md line 5: Baseline line 5 from origin main.
subagent_probe_20260416_X91K.txt: absent
uncommitted changes: none

In both reproductions, the subagent could still read the parent repo correctly by absolute path, which suggests the problem is specifically the subagent's default repo/worktree view rather than raw filesystem access.

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

Unknown

Claude Code Version

2.1.110 (Claude Code)

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Xterm

Additional Information

  • This issue was reproduced independently in two local environments.
  • In both cases, the mismatch pattern was the same:
  • parent session local branch ahead of origin/main
  • subagent default repo view rooted at .claude/worktrees/...
  • subagent HEAD matching the older origin/main baseline instead of the parent session local HEAD
  • The fact that absolute-path reads still show the parent repo correctly strongly suggests the bug is in how the subagent's default repository context is initialized.
  • In a separate session, I also saw:

``text
Cannot create agent worktree: not in a git repository and no WorktreeCreate hooks are configured.
``

That may be a separate repo-detection / session-initialization issue, so I am not relying on it for the main reproduction above.

View original on GitHub ↗

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