Agent tool `isolation: "worktree"` is silently ignored when spawning teammates with `team_name`
Summary
When spawning a teammate via the Agent tool with a team_name, the isolation: "worktree" parameter is silently ignored. The teammate runs in the main working directory on the main branch instead of an isolated git worktree. The same isolation: "worktree" parameter works correctly for non-team background agents (no team_name).
Environment
- Claude Code version: 2.1.172 (
@anthropic-ai/claude-code@2.1.172) - Platform: Linux (Ubuntu container)
Expected behavior
A teammate spawned with isolation: "worktree" should automatically start inside an isolated git worktree (e.g. .claude/worktrees/<name> on branch worktree-<name>), the same way non-team background agents do.
Actual behavior
The teammate starts in the main working directory (/workspace/test) on the main branch (master). The isolation parameter has no effect — it is a silent no-op on the team spawn path.
Reproduction
Controlled comparison, varying only team_name:
| # | Spawn method | isolation | Called EnterWorktree? | Landing spot | Isolated? |
|---|---|---|---|---|---|
| 1 | Team teammate (team_name set) | worktree | no | /workspace/test @ master | ❌ |
| 2 | Team teammate (team_name set) | worktree | no | /workspace/test @ master | ❌ |
| 3 | Non-team background agent | worktree | no | .claude/worktrees/agent-<id> @ worktree-agent-<id> | ✅ |
| 4 | Team teammate | — | yes (manual) | .claude/worktrees/worktree-test-2 | ✅ |
| 5 | Team teammate (team_name set) | worktree | no | /workspace/test @ master | ❌ |
Steps:
- Create a team with
TeamCreate. - Spawn a teammate via the Agent tool with
team_name,name, andisolation: "worktree". - In the teammate, run
pwd,git branch --show-current,git rev-parse --show-toplevel. - Observe the teammate is in the main working dir on the main branch, not in an isolated worktree.
- For contrast, spawn a background agent without
team_namebut withisolation: "worktree"— it correctly lands in.claude/worktrees/agent-<id>.
The only differing variable between the working and broken cases is the presence of team_name.
Workaround
Have the team teammate explicitly call the EnterWorktree tool at the start of its task (case #4 above), then verify with pwd / git branch --show-current before making changes.