claude-code - 💡(How to fix) Fix [BUG] Subagents / Explore use stale isolated worktree instead of parent repo HEAD [3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#49169Fetched 2026-04-17 08:48:55
View on GitHub
Comments
3
Participants
3
Timeline
7
Reactions
1
Author
Timeline (top)
labeled ×4commented ×3

Error Message

Error Messages/Logs

Code Example

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

---

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

---

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

---

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

---

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

---

2.1.110 (Claude Code)

---

Cannot create agent worktree: not in a git repository and no WorktreeCreate hooks are configured.
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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
  8. 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
  9. 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:

    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.

extent analysis

TL;DR

The subagent's default repository view should be updated to inherit the parent session's current local branch HEAD or provide a clear indication of the isolated baseline being analyzed.

Guidance

  • Verify that the subagent is correctly detecting the parent session's current local branch HEAD and update its default repository view accordingly.
  • Consider adding a supported option to launch the subagent from the parent session's current HEAD or disable repo isolation for read-only exploration/review.
  • Ensure that Claude Code clearly warns when the subagent is analyzing an isolated baseline and shows which commit it is based on.
  • Investigate the Cannot create agent worktree error as a potential separate issue related to repo-detection or session-initialization.

Example

No code snippet is provided as the issue is related to the configuration and behavior of the Claude Code tool rather than a specific code implementation.

Notes

The issue seems to be related to how the subagent's default repository context is initialized, and the fact that absolute-path reads still show the parent repo correctly suggests that the problem is specific to the subagent's default repo/worktree view.

Recommendation

Apply a workaround to ensure the subagent's default repository view is updated to reflect the parent session's current local branch HEAD, such as launching the subagent with a specific option or configuring the tool to disable repo isolation for read-only exploration/review. This will help prevent the subagent from analyzing a stale baseline without clear indication.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING