Claude · 21 · Part 10 · Hands-On Agents

Agent Teams and Parallel Work

One worker returning a summary is simple. Several workers that run at once, share a task list and message each other is a different tool, with different costs. This chapter climbs the ladder from one subagent to a full agent team, runs the part of it that can be run non-interactively, and is plain about the part that was not run.

1
Real parallel run
0
Team sessions run
3
Team prompts (illustrative)
Information current as of: 2026-10-31. The parallel run used Claude Code 2.1.316 on the bookshelf project. Agent teams are documented by Anthropic as experimental and disabled by default, so details here may change. Read Chapter 20 first.
01
Choosing

From One Helper to a Team

Before reaching for a team, Anthropic's own guidance is to check whether a lighter option does the job: subagents inside one session, or separate sessions that you run yourself and that pass findings between them (Source 1). The difference is in who talks to whom.

Who talks to whom
Subagents main agent sub A sub B sub C each reports only to the caller Agent team lead mate 1 mate 2 mate 3 shared task list mates also message each other
SubagentsAgent teams
ContextOwn window; result returns to the callerOwn window; fully independent sessions
CommunicationReport to the caller (named ones can also message each other)Teammates message each other directly
CoordinationThe main agent manages everythingShared task list plus messages
Best forFocused jobs where only the result mattersWork that needs discussion and challenge
Token costLower: results are summarised backHigher: every teammate is a separate Claude instance

The table is Anthropic's comparison (Source 1), condensed. Notice that it gives no numbers for cost, and neither does this chapter: the documentation says only that teams use significantly more tokens and that usage scales with the number of active teammates.

02
Real Run

Parallel Subagents, Run for Real

Agent teams cannot be run the way the other samples in this guide were, and section 03 explains why. What can be run non-interactively is the step below the team: two subagents from Chapter 20 working at the same time on different files. I asked a small, cheap main model (haiku) to coordinate, and let the two agents' own files choose their models:

Real run AG-03: prompt, every step, and the answer (Checked)
Prompt as sent
In parallel, use the sql-reviewer subagent on BookService and the api-reviewer subagent on BookController, each with a complete self-contained prompt. Then give me one combined list of the single most important finding from each, with file and line.
Who did what, in order · executed 2026-10-31
#WhoEventContent (shortened)
1Main sessionAgent callsubagent_type=sql-reviewer
2Main sessionAgent callsubagent_type=api-reviewer
3SubagentGlob call{"pattern": "**/*.java", "path": "<project>"}
4Main sessionBash call{"command": "sleep 1", "description": "Wait briefly for background reviewers"}
5SubagentGrep call{"pattern": "class BookController|class ApiExceptionHandler", "path": "<project>", "output_mode": "files_with_matches"}
6SubagentRead call{"file_path": "<project>/src/main/java/com/example/bookshelf/BookService.java"}
7SubagentRead call{"file_path": "<project>/src/main/java/com/example/bookshelf/BookController.java"}
8SubagentRead call{"file_path": "<project>/src/main/java/com/example/bookshelf/Book.java"}
9SubagentRead call{"file_path": "<project>/src/main/java/com/example/bookshelf/ApiExceptionHandler.java"}
10Main sessionTextThe two reviewers are still running in the background. I'll share the combined list once both have reported back.
11SubagentRead call{"file_path": "<project>/src/main/java/com/example/bookshelf/BookRepository.java"}
12SubagentRead call{"file_path": "<project>/src/main/java/com/example/bookshelf/Author.java"}
13SubagentRead call{"file_path": "<project>/src/main/java/com/example/bookshelf/BookDto.java"}
14SubagentGlob call{"pattern": "src/main/java/com/example/bookshelf/*.java", "path": "<project>"}
15SubagentRead call{"file_path": "<project>/src/main/java/com/example/bookshelf/CreateBookRequest.java"}
16SubagentRead call{"file_path": "<project>/src/main/java/com/example/bookshelf/BookDto.java"}
17SubagentRead call{"file_path": "<project>/src/main/java/com/example/bookshelf/BookService.java"}
18SubagentText**Finding: `findById` runs two SELECTs for one book. It's a minor N+1 on a single row, not a correctness bug.** - **File and line:** `<proj…
19SubagentGrep call{"pattern": "problemdetails|error\\.|ProblemDetail|ResponseEntityExceptionHandler", "path": "<scratch>", "output_mode": "content", "-n": true, "glob":
20SubagentText**Finding: validation failures on `POST /api/books` bypass ProblemDetail.** - **Where:** `<project>/src/main/java/com/example/bookshelf/Boo…
21Main sessionGrep call{"pattern": "problemdetails", "path": "<project>", "output_mode": "content", "-n": true}
22Main sessionTextBoth reviewers finished. Here is one combined list, with the most important finding from each. 1. **BookService: `findById` triggers an ext…
Final answer shown to you · 6 turns, 47.3 s, estimated $0.130, models claude-haiku-5-5, claude-sonnet-5-5, 3 result events (costs summed)
Both reviewers finished. Here is one combined list, with the most important finding from each. 1. **BookService: `findById` triggers an extra query (minor N+1).** `src/main/java/com/example/bookshelf/BookService.java:30` - `Book.author` is LAZY, and the inherited `findById` has no `@EntityGraph`. `BookDto.from` then reads the author, so each call runs two SELECTs: one for the book and one for the author. - It is not a correctness bug, because the access happens inside `@Transactional(readOnly = true)`. - Fix: add `@EntityGraph(attributePaths = "author") Optional<Book> findWithAuthorById(Long id);` to `BookRepository` and call it from `findById`. - The list and search methods (`BookService.java:20` and `:25`) already use the entity graph, so `BookQueryCountTest` is not affected. 2. **BookController: validation errors on `POST /api/books` may not come back as ProblemDetail.** `src/main/java/com/example/bookshelf/BookController.java:42`, with the gap in `ApiExceptionHandler.java:11-14`. - `create` uses `@Valid`, but `ApiExceptionHandler` only handles `BookNotFoundException`. A `MethodArgumentNotValidException` is therefore not handled by the project's handler. - The reviewer expected a default Spring error body. I could not confirm that. I grepped the project for `problemdetails` and found no match, so the `spring.mvc.problemdetails` setting is not configured. With that setting off, Spring's default error body is what I'd expect, but I did not run the app to see the response. - Fix: add an `@ExceptionHandler(MethodArgumentNotValidException.class)` to `ApiExceptionHandler` that returns a 400 `ProblemDetail` with the field errors. The same handler would also cover the missing `title` parameter at `BookController.java:31` and the non-numeric `{id}` at line 36. Caveat: the SQL reviewer did not read `AuthorRepository.findByName` or the tests. The API reviewer did not read `Book.java` or `BookNotFoundException.java`. Neither gap changes the two findings above.
Author's check: Checked. Both findings hold. findById: 2 statements measured with the temporary test (see AG-01). Validation: the three unhandled 400 cases returned no problem+json in my MockMvc probe (see AG-02). Cited lines match (BookService.java:30, BookController.java:42, ApiExceptionHandler.java:11-14). The combined answer is appropriately cautious: it says it did not run the app. Two oddities in the log: the main session wrote "still running" and the run produced three result events, and the cost is the sum of all three (the second repeats the first, so the estimate is slightly high).

What the log shows, and what it does not:

  • Parallel: the main session issued both Agent calls in a row before either reviewer had finished, and the table interleaves the reviewers' own calls. Their results arrived separately.
  • Mixed models: the log lists both claude-haiku-5-5 and claude-sonnet-5-5. I did not trace which step used which.
  • A messy edge: the main session first answered "still running in the background", then produced a combined answer after the reviewers reported. The log contains three result events, and the cost shown is the sum of all three. The second repeats the first, so the figure is slightly high. If you script around claude -p and subagents, expect more than one result and do not assume the first is final.
  • Checked: both findings were verified against the code and by measurement (see the author's check). The combined answer was properly cautious about what the reviewers had not run.
This is the 80% case. If your task is "look at two or three independent things and tell me what you found", parallel subagents do it with lower cost and no coordination machinery. Reach for a team when the workers need to argue with each other or share intermediate results.
03
Starting a Team · Not Executed

Turning Teams On

Nothing in sections 03 to 06 was run. According to the documentation, spawning teammates requires an interactive session: in non-interactive mode (claude -p, including SDK sessions) Claude does not spawn teammates, and a subagent that Claude names runs as an ordinary subagent even with teams enabled (Source 1). Every sample in this guide is captured with -p, so I had no honest way to record a team session, and I did not fake one. Treat the rest as documentation read and organised, plus prompts I wrote and did not execute.

The facts, from Anthropic's page:

  • It is off by default. Set the environment variable CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS to 1 in your shell or in settings.json under env. Without it no team is set up and Claude does not propose teammates.
  • Enabling it changes ordinary delegation. While it is on, a subagent that Claude gives a name to launches as a teammate, so a team can form even when you did not ask for one. Setting the variable to 0 turns that back off.
  • You describe the team in plain words. The lead session creates the shared task list, spawns teammates and synthesises results. You can ask for specific names and models ("use Sonnet for each teammate").
  • Two display modes. In-process (the default; all teammates inside your terminal, with arrow keys and Enter to open a teammate's transcript) or split panes, which need tmux or iTerm2 and are not supported in VS Code's integrated terminal, Windows Terminal or Ghostty. The teammateMode setting and an experimental --teammate-mode flag choose between them.
  • Roles can be reused. You can name a subagent definition when spawning a teammate, so a sql-reviewer file works both as a delegated subagent and as a teammate. The definition's tools and model apply and its body is added to the teammate's instructions. Its skills are not applied, and mcpServers applies only to split-pane teammates.
04
Three Prompts · Illustrative

Team Prompts for the Bookshelf Project

Anthropic's page recommends starting with research and review, which have clear boundaries and avoid the file-conflict problems of parallel coding, and says the strongest cases are research and review, new modules, competing-hypothesis debugging and work that spans layers. These three prompts follow that advice for bookshelf. They are the author's, written for this chapter and not executed. They are patterns, not recorded results.

Prompt A · competing hypotheses (illustrative, not executed)
Users report that GET /api/books got slow after we seeded 10,000 books. Spawn three teammates named hyp-sql, hyp-mapping and hyp-data. Each investigates one theory (query count, DTO mapping, test data shape). Each teammate must also try to disprove the other two theories using evidence from the code. Read-only: nobody edits files. Write the surviving explanation, with file and line references, to docs/findings.md.

The documentation's reasoning for this shape is that a single investigator tends to stop at the first plausible explanation, while several investigators trying to disprove each other are less anchored (Source 1). That is the documented mechanism, not something shown here.

Prompt B · three-lens review using your own agent files (illustrative, not executed)
Review the last commit. Spawn three teammates: - one using the sql-reviewer agent type (persistence cost) - one using the api-reviewer agent type (HTTP contract) - one named test-gap, plain, checking whether each changed behaviour has a test Each reports findings with file and line. Do not edit anything. When all three have reported, merge into one list ordered by severity, and mark any finding that two reviewers disagree on.
Prompt C · parallel build with file ownership (illustrative, not executed)
Add GET /api/authors that lists authors with their book counts. Switch to plan mode first. Spawn three teammates: - api: owns BookController-style AuthorController and the DTO only - data: owns AuthorRepository and the service method only - tests: owns the new test classes only No teammate edits a file another owns. Each proposes its plan before editing. Run ./mvnw -B test at the end and report the real result.
Why prompt C names file owners. The page warns that two teammates editing the same file leads to overwrites, and advises breaking work so each teammate owns a different set of files. It also recommends planning first for risky work: a teammate spawned while the lead is in plan mode stays read-only until its plan is ready. One detail to read twice: unless you change that teammate's permission mode, Claude Code approves the plan as soon as the request arrives, without the lead reviewing it (Source 1).
05
Mechanics · From the Docs

Controlling a Team

PartHow it works (documented)
Task listTasks are pending, in progress or completed, and may depend on others. A blocked task is not self-claimed. Claiming uses file locking so two teammates cannot take the same task
AssigningThe lead assigns, or a teammate claims the next unassigned, unblocked task itself
MessagingEach agent has a mailbox file; messages arrive automatically. You can open a teammate and message it directly
PermissionsTeammates start with the lead's permission mode, except dontAsk, which they do not inherit. Their permission prompts appear in the lead's session
Messages are not approvalA message from another agent never counts as your consent, and a teammate cannot relay a denied action to another teammate
Quality gatesHooks TeammateIdle, TaskCreated and TaskCompleted: exit with code 2 to send feedback and keep the teammate working or block the task action
ShutdownAsk the lead to shut a teammate down; the teammate can approve or refuse. The team's config directory is removed when the session ends; the task list stays on disk for the cleanup period

The hook rows are the practical lever. They are how you stop a teammate marking a task done while the build is red. The hooks lab in Chapter 22 covers the whole contract; the short version: exit code 2 is the "block and tell Claude" signal in Claude Code's hook system.

06
Limits and Cost

What Teams Cost and Where They Break

The documented limitations are worth reading as a checklist before you start, because several are about losing work:

  • No session resumption for in-process teammates. /resume and /rewind do not restore them; the lead may try to message teammates that no longer exist.
  • Task status can lag. Teammates sometimes do not mark tasks complete, which blocks dependent tasks. You may need to nudge or update status by hand.
  • One team per session, no nested teams, fixed lead. Teammates cannot spawn teams, and a teammate cannot become the lead.
  • The lead can finish early or start doing the work itself. The page suggests telling it to wait for teammates.
  • Split panes need tmux or iTerm2, and orphaned tmux sessions can remain after a session ends.

On size: the documentation suggests starting with three to five teammates and about five or six tasks per teammate, and says token cost scales linearly with the number of active teammates. A team is a bet that parallel exploration is worth that multiple. For routine work, a single session or a subagent is the better bet, which is the same answer the comparison table gave.

07
Summary

Key Takeaways, Exercises and Sources

∑ Teams and parallel work: what to remember
  • Climb the ladder one rung at a time: a single session, then subagents, then forks or your own parallel sessions, then a team.
  • Parallel subagents are the cheap 80%. They work non-interactively, and the log shows both agents' calls.
  • Teams are for debate and shared state: competing hypotheses, multi-lens review, owned modules.
  • Experimental and interactive-only. Teams are off by default and are not spawned under claude -p.
  • Own the files, gate the tasks. Give each teammate separate files and use hooks to enforce quality.
Exercises

Exercise 1 Beginner

Take a review you would normally do in three passes (security, performance, tests). Run it as three parallel subagents in one prompt. Compare the time and the quality with doing it as one long prompt, and note which findings only one lens produced.

Learning outcome: feel the value and cost of parallelism without a team.

Exercise 2 Intermediate

Enable agent teams in a throwaway project and run Prompt A against a bug you already understand. Open each teammate's transcript. Did the debate change the answer, or did one teammate simply win? Write down what you saw before you read any summary.

Learning outcome: judge a team on evidence, not on the narrative.

Exercise 3 Advanced

Write a TaskCompleted hook that runs your test command and exits with code 2 when it fails. Then deliberately break a test, ask a teammate to finish a task, and check that completion is refused. Read the hooks reference first for the input format; do not guess it.

Learning outcome: enforce quality gates mechanically.

Sources (read on 2026-10-31; paraphrased)
  1. Anthropic, Orchestrate teams of Claude Code sessions — status and enabling, comparison with subagents, display modes, task list and mailbox architecture, subagent definitions as teammates, permissions, hooks, token usage, best practices and limitations. The page was read in full.
  2. Anthropic, Create custom subagents — used for the subagent side of the comparison and for forks.

Only AG-03 (parallel subagents) was executed, on 2026-10-31. No agent team was started, and no output from one appears anywhere in this guide. The three team prompts are the author's and are labelled illustrative.