[BUG] Agent Teams - Agent tool with `team_name` parameter fails with internal error

Resolved 💬 3 comments Opened Mar 28, 2026 by zgjin Closed Apr 1, 2026

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

  1. Enable Agent Teams: set CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 in settings.json
  2. Create a team:

``
TeamCreate({ team_name: "my-team", description: "test team" })
// Result: ✅ Success
``

  1. Create a task:

``
TaskCreate({ subject: "Test task", description: "..." })
// Result: ✅ Success
``

  1. 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:

  1. Race condition: getTeammateModeFromSnapshot is called before the snapshot is captured. The error message explicitly says "this indicates an initialization bug."
  1. Incorrect tmux detection: Even when running inside tmux (with TMUX env var set and TERM=tmux-256color), Claude Code reports insideTmux=false.
  1. Teammate mode fallback fails: Because insideTmux=false, mode=auto falls 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:

  1. When Agent is called with team_name, it enters the teammate code path
  2. This path calls getTeammateModeFromSnapshot() to determine how to spawn the teammate
  3. But TeammateModeSnapshot hasn't been captured yet at this point
  4. The function throws an error, which is caught internally and surfaces as a generic "internal error"
  5. Additionally, the tmux detection (insideTmux) incorrectly returns false even when the TMUX environment 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

  1. Install Claude Code v2.1.86 on Linux, run inside tmux
  2. Enable Agent Teams in ~/.claude/settings.json:

{ "env": { "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1" } }

  1. Start a new Claude Code session
  2. Ask Claude to create a team:

TeamCreate({ team_name: "test-team", description: "test" })
→ ✅ Success

  1. 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]

  1. 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_

View original on GitHub ↗

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