agent-teams.md +399 −0 added
1> ## Documentation Index
2> Fetch the complete documentation index at: https://code.claude.com/docs/llms.txt
3> Use this file to discover all available pages before exploring further.
4
5# Orchestrate teams of Claude Code sessions
6
7> Coordinate multiple Claude Code instances working together as a team, with shared tasks, inter-agent messaging, and centralized management.
8
9<Warning>
10 Agent teams are experimental and disabled by default. Enable them by adding `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` to your [settings.json](/en/settings) or environment. Agent teams have [known limitations](#limitations) around session resumption, task coordination, and shutdown behavior.
11</Warning>
12
13Agent teams let you coordinate multiple Claude Code instances working together. One session acts as the team lead, coordinating work, assigning tasks, and synthesizing results. Teammates work independently, each in its own context window, and communicate directly with each other.
14
15Unlike [subagents](/en/sub-agents), which run within a single session and can only report back to the main agent, you can also interact with individual teammates directly without going through the lead.
16
17This page covers:
18
19* [When to use agent teams](#when-to-use-agent-teams), including best use cases and how they compare with subagents
20* [Starting a team](#start-your-first-agent-team)
21* [Controlling teammates](#control-your-agent-team), including display modes, task assignment, and delegation
22* [Best practices for parallel work](#best-practices)
23
24## When to use agent teams
25
26Agent teams are most effective for tasks where parallel exploration adds real value. See [use case examples](#use-case-examples) for full scenarios. The strongest use cases are:
27
28* **Research and review**: multiple teammates can investigate different aspects of a problem simultaneously, then share and challenge each other's findings
29* **New modules or features**: teammates can each own a separate piece without stepping on each other
30* **Debugging with competing hypotheses**: teammates test different theories in parallel and converge on the answer faster
31* **Cross-layer coordination**: changes that span frontend, backend, and tests, each owned by a different teammate
32
33Agent teams add coordination overhead and use significantly more tokens than a single session. They work best when teammates can operate independently. For sequential tasks, same-file edits, or work with many dependencies, a single session or [subagents](/en/sub-agents) are more effective.
34
35### Compare with subagents
36
37Both agent teams and [subagents](/en/sub-agents) let you parallelize work, but they operate differently. Choose based on whether your workers need to communicate with each other:
38
39<Frame caption="Subagents only report results back to the main agent and never talk to each other. In agent teams, teammates share a task list, claim work, and communicate directly with each other.">
40 <img src="https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-light.png?fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=2f8db9b4f3705dd3ab931fbe2d96e42a" className="dark:hidden" alt="Diagram comparing subagent and agent team architectures. Subagents are spawned by the main agent, do work, and report results back. Agent teams coordinate through a shared task list, with teammates communicating directly with each other." data-og-width="4245" width="4245" data-og-height="1615" height="1615" data-path="images/subagents-vs-agent-teams-light.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-light.png?w=280&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=a2cfe413c2084b477be40ac8723d9d40 280w, https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-light.png?w=560&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=c642c09a4c211b10b35eee7d7d0d149f 560w, https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-light.png?w=840&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=40d286f77c8a4075346b4fcaa2b36248 840w, https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-light.png?w=1100&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=923986caa23c0ef2c27d7e45f4dce6d1 1100w, https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-light.png?w=1650&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=17a730a070db6d71d029a98b074c68e8 1650w, https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-light.png?w=2500&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=e402533fc9e8b5e8d26a835cc4aa1742 2500w" />
41
42 <img src="https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-dark.png?fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=d573a037540f2ada6a9ae7d8285b46fd" className="hidden dark:block" alt="Diagram comparing subagent and agent team architectures. Subagents are spawned by the main agent, do work, and report results back. Agent teams coordinate through a shared task list, with teammates communicating directly with each other." data-og-width="4245" width="4245" data-og-height="1615" height="1615" data-path="images/subagents-vs-agent-teams-dark.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-dark.png?w=280&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=06ca5b18b232855acc488357d8d01fa7 280w, https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-dark.png?w=560&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=3d34daee83994781eb74b74d1ed511c4 560w, https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-dark.png?w=840&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=82ea35ac837de7d674002de69689b9cf 840w, https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-dark.png?w=1100&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=3653085214a9fc65d1f589044894a296 1100w, https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-dark.png?w=1650&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=8e74b42694e428570e876d34f29e6ad6 1650w, https://mintcdn.com/claude-code/nsvRFSDNfpSU5nT7/images/subagents-vs-agent-teams-dark.png?w=2500&fit=max&auto=format&n=nsvRFSDNfpSU5nT7&q=85&s=3be00c56c6a0dcccbe15640020be0128 2500w" />
43</Frame>
44
45| | Subagents | Agent teams |
46| :---------------- | :----------------------------------------------- | :-------------------------------------------------- |
47| **Context** | Own context window; results return to the caller | Own context window; fully independent |
48| **Communication** | Report results back to the main agent only | Teammates message each other directly |
49| **Coordination** | Main agent manages all work | Shared task list with self-coordination |
50| **Best for** | Focused tasks where only the result matters | Complex work requiring discussion and collaboration |
51| **Token cost** | Lower: results summarized back to main context | Higher: each teammate is a separate Claude instance |
52
53Use subagents when you need quick, focused workers that report back. Use agent teams when teammates need to share findings, challenge each other, and coordinate on their own.
54
55## Enable agent teams
56
57Agent teams are disabled by default. Enable them by setting the `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` environment variable to `1`, either in your shell environment or through [settings.json](/en/settings):
58
59```json settings.json theme={null}
60{
61 "env": {
62 "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
63 }
64}
65```
66
67## Start your first agent team
68
69After enabling agent teams, tell Claude to create an agent team and describe the task and the team structure you want in natural language. Claude creates the team, spawns teammates, and coordinates work based on your prompt.
70
71This example works well because the three roles are independent and can explore the problem without waiting on each other:
72
73```
74I'm designing a CLI tool that helps developers track TODO comments across
75their codebase. Create an agent team to explore this from different angles: one
76teammate on UX, one on technical architecture, one playing devil's advocate.
77```
78
79From there, Claude creates a team with a [shared task list](/en/interactive-mode#task-list), spawns teammates for each perspective, has them explore the problem, synthesizes findings, and attempts to [clean up the team](#clean-up-the-team) when finished.
80
81The lead's terminal lists all teammates and what they're working on. Use Shift+Down to cycle through teammates and message them directly. After the last teammate, Shift+Down wraps back to the lead.
82
83If you want each teammate in its own split pane, see [Choose a display mode](#choose-a-display-mode).
84
85## Control your agent team
86
87Tell the lead what you want in natural language. It handles team coordination, task assignment, and delegation based on your instructions.
88
89### Choose a display mode
90
91Agent teams support two display modes:
92
93* **In-process**: all teammates run inside your main terminal. Use Shift+Down to cycle through teammates and type to message them directly. Works in any terminal, no extra setup required.
94* **Split panes**: each teammate gets its own pane. You can see everyone's output at once and click into a pane to interact directly. Requires tmux, or iTerm2.
95
96<Note>
97 `tmux` has known limitations on certain operating systems and traditionally works best on macOS. Using `tmux -CC` in iTerm2 is the suggested entrypoint into `tmux`.
98</Note>
99
100The default is `"auto"`, which uses split panes if you're already running inside a tmux session, and in-process otherwise. The `"tmux"` setting enables split-pane mode and auto-detects whether to use tmux or iTerm2 based on your terminal. To override, set `teammateMode` in your [settings.json](/en/settings):
101
102```json theme={null}
103{
104 "teammateMode": "in-process"
105}
106```
107
108To force in-process mode for a single session, pass it as a flag:
109
110```bash theme={null}
111claude --teammate-mode in-process
112```
113
114Split-pane mode requires either [tmux](https://github.com/tmux/tmux/wiki) or iTerm2 with the [`it2` CLI](https://github.com/mkusaka/it2). To install manually:
115
116* **tmux**: install through your system's package manager. See the [tmux wiki](https://github.com/tmux/tmux/wiki/Installing) for platform-specific instructions.
117* **iTerm2**: install the [`it2` CLI](https://github.com/mkusaka/it2), then enable the Python API in **iTerm2 → Settings → General → Magic → Enable Python API**.
118
119### Specify teammates and models
120
121Claude decides the number of teammates to spawn based on your task, or you can specify exactly what you want:
122
123```
124Create a team with 4 teammates to refactor these modules in parallel.
125Use Sonnet for each teammate.
126```
127
128### Require plan approval for teammates
129
130For complex or risky tasks, you can require teammates to plan before implementing. The teammate works in read-only plan mode until the lead approves their approach:
131
132```
133Spawn an architect teammate to refactor the authentication module.
134Require plan approval before they make any changes.
135```
136
137When a teammate finishes planning, it sends a plan approval request to the lead. The lead reviews the plan and either approves it or rejects it with feedback. If rejected, the teammate stays in plan mode, revises based on the feedback, and resubmits. Once approved, the teammate exits plan mode and begins implementation.
138
139The lead makes approval decisions autonomously. To influence the lead's judgment, give it criteria in your prompt, such as "only approve plans that include test coverage" or "reject plans that modify the database schema."
140
141### Talk to teammates directly
142
143Each teammate is a full, independent Claude Code session. You can message any teammate directly to give additional instructions, ask follow-up questions, or redirect their approach.
144
145* **In-process mode**: use Shift+Down to cycle through teammates, then type to send them a message. Press Enter to view a teammate's session, then Escape to interrupt their current turn. Press Ctrl+T to toggle the task list.
146* **Split-pane mode**: click into a teammate's pane to interact with their session directly. Each teammate has a full view of their own terminal.
147
148### Assign and claim tasks
149
150The shared task list coordinates work across the team. The lead creates tasks and teammates work through them. Tasks have three states: pending, in progress, and completed. Tasks can also depend on other tasks: a pending task with unresolved dependencies cannot be claimed until those dependencies are completed.
151
152The lead can assign tasks explicitly, or teammates can self-claim:
153
154* **Lead assigns**: tell the lead which task to give to which teammate
155* **Self-claim**: after finishing a task, a teammate picks up the next unassigned, unblocked task on its own
156
157Task claiming uses file locking to prevent race conditions when multiple teammates try to claim the same task simultaneously.
158
159### Shut down teammates
160
161To gracefully end a teammate's session:
162
163```
164Ask the researcher teammate to shut down
165```
166
167The lead sends a shutdown request. The teammate can approve, exiting gracefully, or reject with an explanation.
168
169### Clean up the team
170
171When you're done, ask the lead to clean up:
172
173```
174Clean up the team
175```
176
177This removes the shared team resources. When the lead runs cleanup, it checks for active teammates and fails if any are still running, so shut them down first.
178
179<Warning>
180 Always use the lead to clean up. Teammates should not run cleanup because their team context may not resolve correctly, potentially leaving resources in an inconsistent state.
181</Warning>
182
183### Enforce quality gates with hooks
184
185Use [hooks](/en/hooks) to enforce rules when teammates finish work or tasks complete:
186
187* [`TeammateIdle`](/en/hooks#teammateidle): runs when a teammate is about to go idle. Exit with code 2 to send feedback and keep the teammate working.
188* [`TaskCompleted`](/en/hooks#taskcompleted): runs when a task is being marked complete. Exit with code 2 to prevent completion and send feedback.
189
190## How agent teams work
191
192This section covers the architecture and mechanics behind agent teams. If you want to start using them, see [Control your agent team](#control-your-agent-team) above.
193
194### How Claude starts agent teams
195
196There are two ways agent teams get started:
197
198* **You request a team**: give Claude a task that benefits from parallel work and explicitly ask for an agent team. Claude creates one based on your instructions.
199* **Claude proposes a team**: if Claude determines your task would benefit from parallel work, it may suggest creating a team. You confirm before it proceeds.
200
201In both cases, you stay in control. Claude won't create a team without your approval.
202
203### Architecture
204
205An agent team consists of:
206
207| Component | Role |
208| :------------ | :----------------------------------------------------------------------------------------- |
209| **Team lead** | The main Claude Code session that creates the team, spawns teammates, and coordinates work |
210| **Teammates** | Separate Claude Code instances that each work on assigned tasks |
211| **Task list** | Shared list of work items that teammates claim and complete |
212| **Mailbox** | Messaging system for communication between agents |
213
214See [Choose a display mode](#choose-a-display-mode) for display configuration options. Teammate messages arrive at the lead automatically.
215
216The system manages task dependencies automatically. When a teammate completes a task that other tasks depend on, blocked tasks unblock without manual intervention.
217
218Teams and tasks are stored locally:
219
220* **Team config**: `~/.claude/teams/{team-name}/config.json`
221* **Task list**: `~/.claude/tasks/{team-name}/`
222
223The team config contains a `members` array with each teammate's name, agent ID, and agent type. Teammates can read this file to discover other team members.
224
225### Permissions
226
227Teammates start with the lead's permission settings. If the lead runs with `--dangerously-skip-permissions`, all teammates do too. After spawning, you can change individual teammate modes, but you can't set per-teammate modes at spawn time.
228
229### Context and communication
230
231Each teammate has its own context window. When spawned, a teammate loads the same project context as a regular session: CLAUDE.md, MCP servers, and skills. It also receives the spawn prompt from the lead. The lead's conversation history does not carry over.
232
233**How teammates share information:**
234
235* **Automatic message delivery**: when teammates send messages, they're delivered automatically to recipients. The lead doesn't need to poll for updates.
236* **Idle notifications**: when a teammate finishes and stops, they automatically notify the lead.
237* **Shared task list**: all agents can see task status and claim available work.
238
239**Teammate messaging:**
240
241* **message**: send a message to one specific teammate
242* **broadcast**: send to all teammates simultaneously. Use sparingly, as costs scale with team size.
243
244### Token usage
245
246Agent teams use significantly more tokens than a single session. Each teammate has its own context window, and token usage scales with the number of active teammates. For research, review, and new feature work, the extra tokens are usually worthwhile. For routine tasks, a single session is more cost-effective. See [agent team token costs](/en/costs#agent-team-token-costs) for usage guidance.
247
248## Use case examples
249
250These examples show how agent teams handle tasks where parallel exploration adds value.
251
252### Run a parallel code review
253
254A single reviewer tends to gravitate toward one type of issue at a time. Splitting review criteria into independent domains means security, performance, and test coverage all get thorough attention simultaneously. The prompt assigns each teammate a distinct lens so they don't overlap:
255
256```
257Create an agent team to review PR #142. Spawn three reviewers:
258- One focused on security implications
259- One checking performance impact
260- One validating test coverage
261Have them each review and report findings.
262```
263
264Each reviewer works from the same PR but applies a different filter. The lead synthesizes findings across all three after they finish.
265
266### Investigate with competing hypotheses
267
268When the root cause is unclear, a single agent tends to find one plausible explanation and stop looking. The prompt fights this by making teammates explicitly adversarial: each one's job is not only to investigate its own theory but to challenge the others'.
269
270```
271Users report the app exits after one message instead of staying connected.
272Spawn 5 agent teammates to investigate different hypotheses. Have them talk to
273each other to try to disprove each other's theories, like a scientific
274debate. Update the findings doc with whatever consensus emerges.
275```
276
277The debate structure is the key mechanism here. Sequential investigation suffers from anchoring: once one theory is explored, subsequent investigation is biased toward it.
278
279With multiple independent investigators actively trying to disprove each other, the theory that survives is much more likely to be the actual root cause.
280
281## Best practices
282
283### Give teammates enough context
284
285Teammates load project context automatically, including CLAUDE.md, MCP servers, and skills, but they don't inherit the lead's conversation history. See [Context and communication](#context-and-communication) for details. Include task-specific details in the spawn prompt:
286
287```
288Spawn a security reviewer teammate with the prompt: "Review the authentication module
289at src/auth/ for security vulnerabilities. Focus on token handling, session
290management, and input validation. The app uses JWT tokens stored in
291httpOnly cookies. Report any issues with severity ratings."
292```
293
294### Choose an appropriate team size
295
296There's no hard limit on the number of teammates, but practical constraints apply:
297
298* **Token costs scale linearly**: each teammate has its own context window and consumes tokens independently. See [agent team token costs](/en/costs#agent-team-token-costs) for details.
299* **Coordination overhead increases**: more teammates means more communication, task coordination, and potential for conflicts
300* **Diminishing returns**: beyond a certain point, additional teammates don't speed up work proportionally
301
302Start with 3-5 teammates for most workflows. This balances parallel work with manageable coordination. The examples in this guide use 3-5 teammates because that range works well across different task types.
303
304Having 5-6 [tasks](/en/agent-teams#architecture) per teammate keeps everyone productive without excessive context switching. If you have 15 independent tasks, 3 teammates is a good starting point.
305
306Scale up only when the work genuinely benefits from having teammates work simultaneously. Three focused teammates often outperform five scattered ones.
307
308### Size tasks appropriately
309
310* **Too small**: coordination overhead exceeds the benefit
311* **Too large**: teammates work too long without check-ins, increasing risk of wasted effort
312* **Just right**: self-contained units that produce a clear deliverable, such as a function, a test file, or a review
313
314<Tip>
315 The lead breaks work into tasks and assigns them to teammates automatically. If it isn't creating enough tasks, ask it to split the work into smaller pieces. Having 5-6 tasks per teammate keeps everyone productive and lets the lead reassign work if someone gets stuck.
316</Tip>
317
318### Wait for teammates to finish
319
320Sometimes the lead starts implementing tasks itself instead of waiting for teammates. If you notice this:
321
322```
323Wait for your teammates to complete their tasks before proceeding
324```
325
326### Start with research and review
327
328If you're new to agent teams, start with tasks that have clear boundaries and don't require writing code: reviewing a PR, researching a library, or investigating a bug. These tasks show the value of parallel exploration without the coordination challenges that come with parallel implementation.
329
330### Avoid file conflicts
331
332Two teammates editing the same file leads to overwrites. Break the work so each teammate owns a different set of files.
333
334### Monitor and steer
335
336Check in on teammates' progress, redirect approaches that aren't working, and synthesize findings as they come in. Letting a team run unattended for too long increases the risk of wasted effort.
337
338## Troubleshooting
339
340### Teammates not appearing
341
342If teammates aren't appearing after you ask Claude to create a team:
343
344* In in-process mode, teammates may already be running but not visible. Press Shift+Down to cycle through active teammates.
345* Check that the task you gave Claude was complex enough to warrant a team. Claude decides whether to spawn teammates based on the task.
346* If you explicitly requested split panes, ensure tmux is installed and available in your PATH:
347 ```bash theme={null}
348 which tmux
349 ```
350* For iTerm2, verify the `it2` CLI is installed and the Python API is enabled in iTerm2 preferences.
351
352### Too many permission prompts
353
354Teammate permission requests bubble up to the lead, which can create friction. Pre-approve common operations in your [permission settings](/en/permissions) before spawning teammates to reduce interruptions.
355
356### Teammates stopping on errors
357
358Teammates may stop after encountering errors instead of recovering. Check their output using Shift+Down in in-process mode or by clicking the pane in split mode, then either:
359
360* Give them additional instructions directly
361* Spawn a replacement teammate to continue the work
362
363### Lead shuts down before work is done
364
365The lead may decide the team is finished before all tasks are actually complete. If this happens, tell it to keep going. You can also tell the lead to wait for teammates to finish before proceeding if it starts doing work instead of delegating.
366
367### Orphaned tmux sessions
368
369If a tmux session persists after the team ends, it may not have been fully cleaned up. List sessions and kill the one created by the team:
370
371```bash theme={null}
372tmux ls
373tmux kill-session -t <session-name>
374```
375
376## Limitations
377
378Agent teams are experimental. Current limitations to be aware of:
379
380* **No session resumption with in-process teammates**: `/resume` and `/rewind` do not restore in-process teammates. After resuming a session, the lead may attempt to message teammates that no longer exist. If this happens, tell the lead to spawn new teammates.
381* **Task status can lag**: teammates sometimes fail to mark tasks as completed, which blocks dependent tasks. If a task appears stuck, check whether the work is actually done and update the task status manually or tell the lead to nudge the teammate.
382* **Shutdown can be slow**: teammates finish their current request or tool call before shutting down, which can take time.
383* **One team per session**: a lead can only manage one team at a time. Clean up the current team before starting a new one.
384* **No nested teams**: teammates cannot spawn their own teams or teammates. Only the lead can manage the team.
385* **Lead is fixed**: the session that creates the team is the lead for its lifetime. You can't promote a teammate to lead or transfer leadership.
386* **Permissions set at spawn**: all teammates start with the lead's permission mode. You can change individual teammate modes after spawning, but you can't set per-teammate modes at spawn time.
387* **Split panes require tmux or iTerm2**: the default in-process mode works in any terminal. Split-pane mode isn't supported in VS Code's integrated terminal, Windows Terminal, or Ghostty.
388
389<Tip>
390 **`CLAUDE.md` works normally**: teammates read `CLAUDE.md` files from their working directory. Use this to provide project-specific guidance to all teammates.
391</Tip>
392
393## Next steps
394
395Explore related approaches for parallel work and delegation:
396
397* **Lightweight delegation**: [subagents](/en/sub-agents) spawn helper agents for research or verification within your session, better for tasks that don't need inter-agent coordination
398* **Manual parallel sessions**: [Git worktrees](/en/common-workflows#run-parallel-claude-code-sessions-with-git-worktrees) let you run multiple Claude Code sessions yourself without automated team coordination
399* **Compare approaches**: see the [subagent vs agent team](/en/features-overview#compare-similar-features) comparison for a side-by-side breakdown