TeammateTool

The multi-agent coordination layer in claude-code. Not a single spawn function — it exposes 13 distinct operations covering the full team lifecycle, from creation through task claiming to graceful shutdown.

13 Operations

Team Setup

Membership

Task Coordination

Communication

Three Execution Models

Model Isolation Use Case
InProcessTeammate AsyncLocalStorage — same process, different context Same terminal pane, lightweight
LocalAgentTask Async background process Non-blocking parallel sub-agent
RemoteAgentTask Cloud container (CCR) Full cloud-sandboxed execution

Additional isolation modes: git worktree (own branch and directory), DreamTask (background memory consolidation), MonitorMcpTask (MCP server monitoring).

Task Claiming and Locking

The task list is a shared work queue stored as JSON files in ~/.claude/tasks/{team-name}/. Claiming uses file locking: writing to current_tasks/parse_if_statement.txt prevents others from claiming the same work. Lock retries: 30 attempts at 5-100ms backoff (~2.6 second max wait).

Tasks have three states: pending, in-progress, completed. When a task moves to completed, any tasks listing it in blockedBy are automatically unblocked.

Critical: the locking applies to task claiming, not to file writes. Two agents can simultaneously write to different source files. Merge conflicts during git operations are expected and resolved by the agents themselves.

Communication: Mailbox System

Each teammate has an independent async message queue stored as JSON: ~/.claude/teams/{name}/inboxes/{agent}.json. Structured message types include shutdown_request, plan_approval_response, and permission bubbling (teammates can escalate permission requests up to the lead).

The 36.8 GB Lesson

TEAMMATE_MESSAGES_UI_CAP = 50 was not added speculatively — it was added after an internal test run with 292 agents triggered a memory leak consuming 36.8 GB. Every concrete engineering limit in the codebase has a production failure story behind it.

Permission Modes

Known bug: if the lead agent is in Delegate Mode, all spawned teammates inherit the restriction and lose file operation tools, even when mode: "bypassPermissions" is set.

Git Worktree Isolation

When isolation: worktree is set, Claude Code creates a temporary git worktree with its own working directory, staging area, and HEAD — but sharing .git/objects/ (history stored once). Five simultaneous worktree agents produce five independent branches that merge through standard PRs. Cleanup is automatic on exit.

Feature Gate

Process-based agents gated behind tengu_amber_flint. Each agent receives a color assignment and identity flags (--agent-name, --team-name).

Key Claims

Sources