Bug: `isolation: "worktree"` silently ignored when `team_name` is present in Agent tool

Resolved 💬 3 comments Opened Mar 25, 2026 by paul-maas Closed Mar 29, 2026

Summary

When spawning an agent via the Agent tool with both team_name and isolation: "worktree" parameters, the worktree isolation is silently ignored. The teammate starts in the main project directory without any worktree being created. This works correctly when team_name is omitted.

Reproduction

Test 1: Agent WITHOUT team_name — works correctly

Agent(
  description="test",
  prompt="Run: pwd, ls -la .git, git branch --show-current, git worktree list",
  isolation="worktree"
)

Result:

  • pwd: <repo>/.claude/worktrees/agent-a8d62c42
  • .git: FILE (worktree pointer) containing gitdir: <repo>/.git/worktrees/agent-a8d62c42
  • git branch --show-current: worktree-agent-a8d62c42
  • git worktree list: 2 entries (main + worktree)

Worktree is created and the agent runs inside it. Everything works as expected.

Test 2: Agent WITH team_name — broken

TeamCreate(team_name="worktree-test")
Agent(
  description="test",
  prompt="Run: pwd, ls -la .git, git branch --show-current, git worktree list",
  team_name="worktree-test",
  name="diag-probe",
  isolation="worktree"
)

Result:

  • Team config shows: "cwd": "<repo>" (main repo, NOT a worktree)
  • pwd: main project directory
  • .git: DIRECTORY (main repo, not a worktree)
  • git branch --show-current: main
  • git worktree list: 1 entry (main only — NO worktree created)

The isolation: "worktree" parameter was completely ignored. No worktree was created, no error was raised.

Test 3: Inside Docker container — also broken

Same behavior inside a Docker container. The teammate is spawned with:

cd /project && env CLAUDECODE=1 CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 \
  /usr/local/bin/claude --agent-id diag@team --agent-name diag --team-name team \
  --agent-color blue --parent-session-id <id> --dangerously-skip-permissions --model haiku

No worktree flags appear in the subprocess command. No worktree is created. The teammate runs in /project on main.

Note: Git worktrees themselves work perfectly inside Docker — manually verified with git worktree add.

Expected behavior

When isolation: "worktree" is passed to the Agent tool, a git worktree should be created and the agent should run in that worktree directory, regardless of whether team_name is also present.

Actual behavior

The isolation parameter is silently ignored when team_name is present. No worktree is created, no error is raised. The teammate runs in the main project directory.

Impact

This makes parallel team workflows unsafe — multiple teammates operating in the same directory cause git branch cross-contamination. When 3 parallel teammates each try to git checkout their own branch, the last checkout wins and all commits end up on one branch.

Our project has tracked 14 incidents of this across 13 sprints. We iteratively developed mitigations (anti-cross-contamination protocol: pre-create branches, sequential worktree creation, branch name verification checkpoint) — none worked because the root cause is that worktrees are never created in the first place.

Diagnostic evidence

Key differentiator: .git type

| Test | team_name | isolation | .git type | Worktree created? |
|------|-------------|-------------|-------------|-------------------|
| Agent (no team) | absent | "worktree" | FILE | YES |
| Agent (with team) | present | "worktree" | DIRECTORY | NO |
| Teammate in Docker | present | "worktree" | DIRECTORY | NO |

A .git file indicates a worktree (contains gitdir: pointer). A .git directory indicates the main repository.

Subprocess command comparison

Without team (worktree works):
Agent runs in .claude/worktrees/agent-xxx/ with its own branch.

With team (worktree ignored):

cd /project && env CLAUDECODE=1 ... /usr/local/bin/claude --agent-id ... --team-name ...

No worktree-related flags. Starts directly in main project directory.

Environment

  • Claude Code: latest (npm install -g @anthropic-ai/claude-code@latest)
  • Tested on: macOS (Darwin 25.3.0) and Docker (python:3.12-slim + node:22-slim)
  • Teams enabled via: CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 in settings
  • Git: works correctly for worktree operations in both environments

Workaround

Teammates can manually create and manage worktrees via prompt instructions:

# First action in teammate prompt:
cd /project && git worktree add /tmp/worktree-stream-a -b fix/branch-name HEAD
cd /tmp/worktree-stream-a

# Verify isolation:
pwd                      # should be /tmp/worktree-stream-a
ls -la .git              # should be a FILE, not directory
git branch --show-current # should be fix/branch-name

# ... do work using /tmp/worktree-stream-a/ paths ...

# Cleanup before exit:
cd /project
git worktree remove /tmp/worktree-stream-a

This works but requires every parallel teammate's prompt to include boilerplate worktree management, and all file operations must use the worktree path instead of the project path.

View original on GitHub ↗

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