Agent Teams ignore isolation: "worktree" — worktree never created, WorktreeCreate hook never called
Bug Description
When launching an agent with both team_name and isolation: "worktree", the worktree is never created and the WorktreeCreate hook is never called. The agent silently runs in the main repository directory instead of an isolated worktree.
Reproduction Steps
- Enable Agent Teams:
``json``
{ "env": { "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1" } }
- Create a team and launch an agent with
isolation: "worktree":
````
TeamCreate({ team_name: "test-team" })
TaskCreate({ subject: "Test task", description: "..." })
Agent({
name: "member-1",
team_name: "test-team",
isolation: "worktree",
run_in_background: true,
prompt: "Run pwd && git branch --show-current && ls -la .git, then report via SendMessage"
})
- Agent reports:
pwd→ main repo pathgit branch --show-current→main.gitis a directory (not a worktree file)
Expected Behavior
WorktreeCreatehook is called- Agent runs inside an isolated git worktree
.gitis a file pointing to.git/worktrees/...- Agent has its own branch
Actual Behavior
WorktreeCreatehook is never called (verified via debug logging)- Agent runs in the main repository on
mainbranch .gitis a full directory- No worktree is created anywhere on disk (
git worktree listshows only main) - No error or warning is emitted — the failure is completely silent
Verification Matrix
We tested all combinations systematically:
| subagent_type | team_name | isolation | WorktreeCreate hook called | Agent in worktree |
|---|---|---|---|---|
| (none) | (none) | "worktree" | Yes | Yes ✅ |
| custom agent | team | "worktree" | No | No ❌ |
| custom agent (with frontmatter isolation: worktree) | team | "worktree" | No | No ❌ |
| (none) | team | "worktree" | No | No ❌ |
Conclusion: team_name is the deciding factor. Any agent launched with team_name silently ignores isolation: "worktree".
Additional Context: WorktreeCreate Hook stdout issue
During investigation, we also discovered a separate issue: git worktree add outputs HEAD is now at ... to stdout, which contaminates the hook's stdout that Claude Code reads as the worktree path. This caused worktree isolation failures even without team_name until we redirected both stdout and stderr:
- git worktree add -b "$NAME" "$WORKTREE_PATH" 2>>"$DEBUG_LOG"
+ git worktree add -b "$NAME" "$WORKTREE_PATH" >>"$DEBUG_LOG" 2>&1
This is a footgun for anyone writing a custom WorktreeCreate hook — the docs should note that git worktree add writes to stdout and the hook must ensure only the path appears on stdout.
Environment
- Claude Code: v2.1.83
- OS: macOS (Darwin 23.6.0)
- Git: worktree feature works correctly outside Claude Code
Related Issues
- #33045 —
isolation: "worktree"has no effect for team agents - #37549 —
isolation: "worktree"silently fails when combined withteam_name - #34645 — Parallel subagents with worktree fail due to git config lock contention
🤖 Generated with Claude Code
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗