[BUG] Agent Teams - Agent tool with `team_name` parameter fails with internal error
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Environment
- Claude Code version: 2.1.86
- OS: Linux (Ubuntu 22.04)
- Shell: bash (inside tmux 3.5a)
- Model: Opus 4.6 (1M context)
- Subscription: Claude Max (5x rate limit tier)
Configuration
// settings.json
{
"env": {
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
}
}
// .claude.json
{
"teammateMode": "tmux"
}
Bug Description
The Agent tool fails with [Tool result missing due to internal error] whenever the team_name parameter is provided. TeamCreate and TaskCreate work fine, but spawning any teammate agent consistently fails.
This has been reproduced across 6+ separate sessions over multiple days, with varying team sizes (2 to 6 members), both sequential and parallel spawning.
Steps to Reproduce
- Enable Agent Teams: set
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1in settings.json - Create a team:
````
TeamCreate({ team_name: "my-team", description: "test team" })
// Result: ✅ Success
- Create a task:
````
TaskCreate({ subject: "Test task", description: "..." })
// Result: ✅ Success
- Spawn a teammate agent:
````
Agent({
name: "worker",
team_name: "my-team",
subagent_type: "general-purpose",
prompt: "Hello",
run_in_background: true
})
// Result: ❌ [Tool result missing due to internal error]
Verification: Normal Agent Works Fine
Spawning a regular Agent (without team_name) works immediately:
Agent({
subagent_type: "general-purpose",
prompt: "Reply hello"
})
// Result: ✅ "hello, agent works" — returned in 2.5 seconds
Comparison Table
| Operation | team_name param | Result |
|-----------|-------------------|--------|
| TeamCreate | N/A | ✅ Success |
| TaskCreate | N/A | ✅ Success |
| Agent | Not set | ✅ Success (2.5s) |
| Agent | Set | ❌ Internal error |
Debug Log Evidence
Debug logs from a previous session show the following error during teammate initialization:
[ERROR] Error: getTeammateModeFromSnapshot called before capture - this indicates an initialization bug
at KrH (/$bunfs/root/src/entrypoints/cli.js:2714:9814)
at xF1 (/$bunfs/root/src/entrypoints/cli.js:2731:190)
at PU (/$bunfs/root/src/entrypoints/cli.js:2731:308)
...
Followed by:
[TeammateModeSnapshot] Captured from config: auto
[BackendRegistry] isInProcessEnabled: true (mode=auto, insideTmux=false)
Key observations from debug logs:
- Race condition:
getTeammateModeFromSnapshotis called before the snapshot is captured. The error message explicitly says "this indicates an initialization bug."
- Incorrect tmux detection: Even when running inside tmux (with
TMUXenv var set andTERM=tmux-256color), Claude Code reportsinsideTmux=false.
- Teammate mode fallback fails: Because
insideTmux=false,mode=autofalls back to in-process mode, and the initialization race condition causes the teammate spawn to fail entirely.
Attempted Workarounds (None Worked)
- Setting
teammateMode: "tmux"explicitly in.claude.json - Reducing team size to 2 members (even 1 teammate fails)
- Sequential spawning instead of parallel
- Starting new sessions between attempts
- Different project directories
Expected Behavior
Agent tool with team_name parameter should successfully spawn a teammate agent, either as a tmux pane (when in tmux) or in-process.
Actual Behavior
Agent tool with team_name parameter always fails with [Tool result missing due to internal error]. The teammate never initializes.
Root Cause Analysis
The bug appears to be a race condition in the teammate initialization code path:
- When
Agentis called withteam_name, it enters the teammate code path - This path calls
getTeammateModeFromSnapshot()to determine how to spawn the teammate - But
TeammateModeSnapshothasn't been captured yet at this point - The function throws an error, which is caught internally and surfaces as a generic "internal error"
- Additionally, the tmux detection (
insideTmux) incorrectly returnsfalseeven when theTMUXenvironment variable is set
What Should Happen?
Agent tool with team_name parameter should successfully spawn a teammate agent, either as a tmux pane (when in tmux) or in-process.
Error Messages/Logs
Steps to Reproduce
- Install Claude Code v2.1.86 on Linux, run inside tmux
- Enable Agent Teams in ~/.claude/settings.json:
{ "env": { "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1" } }
- Start a new Claude Code session
- Ask Claude to create a team:
TeamCreate({ team_name: "test-team", description: "test" })
→ ✅ Success
- Ask Claude to spawn a teammate agent:
Agent({ name: "worker", team_name: "test-team", subagent_type: "general-purpose", prompt:
"Reply hello" })
→ ❌ [Tool result missing due to internal error]
- For comparison, spawn a normal agent without team_name:
Agent({ subagent_type: "general-purpose", prompt: "Reply hello" })
→ ✅ Success
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.86
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗