Agent Teams
- Entity ID:
ent-agent-teams - Type:
service - Scope:
shared
What it is
Agent Teams is Claude Code's multi-instance coordination layer that turns a single CLI into a parallel team of workers. It provides three distinct execution models (in-process, local async, and remote cloud), a 13-operation TeammateTool for the full team lifecycle, file-lock-based task claiming, per-agent mailbox communication, and git worktree isolation for parallel code editing.
Agent Teams is gated behind the tengu_amber_flint feature flag and not generally available. Each agent receives a color assignment and identity flags (--agent-name, --team-name) for UI differentiation.
Why it exists
Single-agent execution hits fundamental limits on complex tasks: one agent can't read 50 files, write 20 tests, and refactor 10 modules simultaneously. Agent Teams solves this with structured parallelism:
- Parallel investigation — multiple agents explore different parts of a codebase simultaneously
- Divide-and-conquer implementation — each agent takes a subset of changes, merges through git
- Cost optimization — the forked agent pattern achieves 92% prompt cache reuse, making 5 parallel agents cost nearly the same as 1
The design philosophy (from COORDINATOR_MODE's system prompt): "Parallelism is your superpower. Workers are async. Launch independent workers concurrently whenever possible — don't serialize work that can run simultaneously."
Three execution models
| Model | Isolation | Use case |
|---|---|---|
InProcessTeammate |
AsyncLocalStorage — same process, different context |
Lightweight, same terminal pane |
LocalAgentTask |
Async background process | Non-blocking parallel sub-agent |
RemoteAgentTask |
Cloud container (CCR) | Full cloud-sandboxed execution |
| Worktree isolation | Git worktree — own branch and directory | Parallel code editing without merge conflicts |
DreamTask |
Background-only, memory-directory-only writes | Memory consolidation (auto-dream) |
AsyncLocalStorage provides implicit context isolation for in-process teammates without explicit parameter passing — each agent has its own storage namespace even though they share a Node.js process.
TeammateTool: 13 operations
Team setup: spawnTeam (creates ~/.claude/teams/{name}/), discoverTeams, cleanup
Membership: requestJoin, approveJoin, rejectJoin
Task coordination: TaskCreate (with blockedBy dependency declarations), TaskClaim (file-lock protected), TaskComplete (auto-unblocks dependent tasks)
Communication: SendMessage (direct), Broadcast (all teammates — cost scales with team size), requestShutdown, approveShutdown
Task claiming and file locking
The task list is a shared work queue stored as JSON files in ~/.claude/tasks/{team-name}/. Claiming uses file locking: writing current_tasks/parse_if_statement.txt prevents other agents from claiming the same work. Tasks have three states: pending, in-progress, completed. Completion auto-unblocks blockedBy dependencies.
Critical distinction: Locking applies to task claiming, not 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
Per-agent mailboxes at ~/.claude/teams/{name}/inboxes/{agent}.json. Structured message types include shutdown_request, plan_approval_response, and permission bubbling (teammates can escalate permission requests to the lead).
Git worktree isolation
When isolation: worktree is set, Claude Code creates a temporary git worktree:
- Isolated: own working directory, staging area, HEAD
- Shared: .git/objects/ (history stored once), .git/refs/ (branches visible to all)
Five simultaneous worktree agents produce five independent branches that merge through standard PR process. Cleanup is automatic on agent exit.
Permission model
| Mode | Behavior |
|---|---|
ask |
Every tool use requires human confirmation |
bubble |
Permission prompts float up to team lead |
allow |
Auto-approve, bounded by lead's permissions |
Known bug: If the lead agent is in Delegate Mode, all spawned teammates inherit the restriction and lose file operation tools (Bash, Read, Write, Edit, Grep, Glob) even when mode: "bypassPermissions" is set.
What depends on it
- COORDINATOR_MODE — one worker per logical CPU core, distributes across cores
- Worktree isolation — leverages git's built-in parallel development mechanism
- Forked agent pattern — all agents share the same cache-safe prompt prefix
- Task system — TaskCreate, TaskClaim, TaskComplete used for work distribution
- Auto-dream — DreamTask is one of the execution models
Trade-offs and limitations
36.8 GB lesson: TEAMMATE_MESSAGES_UI_CAP = 50 was added after an internal test with 292 agents consumed 36.8 GB of memory. Every engineering limit has a story.
50-message UI cap: Prevents unbounded message queue growth during large swarms.
No recursive forking: Anti-recursion enforced by <fork_boilerplate_tag> marker — fork children see AgentTool but reject attempts to fork recursively.
Lead context doesn't carry over: Spawned teammates are peers, not children. They load the same project context (CLAUDE.md, MCP, skills) but not the lead's conversation history.
omitClaudeMd optimization: Read-only agents (explore, plan) are spawned with omitClaudeMd: true, saving 5-15 GTok/week across Anthropic's fleet.
Key claims
- 92% prompt cache reuse across forked agents (measured $4.85 / 81% cost reduction per task)
- 13 TeammateTool operations covering full lifecycle
- 292-agent test triggered 36.8 GB memory consumption → led to message cap
- File-lock task claiming with 30 retry attempts
- One worker per logical CPU core in COORDINATOR_MODE
Relationships
- depends_on: forked-agent-pattern, permission-pipeline, git
- contains: TeammateTool, InProcessTeammate, LocalAgentTask, RemoteAgentTask, DreamTask
- uses: kairos (for autonomous agents), auto-dream (DreamTask model)
- related_to: coordinator-mode, worktree-isolation
Evidence
src-20260409-a14e9e98c3cd: Internals: Auto-Memory, Auto-Dream & Agent Teamssrc-20260409-037a8abb6277: Community deep dive architecturesrc-20260409-668cb0fcddef: Deep dive Claude Code
Open questions
- How does team state persist across sessions? Can a team be resumed after all agents exit?
- What happens when a worktree merge conflict can't be auto-resolved?
- How does the cost model change when COORDINATOR_MODE distributes across cloud containers?