isolation: "worktree" silently fails — agent runs in main repo instead of isolated worktree

Resolved 💬 3 comments Opened Mar 27, 2026 by Puneethkumarck Closed Mar 31, 2026

Description

When spawning a subagent with isolation: "worktree", the agent silently runs in the main repository directory instead of an isolated worktree. No error is raised — the worktree simply never gets created.

Steps to Reproduce

  1. Open a project with a git repository
  2. Spawn a subagent with isolation: "worktree":

``
Agent({
description: "Test worktree isolation",
isolation: "worktree",
prompt: "Run pwd and git branch --show-current"
})
``

  1. Observe the agent's output

Expected Behavior

  • Agent should run in a temporary git worktree (e.g., /tmp/worktree-<hash>)
  • Agent should be on its own branch, isolated from the main checkout
  • pwd should show the worktree path, not the main repo
  • worktreePath in the result should be an actual path
  • worktreeBranch should be defined

Actual Behavior

  • Agent runs in the main repository directory (same pwd as parent)
  • worktreePath: done (not an actual path)
  • worktreeBranch: undefined
  • Agent commits directly to the main checkout's branch
  • Zero isolation — the agent modifies shared git state

Impact

This makes it impossible to run parallel agents that work on different branches. When multiple agents share the same .git state:

  • Branch checkout races: Agent A checks out branch X, Agent B checks out branch Y → Agent A is now on branch Y
  • Commits land on wrong branches
  • Changes "leak" to unintended branches (including main)

We lost a full morning diagnosing this before discovering the root cause.

Workaround

  • Use parallel agents only for read-only tasks (search, read, analyze)
  • Perform all git mutations (checkout, commit, push) sequentially from the main conversation thread
  • Never dispatch two agents that both need different branches

Environment

  • Claude Code CLI (Opus 4.6, 1M context)
  • macOS Darwin 24.3.0
  • Git 2.x
  • Repository with standard .git structure

Diagnostic Evidence

Agent dispatched with: isolation: "worktree"
Result metadata:
  worktreePath: done
  worktreeBranch: undefined

Agent reported:
  pwd: /Users/.../stablebridge-tx-recovery  (MAIN REPO, not a worktree)
  git branch: test/subagent-diagnostics     (MAIN REPO's branch)
  git commit: succeeded                      (committed to MAIN REPO)
  git worktree list: only 1 worktree (main) (no additional worktree created)

View original on GitHub ↗

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