Agent(isolation: "worktree") can check the subagent's branch out onto the primary checkout when the calling session is itself inside a worktree

Status Open
Maintainer reply None cached
Activity 0 comments · opened Jul 22, 2026

Summary

The Agent tool's isolation: "worktree" option is meant to land the delegated subagent's work in a separate git worktree. When the calling session is itself already running inside a Claude Code worktree (cwd under <repo>/.claude/worktrees/<name>/), the delegated call's branch can instead end up checked out on the repo's primary checkout, with no error or warning surfaced to either the caller or the subagent.

git worktree list afterward shows the primary checkout sitting on the subagent's feature branch. For workflows that treat the primary checkout as shared, always-on-main state (concurrent sessions on the same repo, or checkouts synced across machines), this is the collision the isolation option exists to prevent: a sibling session that trusts the primary checkout finds a foreign branch checked out mid-flight.

Steps to trigger

  1. Start a Claude Code session and enter a worktree (e.g. via EnterWorktree), so the session's cwd is <repo>/.claude/worktrees/<session-name>/.
  2. From that session, invoke the Agent tool with isolation: "worktree" and a prompt that creates a branch and commits a small change.
  3. After the subagent completes, run git worktree list from any checkout of the repo.

Expected: the subagent's work lands in its own worktree directory, or the call fails loudly if a nested worktree can't be created.

Reported behavior: no new worktree directory is created for the subagent, its branch is checked out on the primary checkout, and no error is reported.

Impact

The failure is silent — the calling session receives a normal-looking success result, and the problem only surfaces later when another session (or the user) finds the primary checkout on an unexpected branch. A workable mitigation is to re-check git worktree list and restore the primary checkout after any nested Agent(isolation: "worktree") call.

Environment

  • Claude Code CLI on macOS (Apple Silicon)
  • The calling session was itself running inside a .claude/worktrees/ worktree

Note on provenance

This is filed from an internally-documented known gap encountered during agent orchestration, not from a minimal reproduction captured specifically for this report. If a self-contained repro would help triage, we can put one together.

View original on GitHub ↗