Multi-agent orchestration lets you run multiple Claude Code instances working together as a team, each with its own context window, claiming tasks from a shared list and messaging each other directly. One session acts as team lead, coordinating work, spawning teammates, and synthesizing results. This is the highest-leverage pattern for parallelizing complex work across an entire codebase.
Subagents vs Teams
The key distinction is hierarchy. Subagents report back to a single parent. Agent teams are peers that coordinate through a shared task list and direct messaging.
Subagents vs Agent Teams
| Dimension | Subagents | Agent Teams |
|---|---|---|
| Context | Own window, results return to caller | Own window, fully independent |
| Communication | Report back to main agent only | Message each other directly |
| Coordination | Main agent manages all work | Shared task list with self-coordination |
| Best for | Focused tasks where only the result matters | Complex work requiring cross-agent discussion |
| Token cost | Lower (results summarized back) | Higher (~7x in plan mode per agent) |
| Nesting | Can be nested | Cannot nest (lead is fixed) |
Use subagents when a focused job needs to run, produce a result, and return. Use agent teams when multiple agents need to negotiate, share context mid-flight, and claim work independently from a common backlog.
Team Lead Pattern
The team lead is the main Claude Code session. It creates the team, spawns teammates with role-specific prompts, defines the shared task list, and synthesizes results at the end. The lead is fixed for the lifetime of the team and cannot be transferred.
The lifecycle follows a clear sequence:
- Setup — You describe the task and team structure in natural language
- Spawn — Claude creates teammates with specific role prompts
- Planning — Lead creates a shared task list with dependencies
- Execution — Teammates claim and work on tasks independently
- Communication — Teammates message each other to share findings and resolve conflicts
- Synthesis — Lead collects results and produces final output
- Cleanup — You tell the lead to clean up when done (always via lead, never teammates)
Teammates do NOT inherit the lead’s conversation history. They get CLAUDE.md, MCP servers, and skills, but not the conversation context. Always include the full role description, owned files, expected output format, and constraints directly in the spawn prompt.
Shared Task List
The shared task list is the coordination backbone. Each task has a state that progresses through a fixed lifecycle:
pending --> in progress --> completedTasks can declare dependencies on other tasks. A pending task with unresolved dependencies cannot be claimed. When a teammate finishes its current work, it scans the list for the next available pending task, claims it, and begins.
Task claiming uses file locking to prevent race conditions. If two teammates try to claim the same task at the same instant, only one succeeds. The other re-scans and picks a different task.
Team configuration lives at ~/.claude/teams/{team-name}/config.json and task data at ~/.claude/tasks/{team-name}/. These persist on disk so the lead can track state across the full session.
Press Ctrl+T in the terminal to toggle the task list overlay. This shows you real-time status of all tasks and which teammate owns each one.
Mailbox System
The mailbox system enables direct inter-agent messaging. Teammates can send messages to each other, not just back to the lead. This avoids routing every coordination request through a bottleneck.
A typical exchange looks like this:
[frontend-dev -> backend-dev] "I need the /auth endpoint to return a user_id field in the response body."
[backend-dev -> frontend-dev] "Done. The response now includes { user_id, token, expires_at }."The mailbox pattern is what separates agent teams from subagents. Instead of a hub-and-spoke model where the lead relays everything, teammates form a peer network. This is critical for workflows like cross-layer feature development, where the frontend and backend agents need to negotiate API contracts without waiting for the lead to relay messages.
File Locking
Two teammates editing the same file will cause merge conflicts and wasted work. The agent teams system uses file locking during task claiming to prevent race conditions, but the more important defense is task design.
Structure tasks around directory boundaries so each teammate owns different files:
- Frontend teammate:
src/components/,src/styles/ - Backend teammate:
src/api/,src/middleware/ - Test teammate:
tests/,test-fixtures/
The ideal team size is 3-5 teammates with 5-6 tasks per teammate. More teammates means linear token cost scaling and more coordination overhead. Fewer teammates means less parallelism.
Teammate Modes
How teammates are displayed in your terminal depends on the --teammate-mode flag.
Display Modes
| Mode | Flag | Behavior | Requirements |
|---|---|---|---|
| in-process | —teammate-mode in-process | All teammates in one terminal. Press Shift+Down to cycle between them. | Works anywhere |
| split panes | —teammate-mode tmux | Each teammate gets its own pane. Click a pane to interact directly. | tmux or iTerm2 only |
| auto (default) | —teammate-mode auto | Uses split panes if running inside tmux, otherwise falls back to in-process. | — |
In-process mode is the most portable option. Split pane mode gives better visibility but does not work in VS Code terminal, Windows Terminal, or Ghostty. If the terminal crashes while using in-process mode, teammates are lost. Split pane mode (tmux) is more resilient because each pane is an independent tmux process.
Git Worktrees for Manual Parallelism
For simpler parallel work without the experimental agent teams feature, use native git worktree support:
Each worktree is a separate checkout with its own working directory. Claude sessions in different worktrees cannot conflict on file writes because they operate on separate directory trees. Key constraints: each worktree must use a unique branch name, worktrees share the same .git directory (so git operations like rebasing can still conflict), and the CLAUDECODE environment variable prevents nesting Claude inside Claude.
Quality Gates with Hooks
Two hook events are designed specifically for agent team orchestration:
TeammateIdle— Fires when a teammate finishes its current task and has nothing left to claim. Your hook can exit 0 to allow idling, or exit 2 to send feedback and keep the teammate working (e.g., “You haven’t run the tests yet”).TaskCompleted— Fires when a teammate marks a task complete. Your hook can exit 0 to accept, or exit 2 to reject and send the teammate back to work (e.g., “Tests are failing, fix them first”).
{ "hooks": { "TeammateIdle": [ { "hooks": [ { "type": "command", "command": "./.claude/hooks/check-idle-teammate.sh" } ] } ], "TaskCompleted": [ { "hooks": [ { "type": "command", "command": "./.claude/hooks/verify-task-done.sh" } ] } ] }}These hooks let you enforce quality standards automatically — no teammate can declare victory until tests pass, linting is clean, or whatever bar you set.
Agent teams are gated behind an environment variable: CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1. The feature has known issues with session resumption, task coordination timing, and shutdown sequencing. Always set the flag explicitly before launching.
Each teammate has its own context window. Five teammates means roughly five times the token cost. In plan mode, teams can cost approximately 7x standard usage per agent. Budget accordingly and consider using Sonnet for teammates while reserving Opus for the lead.