Multi-Agent Collaboration

Beginner-Friendly Teaching Edition  ·  One person commanding an AI team
What you will learn
How to run many Claude Code instances at once instead of one: parallel sessions with Git Worktrees, subagents for specialist steps, Agent Teams that coordinate themselves, fan-out batch processing, and asynchronous execution (/schedule, /loop, Remote Control). Plus the trade-offs: cost and merge effort.
Parallel sessionsWorktreesSubagentsAgent TeamsFan-outAsync

The Big Idea

The chapter's claim: the most underrated capability of Claude Code is not how fast it writes code — it is how many instances you can run at once. Master parallelism and your workflow shifts from "one person, one AI" to "one person commanding an AI team."

While writing this book, the author ran 6 Claude Code processes at the same time, each on a different chapter. Six processes in parallel for about 2 hours produced all 10 chapter drafts — work that would take at least a full day sequentially.

The real cost, stated plainly: six agents means six separate contexts — about 6× the token consumption. That afternoon cost around $50. The writing style across agents was not perfectly consistent, so a full unifying pass was still needed. More is not always better. The real questions: can the task be split into independent pieces, and how expensive is the merge?

Why This Topic Matters

Claude Code's work pattern is: you give a task → Claude works a few minutes → you review → you give the next task. There is a lot of waiting in between.

  • With one session, you spend most of your time waiting.
  • With five sessions, you review the first while the other four still run — wait time drops to nearly zero.

Boris Cherny's day-to-day: 5 local Claude Code instances (each in its own git checkout) plus 5–10 claude.ai/code cloud sessions — one writing a feature, one fixing bugs, one writing tests, one refactoring, one doing review. His first productivity tip to his team: do more work in parallel.

Core Concepts

MechanismWhat it isUse when
Parallel sessions + WorktreesSeveral independent Claude sessions, each in an isolated filesystem/branchTasks that have nothing to do with each other
SubagentsA specialist called in for one step of your current task, with its own contextYou need an "expert" (e.g. security review) without opening a new window
Agent TeamsMultiple sessions that message each other and divide the work themselvesOne task that benefits from writer/reviewer or test-driven collaboration
Fan-out / batchThe same operation repeated across many files, run in parallelLarge refactors, migrations, bulk fixes
Async execution/schedule (cloud cron), /loop (long local runs), Remote ControlYou do not want to sit at the terminal

Topic 1 — Git Worktrees: the infrastructure for parallelism

The prerequisite: each session needs its own isolated code environment, or they overwrite each other's files and create conflicts. Git Worktrees solve exactly this — multiple working directories from the same repository, each on a different branch, with completely isolated filesystems.

# Start a Claude session running in an isolated worktree
claude --worktree
# Start inside a Tmux session (can run in the background)
claude --worktree --tmux

What this does: each claude --worktree automatically creates a new worktree, checks out a new branch, and works in that isolated environment. When done, you merge the branch back into main.

Tmux integration and quick navigation

# Add to ~/.zshrc
alias za="tmux select-window -t claude:0"
alias zb="tmux select-window -t claude:1"
alias zc="tmux select-window -t claude:2"

Explaining it: za jumps to the first session, zb the second, and so on. In the Desktop App there is a worktree checkbox in the UI — tick it, no Tmux configuration needed.

Topic 2 — Subagents: calling in a specialist

Parallel sessions suit unrelated tasks. Sometimes you instead want an "expert" to handle a specific step within your current task — like a security reviewer looking at the auth code you just wrote. That is a subagent. Drop a .md file in .claude/agents/:

.claude/agents/
├── security-reviewer.md   # Security review specialist
├── code-simplifier.md     # Code simplification specialist
├── verify-app.md          # Application verification specialist
└── code-architect.md      # Architecture design specialist

Each agent file can define a custom name, tool permissions, permission mode, and even which model to use. A security review agent, for example, can be read-only (no code changes) and set to use a stronger-reasoning model.

The core value of subagents is not "specialised division of labour" — it is independent context. Each subagent runs in its own context window without consuming the main session's space. When the main session is long and near its context limit, delegating a subtask opens a fresh "thinking space" without squeezing the main session.

You can add "use subagents" to your prompt and let Claude decide when to delegate. This makes Claude invest more compute into complex tasks.

A practical combo: security-reviewer (auto-invoked whenever authentication, permissions, or data storage are involved) + verify-app (auto-starts the app and checks functionality after changes). Together they cover "is it written correctly?" and "does it actually run?"

Topic 3 — Agent Teams: let them coordinate themselves

Worktrees = you manually manage parallel sessions. Subagents = the main session calls a specialist. Agent Teams go further: multiple sessions communicate with each other and divide the work themselves. Shipped February 2026, it is currently Claude Code's most powerful collaboration mode. The core idea: instead of you coordinating agents, the agents coordinate themselves. (The book's earlier test — 3 AI teammates building a retro arcade game in 45 minutes — used this.)

Pattern 1 — Writer / Reviewer

1
Writer Agent writes code — implements features, writes code, runs tests per requirements.
2
Reviewer Agent reviews — reads the Writer's output, finds issues, suggests improvements.
3
Writer revises based on feedback — an iterative loop.

Why it works: same reason as human teams. The writer gets locked into their own thinking; the reviewer catches problems from a different angle. Two agents checking each other visibly raises quality.

Pattern 2 — Test-Driven (TDD, AI edition)

One agent writes the tests first, defining "what correct behaviour looks like" from the requirements. The implementation agent then satisfies those tests. Agent Teams automatically share task state and messages — no manual copying between agents — and there is a team lead role that coordinates assignment and progress.

Coordinator Mode — four-phase coordination

Research (workers investigate in parallel) Synthesis (coordinator writes a spec) Implementation (targeted changes to spec) Verification (results checked)

You do not configure this — Agent Teams automatically decides whether to run the full four-phase process based on task complexity.

Topic 4 — Fan-out Batch Processing: AI-scale parallelism

Everything above is a few agents on one task. Fan-out solves a different problem: the same operation across many files.

Non-interactive mode

# Execute a single task in non-interactive mode
claude -p "Migrate this file from JavaScript to TypeScript"

The -p flag passes a prompt directly, so Claude Code is easy to call from scripts. Combine with a shell loop:

# Batch migrate a set of files
for file in $(cat files-to-migrate.txt); do
  claude -p "Migrate $file from JS to TS" \
    --allowedTools "Edit,Bash(git commit *)" &
done

Explaining the code

  • for file in $(cat files-to-migrate.txt) — loop over every filename listed in the text file.
  • claude -p "Migrate $file from JS to TS" — run one non-interactive Claude task per file.
  • --allowedTools "Edit,Bash(git commit *)" — pre-authorise only editing and git commits, so it runs unattended.
  • The trailing & — run each instance in the background in parallel. 50 files → 50 Claude instances at once; a day's work can finish in minutes.

The /batch command (no scripting needed)

1
Interactive planning — tell Claude the goal ("migrate all React class components to function components"); it analyses the project and lists every file to touch.
2
Confirm and execute — you review the plan; once confirmed, Claude launches dozens of agents in parallel.
3
Aggregate results — Claude summarises successes and failures; you only handle the handful that did not go through.

Best suited for large-scale refactors, code migrations, and bulk fixes. One person with Claude can match what an engineering team spends a week doing on a migration.

Topic 5 — You Don't Have to Watch the Screen (async work)

FeatureWhat it doesGood for
Remote ControlGenerate a connection link; open it on your phone to create and manage local Claude sessionsStarting a task on your commute or before heading out. Boris starts sessions on his iPhone in the morning, continues on desktop.
Claude Code on WebRun Claude Code at claude.ai/code with nothing installed locallyCloud dev environments, browser-only work
/scheduleA Claude task that triggers on a schedule and runs in the cloud, even when your computer is offDependency updates, security scans, daily reports
/loopClaude runs unattended locally for up to 3 daysMonitoring CI status, continuous integration tests
# Set up a cloud-based scheduled task
/schedule "Check for outdated dependencies and create PRs"
The mindset shift for async work: traditional development is synchronous — write code, run tests, wait. In async mode you kick off a batch before bed and review results in the morning. Think of AI as a "night shift team": you set direction and make decisions during the day; it executes overnight.

Real-World Use Cases: How Anthropic Uses It Internally

From Anthropic's white paper "How Anthropic Teams Use Claude Code":

TeamHow they use Claude Code
Data infrastructureDebugging Kubernetes clusters — Claude reads pod logs, analyses the error stack, identifies the root cause, and suggests fixes. Hours of a senior engineer's time → minutes to the right direction.
SecurityTracing complex control flows — tracking a request's full path from entry point to database, auto-generating call flow diagrams.
MarketingBatch-generating dozens of ad copy and asset combinations; marketing only handles selection and fine-tuning.
LegalA lawyer — not an engineer, could not write code — built and shipped a phone tree system (routing incoming calls to the right counsel) from scratch.

The legal example is highlighted as a sign that Claude Code's audience has already expanded well beyond engineers.

Visual Mental Model: Four Ways to Go Parallel

PARALLEL SESSIONS      one task each, isolated worktrees/branches
   [feature] [bugs] [tests] [refactor] [review]   <- you coordinate

SUBAGENT               one specialist step, own context
   main session ──► [security-reviewer] ──► result back

AGENT TEAM             they coordinate themselves
   [team lead] ⇄ [writer] ⇄ [reviewer]   (shared task state)

FAN-OUT               same op x many files, in parallel
   /batch ──► [f1][f2][f3]...[f50] ──► summary of pass/fail

Important Comparisons

Parallel sessionsSubagentsAgent Teams
Relationship between tasksIndependentOne step inside your taskCollaborating on one task
Who coordinatesYouMain sessionThe agents themselves (team lead)
ContextSeparate per sessionSeparate per subagent (frees main context)Shared task state + messages
IsolationGit worktrees / branchesWithin the sessionManaged by the team
/schedule/loop
RunsIn the cloudLocally
TriggerOn a schedule (cron-like)Unattended, continuous, up to 3 days
Works when your computer is off?YesNo
Good forRoutine maintenanceLong-running monitoring

Common Beginner Mistakes

  • Opening 10 sessions on day one. Start with 2.
  • Letting every session do "whatever comes up" instead of a clear role.
  • Multiple sessions on the same branch — the author calls resolving those conflicts "a genuine nightmare."
  • Treating parallel as hands-off. Parallel does not mean no oversight.
  • Assuming more agents is always better — ignoring the 6× token cost and the merge/consistency pass.
  • Splitting a task that is not actually independent, making the merge expensive.
  • Using a new window when a subagent (specialist step, own context) is the right tool.

Best Practices (the author's lessons)

  • Start with just 2 sessions — one main task, one support (tests, review). Add more once switching feels natural.
  • Give each session a clear role — frontend / backend / tests only. Clear roles are easier to manage.
  • Use git branches to isolate everything — each session on its own branch, merged via PR. Never share a branch.
  • Check in every 15–20 minutes and course-correct early. Stopping a derailed session is far cheaper than redoing finished work.
  • Ask first: can this task be split into independent pieces, and how expensive is the merge?
  • Manage it like a remote team — know what everyone is working on, how far along, and whether anyone is stuck. Your job shifts from writing code to project management.

Interview / Revision Questions

  1. Why does running multiple sessions cut your wait time to nearly zero?
  2. What are the two real costs of running many agents in parallel?
  3. What problem do Git Worktrees solve, and what does claude --worktree do?
  4. What is the single most important feature of subagents — and why is it not "division of labour"?
  5. Describe the Writer/Reviewer pattern and why it beats a single agent.
  6. What is the Test-Driven pattern in Agent Teams?
  7. Name the four phases of Coordinator Mode.
  8. What does the trailing & do in the batch-migration shell loop?
  9. What are the three steps of the /batch command?
  10. Compare /schedule and /loop.
  11. What is the "night shift team" mindset?
  12. List three of the author's practical rules for managing parallel sessions.

Practice Exercises

Exercise 1: Open two Claude sessions in separate worktrees — one implementing a small feature, one writing its tests. Switch between them while each works.
Exercise 2: Write a .claude/agents/security-reviewer.md with read-only tools, and invoke it on some auth code.
Exercise 3: Try the Writer/Reviewer pattern on one feature and compare the result with a single-agent version.
Exercise 4: Use /batch to plan (not necessarily execute) a repetitive change across your codebase and read the file list it produces.
Exercise 5: Set a /schedule task to check for outdated dependencies weekly.
Exercise 6: For a real task, write one sentence answering: is this independently splittable, and how costly is the merge?

Quick Memory Map

Multi-Agent Collaboration
│
├── Why: Claude work = task -> wait -> review -> next
│        many sessions => wait time ~ 0
│   Cost: ~6x tokens + a consistency/merge pass
│
├── Parallel sessions
│   ├── claude --worktree  (isolated dir + branch)
│   ├── --tmux + shell aliases (za/zb/zc)
│   └── one branch per session, merge via PR
│
├── Subagents  (.claude/agents/*.md)
│   ├── specialist step inside current task
│   └── KEY: independent context (frees main session)
│   └── combo: security-reviewer + verify-app
│
├── Agent Teams  (Feb 2026, self-coordinating)
│   ├── Writer / Reviewer loop
│   ├── Test-Driven (AI TDD)
│   ├── team lead role, shared state
│   └── Coordinator: Research -> Synthesis -> Impl -> Verify
│
├── Fan-out / batch
│   ├── claude -p "..."  (non-interactive)
│   ├── for ... claude -p ... &   (parallel)
│   └── /batch: plan -> confirm -> aggregate
│
└── Async
    ├── Remote Control (phone), Claude Code on Web
    ├── /schedule  (cloud cron, PC off OK)
    └── /loop      (local, up to 3 days)
    Mindset: AI = night shift team

Complete Chapter Revision

  1. The underrated capability is parallelism: one person commanding an AI team.
  2. Many sessions remove wait time, but cost ~6× tokens and need a consistency/merge pass.
  3. Git Worktrees give each session an isolated filesystem and branch; claude --worktree automates it.
  4. Subagents (.claude/agents/*.md) handle a specialist step; their key value is independent context.
  5. Agent Teams self-coordinate: Writer/Reviewer, Test-Driven, a team lead, and an automatic four-phase Coordinator Mode.
  6. Fan-out runs the same operation across many files: claude -p in a backgrounded loop, or the /batch command (plan → confirm → aggregate).
  7. Async: Remote Control, Claude Code on Web, /schedule (cloud), /loop (local, up to 3 days) — treat AI as a night-shift team.
  8. Anthropic teams use it for Kubernetes debugging, security control-flow tracing, ad-variation generation, and even a lawyer's phone-tree system.
  9. Practical rules: start with 2 sessions, give each a clear role, one branch per session, check in every 15–20 minutes.
  10. Your job shifts from writing code to project management.

Final Takeaway

The chapter's central lesson:

Think of parallel work like managing a remote team. You do not need to watch every person write every line, but you do need to know what everyone is working on, how far along they are, and whether anyone is stuck. The skill to build is not typing faster — it is splitting work well, isolating it cleanly, and coordinating it lightly.

This teaching edition is based on the supplied April 2026, 2nd edition of Claude Code: The Complete Guide (§08, "Multi-Agent Collaboration"). Flags, command names, feature availability (e.g. Agent Teams, February 2026) and cost figures reflect that edition and may change over time.