All Days
Day 36

Agent Swarms — Coordinate Multiple Agents

Swarm vs Subagent vs Agent Team

Three orchestration patterns. Each with different tradeoffs in control, context sharing, and scale.

Subagent

1:1 delegation
  • Reports to 1 parent agent
  • Isolated context per task
  • Sequential or parallel execution
  • Parent controls scope and prompt
  • Best for: discrete, bounded tasks

Swarm

1:N fan-out
  • N workers spawned simultaneously
  • Orchestrator coordinates all
  • Fan-out pattern with result collection
  • Workers are independent, no peer comms
  • Best for: parallel bulk work

Agent Team

N:N collaboration
  • Full sessions per agent
  • Peer-to-peer communication
  • Shared or partitioned context
  • Experimental, harder to control
  • Best for: complex multi-step projects
Subagent
Parent
Child
Result
Swarm
Orchestrator
W1
W2
W3
W4
Merged
Agent Team
A
B
peer comms
C
D
Consensus

The 6 Swarm Patterns

Click each pattern to expand. Every pattern includes a flow visualization, example, and code you can use today.

Swarm in Motion

An orchestrator dispatches work to N agents. Each runs independently, returns results to the center.

The /batch Skill

Built-in swarm orchestration. One command decomposes, plans, spawns, and manages parallel agents for you.

/batch migrate all React class components to functional in src/
01

Decompose

Automatically scans the codebase and identifies all units of work (files, components, modules)

02

Plan

Presents the full plan for your approval: which files, what changes, estimated scope per unit

03

Spawn

One agent per unit, each in its own worktree. No conflicts, no merge issues, full isolation

04

Execute

All agents run in parallel. Each makes its changes, runs tests, validates output independently

05

Deliver

Each agent opens a PR. 20 PRs in parallel, clean diffs, ready for your review. You just approve.

# What /batch does under the hood:

# 1. Scan and decompose
files=$(find src/ -name "*.tsx" -exec grep -l "extends React.Component" {} \;)

# 2. Present plan (you approve)
# "Found 20 class components. Migrate each to functional + hooks."
# [approve / modify / cancel]

# 3. Spawn agents in isolated worktrees
for f in $files; do
  # Each agent gets its own git worktree
  git worktree add "/tmp/batch-$(basename $f)" -b "batch/migrate-$(basename $f)"

  claude --worktree "/tmp/batch-$(basename $f)" \
    "Convert $f from class component to functional.
    Replace lifecycle methods with hooks.
    Run tests. Open PR when done." &
done

wait
# Result: 20 PRs ready for review

Interactive Swarm Builder

Select your task, scale, and output format. Get an orchestrator prompt you can copy and run.

Generated Orchestrator Prompt
#!/bin/bash
# Swarm: Code Migration
# Scale: 5-10 agents | Output: json

MAX_PARALLEL=10
count=0

# Discover items
find src/ -name "*.{ext}" -type f

for item in $items; do
  claude "Migrate {file} from {from} to {to}.
Preserve all functionality. Run tests after migration.
Return: {status: "success"|"failed", changes: number, errors: []}" \
    --output "results/{name}.json" &

  count=$((count + 1))
  if [ $((count % MAX_PARALLEL)) -eq 0 ]; then
    wait
  fi
done

wait
echo "Swarm complete: $count items processed"

# Reduce phase: merge all results
claude "Read all results in results/ directory.
Merge into a single summary report.
Highlight: top issues, patterns, recommendations."

Real Use Cases

Patterns that have been deployed in production. Real numbers, real workflows.

Mass JS to TS Migration

200 JavaScript files converted to TypeScript with full type annotations. One agent per file, all running in parallel. Types inferred from usage patterns, imports rewritten, tests updated.

fan-out200 files20 min total

Competitive Analysis

One agent per competitor. Each researches pricing, features, positioning, reviews, tech stack. All results merged into a single comparison matrix with scoring and recommendations.

mapreduce8 competitorsmerged report

Multi-Language Translation

Marketing copy translated into 10 languages simultaneously. Each agent is prompted with language-specific cultural context and terminology. Native-quality output, not machine translation.

fan-out10 languagesparallel

Client Weekly Reports

One agent per client reads their project folder, communication log, and progress file. Generates a formatted weekly report with blockers, wins, and next actions. 12 reports at once.

fan-out12 clients12 reports

Cost Calculator

Compare swarm cost vs sequential. Swarms cost the same in tokens but save massive time.

20
Total Token Cost$1.25
Swarm Time (parallel)~5 min
Sequential Time~40 min
Time Saved35 min
swarm (parallel)
sequential (one by one)

Knowledge Check

5 questions. Test your understanding of agent swarm patterns.

Question 01 / 05
What is the key difference between a swarm and an agent team?
Question 02 / 05
In a MapReduce pattern, what does the "reduce" phase do?
Question 03 / 05
What bash operator runs processes in parallel?
Question 04 / 05
What does /batch do automatically that you would have to do manually?
Question 05 / 05
Which swarm pattern is best for a hard bug you cannot reproduce?

don't miss what's next.

playbooks, templates, and tools that actually save you hours. straight to your inbox. no spam. unsubscribe anytime.

Day 36 of 30 · AY Automate · Claude Code Series