Claude Code guide in three levels, Beginner to Advanced: hands-on lessons with checked exercises, every volatile fact cited to its source. Independent community guide.
Agent teams
Advanced · Elective · about 20 minutes, plus run time · Needs: Choose an orchestration pattern · Verified against Claude Code v2.1.292 (stable) on 2026-10-15
[!NOTE] "Agent teams are experimental and disabled by default." (Orchestrate teams of Claude Code sessions)
Goal
By the end of this Elective you can staff an agent team from your own subagent definitions, show that a team formed, and shut its teammates down by name.
You need
- Choose an orchestration pattern, and the subagent definitions you wrote in Delegate to a custom subagent.
- One of your own repositories, with its
.practice/folder set up as the Intermediate index describes. - macOS, Linux or WSL 2, and
jq: the hooks that log the team are shell commands that use it. - An interactive session: in a
-prun, Claude doesn't spawn teammates (Enable agent teams). The default in-process display, where teammates run inside your terminal, works in any terminal (Choose a display mode). - Usage: heavy. Each teammate is a separate Claude instance with its own context window, and token usage scales with the number of active teammates (Token usage). Cheap variant: change one small file in the Worked example, run two teammates in Your turn, and shut the teammates down as soon as they report.
The idea
An agent team is several Claude Code sessions working together. Your session is the lead: it spawns teammates, each in its own context window. Teammates message each other directly, and you can message any of them, while subagents mainly return a result to the caller (Compare with subagents).
A teammate loads your CLAUDE.md, MCP servers and skills plus the lead's spawn prompt, but not the lead's conversation, so the prompt carries the task (Context and communication). Name a subagent definition in it, and the teammate runs with that definition's tools and instructions, and its model unless the spawn prompt names one; an in-process teammate also gets SendMessage, so a read-only one can still reach the others (Use subagent definitions for teammates).
Teams "use significantly more tokens than a single session" (Token usage), and teammates share your working tree (Choose an approach). Use them where independent views pay off: a review through distinct lenses, or rival hypotheses argued out.
Worked example
In your repository, download the two read-only reviewers from this guide's agent teams example. Read them before you use them:
mkdir -p .claude/agents for a in security-reviewer test-reviewer; do curl -fsSL "https://raw.githubusercontent.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/main/examples/advanced/electives/agent-teams/dot-claude/agents/$a.md" -o ".claude/agents/$a.md" done grep -H '^tools:' .claude/agents/security-reviewer.md .claude/agents/test-reviewer.mdEach line ends in
tools: Read, Grep, Glob: the reviewers can read files, but can't edit them or run commands,gitincluded. Grep and Glob, the search tools, are absent by default on macOS, Linux and WSL; a subagent that lists them and leaves out Bash gets them back (Glob tool behavior). Both setmodel: sonnet. If a session is already open here and.claude/agents/is new, restart it: Claude Code watches only the agent folders that existed when the session started (Write subagent files).Use a change you're working on, or make a throwaway one: change one tracked source file the way a real change would, for example a function that reads user input, with no new test. Leave it uncommitted. The reviewers can't run
git diff, so save the change where they can read it:git diff > .practice/a-teams.diffSave this as
.practice/a-teams.json:{ "env": { "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1" }, "teammateMode": "in-process", "hooks": { "TeammateIdle": [ { "hooks": [ { "type": "command", "command": "jq -r '.teammate_name' >> \"$CLAUDE_PROJECT_DIR/.practice/a-teams-teammates.txt\"" } ] } ] } }It turns agent teams on only for the sessions you start with it (Enable agent teams, Claude spawns teammates instead of subagents), and
teammateModekeeps their teammates in the in-process display that these steps describe (teammateMode). Its hook,TeammateIdle, writes each teammate's name to.practice/a-teams-teammates.txtwhen it is about to go idle.Start the lead with the file:
CLAUDE_CODE_ENABLE_TODO_TOOLS=1 claude --settings .practice/a-teams.json--settingsapplies the file's keys on top of your settings, for this session only (CLI reference). The variable gives the session the Task tools on every model; without it, Claude Code provides them only on the older models that Task tool availability lists, and teammates coordinate by message instead of a shared task list. Run/context: its custom subagents includesecurity-reviewerandtest-reviewer(See what loaded into context).Ask for the team. Give each teammate one lens, as the docs' parallel code review does, plus a name and an agent type:
Create an agent team to review the change saved in .practice/a-teams.diff and the files it touches. Spawn two teammates: one named security, using the security-reviewer agent type, and one named tests, using the test-reviewer agent type. When both have reported, write one combined report to .practice/a-teams-review.md.Claude Code launches teammates without asking you to confirm (How Claude starts agent teams). A row for each appears in the agent panel below the prompt. Subagents show in the same panel, so the panel alone doesn't prove a team formed (Start your first agent team): step 7's log does.
Ctrl+Ttoggles the task list (Talk to teammates directly). The prompt names no model, so each teammate runs on its definition'smodel, unless you've setCLAUDE_CODE_SUBAGENT_MODEL_FORCE=1(Specify teammates and models). When both have reported, the lead writes the combined report (your wording will differ); approve the write if Claude Code asks.Shut the teammates down by name:
Ask the security and tests teammates to shut down.Each teammate approves and exits, or rejects the request with an explanation (Shut down teammates); if one rejects, read its reason and ask again. A teammate whose row has disappeared from the panel is hidden, not stopped, so name it in the request too (Start your first agent team). Then exit the session. Claude Code removes the team's config when the session ends and keeps its task list for resumed sessions, so there's no separate cleanup step (Architecture).
Read the log:
sort -u .practice/a-teams-teammates.txtIt lists
securityandtests, so a team formed.
Your turn
Debug with competing hypotheses, as the docs' Investigate with competing hypotheses example does. Pick a real bug or puzzling behavior in your repository whose cause you don't know and that reading the code could explain. Write a read-only investigator definition, for example by copying test-reviewer.md to .claude/agents/hypothesis-tester.md and rewriting it. Start a new session the same way, so the lead starts clean, and have it spawn three teammates from your definition, each owning one hypothesis and messaging the others to challenge their theories. Cheap variant: two teammates.
Acceptance criteria:
- Your definition has its own
nameanddescription,model: sonnet, and a single-linetools:that names onlyRead,GrepandGlob, as the two reviewers' lines do and as the docs' read-only example does (Quickstart: create your first subagent). A definition with notoolsline inherits every tool available to subagents (Frontmatter reference). - Every teammate runs from your definition, under a name you chose in the spawn prompt.
- The lead saves the explanation that survived, and the theories it ruled out, to
.practice/a-teams-debate.md. - No tracked file changes beyond your change from the Worked example.
- You ask every teammate, by name, to shut down.
Check
You are done when all of these are true:
Every definition a teammate used is read-only. This prints nothing when each has a single-line
tools:that names onlyRead,GrepandGlob(use your definition's file name):for f in .claude/agents/security-reviewer.md .claude/agents/test-reviewer.md .claude/agents/hypothesis-tester.md; do grep -qxE 'tools: *(Read|Grep|Glob)( *, *(Read|Grep|Glob))* *' "$f" || echo "$f: tools: names more than Read, Grep and Glob, or is missing" doneA team formed, not only subagents:
sort -u .practice/a-teams-teammates.txtlists every teammate name you chose.Both results are saved:
ls .practice/a-teams-review.md .practice/a-teams-debate.mdlists both files.The teams changed no tracked file:
git diff | diff - .practice/a-teams.diffprints nothing.Self-check (not tested): the debate report says which theories the teammates ruled out and why, and you asked every teammate, by name, to shut down.
If the teammates log is missing, no team formed: start the lead with the step 4 command and ask explicitly for an agent team. If git diff differs from your saved change, the lead or a teammate edited a tracked file: read the difference, undo that edit, and check each definition's tools: line. When you're done, keep the change, or undo a throwaway one with git restore <file>.
Watch out
- Teammates start with your permission mode, except
dontAsk, and if you run with--dangerously-skip-permissions, every teammate does too. Their permission prompts appear in your session for you to answer (Permissions). While teams are on, a subagent that Claude names launches as a teammate, so a team can form when you didn't ask for one: this Elective turns teams on only for sessions started with--settings, not in your user or project settings (Enable agent teams). - Each active teammate keeps using tokens until it exits or the session ends. Keep teams small, put Sonnet in the definitions, keep spawn prompts focused, and shut teammates down when their work is done (Agent team token costs).
- Two teammates editing the same file overwrite each other's work, so give each its own files (Avoid file conflicts). And
/resumeand/rewinddon't bring in-process teammates back: after a resume, ask the lead to spawn new ones (Limitations).
Go further
- Enforce quality gates with hooks:
TeammateIdle,TaskCreatedandTaskCompletedhooks that exit with code 2 keep a teammate working, or stop a task from being created or completed, until your rule passes. - Have teammates plan before implementing: read-only planning for teams that change code. Claude Code approves each plan as it arrives, without the lead reviewing it; the teammate's edits and commands still go through your permission prompts.
- Choose a display mode: each teammate in its own tmux or iTerm2 pane, in place of the in-process panel.
Sources: Orchestrate teams of Claude Code sessions · Run agents in parallel · Create custom subagents · Hooks reference · Tools reference · All settings · CLI reference · Debug your configuration · Manage costs effectively
Back to the Advanced index · Topic: Subagents and parallel work · Stuck on this lesson?