CCDV-P Study Guide
8. Domain 8: Agent Fleet Operations for Software Delivery
8.1. 8.1 Parallel agent orchestration: fan-out, worktrees, merging and fleet failures
CCDV-P · Domain 8 · Lesson 8.1 · 21 min read
When parallel coding agents speed up a large change: decomposition by file ownership, one worktree per agent, a single integrator, and fleet telemetry.
Why twenty agents can finish later than one
Twenty painters can repaint a twenty-room office in a day, one per room. Put the same twenty painters in one kitchen and you get wet paint on every elbow, three coats on one wall and none on another, and a foreman who spends the afternoon sorting out who did what. The crew is the same. The difference is whether the work splits into rooms.
Lumen Retail Systems runs 140 services for its stores and online shop, all in one repository, each under services/<name>/. Every one of them logs through logkit, an in-house library that loses support in March. Ilse Rafferty, a staff platform engineer, owns the migration to the new lumen-telemetry logger. Done by hand, it is a quarter of engineering time. Done by 20 Claude Code agents running at once, it should take a week.
The first attempt, launched by a colleague on a Monday, did not. By evening there were 20 branches. Seventeen conflicted on the same lockfile, platform/deps.lock. Three agents had each rewritten the shared HTTP middleware, libs/lumen-http, in three incompatible ways. One branch had also upgraded the HTTP client, which nobody asked for. Every branch was red on the same checkout test, and one agent had spent five hours trying to fix it. The day's spend was three times the estimate.
None of that was a model problem. Each agent did sensible work on its own piece; the fleet failed as a fleet. Parallel agent orchestration is the discipline that prevents this. You split the work into units that do not touch each other and give each agent an isolated copy of the code. Then you merge the results through one integrator in a fixed order, and watch fleet-level telemetry for the failures no single agent can see.
When fan-out pays and when it costs
Here is the question every fleet decision starts from: if one agent can do this task, will twenty do it twenty times faster? Only when the task is made of independent units: pieces that change different files, can be tested on their own, and do not depend on each other's results. A logging migration across 140 services is close to that shape. Each service's call sites live in its own directory and its own tests check them.
Fan-out hurts in two shapes. The first is a shared component every unit depends on. Lumen's libs/lumen-http logs through logkit too, and 90 services import it. Give that job to every agent that meets it and you get the Monday result: several agents, several rewrites, all conflicting. The second is one coupled whole. Anthropic hit this when 16 parallel agents built a C compiler. While the test suite had many distinct failures, each agent took a different one. Once the goal became compiling the Linux kernel, one giant task, every agent hit the same bug and overwrote the others' fixes.
Where fan-out pays and where it costs
Independent units
Shared or coupled work
| Task shape | Fan out? | Why |
|---|---|---|
| Many independent units, each with its own tests | Yes, after a pilot on a few units | Failures stay inside one unit, so agents never wait for each other |
| A shared component the units depend on | Not yet: one agent does it first, then the units fan out | Every agent would change it in its own way |
| One coupled whole, such as a build that fails for one reason | No, until a reference or split makes it independent | Every agent finds the same bug; the compiler project fixed this by building most files with GCC as a known-good reference, so each agent chased bugs in different files |
Anthropic's migration guidance adds the step teams skip: run a small pilot first. Ilse migrates five services with the plan she intends to scale and reads every diff. The goal is not those five services but the plan itself: the prompt, the unit boundaries and the done test, fixed while a mistake costs five branches instead of 140.
Decompose by ownership, not by count
The Monday plan divided the work by count: 140 services, 20 agents, seven services each. Nothing said who owned the files that several services share. Here is the failure that makes ownership necessary: two agents with no rule about a shared file will both edit it, each correctly for its own service, and the second edit conflicts with the first.
Decomposition by ownership assigns every file that will change to exactly one owner before any agent starts. A unit owns its paths; nothing else may edit them. Files that many units touch get a single owner of their own. Some go to an earlier wave, a round of units that must land before the next round starts: Lumen's wave 0 is libs/lumen-http, migrated by one agent and merged before any service starts. Others belong only to the integrator: the lockfile is generated, so the integrator regenerates it once after merging instead of letting 20 agents each hand-edit it.
Ilse writes the plan as a manifest that her launcher reads. Look at owns, which bounds each unit, and integrator_only, which names the files no agent may touch. This is a plain file of her own design, not a Claude Code feature.
# logkit migration, wave 1 (excerpt)
wave: w1
starts_after: w0 merged to main # lumen-http already migrated
units:
- id: svc-orders
owns: [services/orders/] # the ONLY paths this agent may edit
done: "no logkit imports; make test passes in services/orders"
- id: svc-pricing
owns: [services/pricing/]
done: "no logkit imports; make test passes in services/pricing"
integrator_only: # no agent edits these
- platform/deps.lock # regenerated once, after merging
- config/logging-defaults.yaml
out_of_scope: "upgrading other dependencies; editing tests outside owned paths"
Each unit also carries a done test a script can check, not a judgment an agent can talk itself into. "No logkit imports and the service's tests pass" is mechanical; "migration looks complete" is not. The out_of_scope line names the drift Ilse expects, such as upgrading the HTTP client along the way.
One worktree per agent
Even with perfect ownership, agents cannot share one working directory. On Monday the first five sessions ran in the same checkout, and within an hour one agent's git stash had swept up another's half-finished edits. Parallel agents need parallel copies of the files.
A git worktree is a separate working directory with its own files and branch that shares the repository's history and remote. Claude Code supports it directly. claude --worktree svc-orders (or -w) creates a worktree under .claude/worktrees/svc-orders/ on a new branch, worktree-svc-orders, and starts the session there. A custom subagent gets the same with isolation: worktree in its frontmatter. The bundled /batch command packages the whole pattern. It researches the codebase, splits a change into 5 to 30 independent units and shows you the plan. After approval it runs one background subagent per unit, each in its own worktree, which tests its unit and opens a pull request or reports what happened.
One unit, one worktree, one branch
.claude/worktrees/svc-ordersworktree-svc-orders plus a JSON reportIlse needs 140 units in waves with her own caps, so her launcher runs one headless session per unit. Look at --worktree, which isolates the run, --max-turns and --max-budget-usd, which stop a runaway agent, and OTEL_RESOURCE_ATTRIBUTES, which labels the run's telemetry with its unit.
unit="svc-orders"
# Label this run's telemetry with its wave and unit
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp OTEL_LOGS_EXPORTER=otlp # endpoint set in settings
export OTEL_RESOURCE_ATTRIBUTES="fleet.wave=w1,fleet.unit=${unit}"
# Own worktree under .claude/worktrees/, hard caps on turns and estimated spend
claude -p "$(cat migrate-prompt.md) Unit: ${unit}. Owned paths: services/orders/" \
--worktree "${unit}" \
--allowedTools "Read,Edit,Write,Bash(make test *),Bash(git commit *)" \
--max-turns 60 --max-budget-usd 6 \
--output-format json > "runs/${unit}.json"
# runs/<unit>.json holds total_cost_usd and session_id for the fleet table
Know where the isolation ends. A worktree is a fresh checkout: dependencies must be installed inside it, and gitignored files such as .env are absent unless a .worktreeinclude file lists them. Worktrees share the repository's .git directory, the remote and anything outside the files: a local database, a fixed port, your rate limits. New worktrees branch from the remote default branch unless worktree.baseRef is set to "head", and Claude Code refetches that branch only when the last fetch is more than 24 hours old. So wave 1 starts only after wave 0 is merged, pushed and fetched. And headless runs are not cleaned up on exit and keep the lock Claude Code put on them, so the integrator runs git worktree unlock and then git worktree remove once a branch is merged.
Merge through one integrator
Twenty green branches do not make a green main. Here is the failure that catches teams: each branch passed its own tests against the commit it started from, and nobody tested the combination. Two branches that each work can break each other once merged, and the more branches you merge at once, the harder it is to say which pair did it.
The fix is a single integrator: one owner of the integration branch, either a person or one agent, through which every unit lands. Nobody else merges. The integrator applies three rules.
- ORDER. Merge in dependency order: wave 0 first, then the units that depend on it, then the rest. Within a wave, small and low-risk units go first, so an early failure has few suspects.
- REBASE AND RETEST. Before merging, rebase the unit onto the current integration tip and rerun its tests there, because the base it started from is out of date.
- FULL SUITE AFTER EACH MERGE. Run the whole suite on the integration branch after every merge, or after each small batch, so a break points at one unit or a handful.
How a unit reaches main
A conflict is a message about the plan. A conflict in a generated file is expected: the integrator regenerates platform/deps.lock instead of hand-merging it. A conflict in a file the manifest gave to one owner means some agent edited outside its paths, which is drift to fix at the cause, not to resolve by hand. When a unit no longer applies cleanly, the integrator sends it back to an agent on a fresh worktree from the current tip, rather than patching it.
Reading fleet telemetry
Every Monday failure was invisible from inside any single agent. Each agent that rewrote libs/lumen-http believed it was fixing a dependency. Each agent on the red checkout test saw a failure it should fix. You find these failures only by comparing runs across the fleet.
Ilse builds one fleet table, a row per unit, from four sources. The JSON report from each run gives total_cost_usd and session_id. Claude Code's OpenTelemetry export gives claude_code.cost.usage, claude_code.token.usage and claude_code.lines_of_code.count per unit, through the label she set, plus claude_code.tool_result events with a success field. Git gives the files each branch changed, and CI gives test results by name per branch. Both cost figures are estimates Claude Code computes on the client and can differ from the bill: good for spotting outliers, not for reconciling spend.
| Failure mode | What the fleet telemetry shows | Fix at the cause |
|---|---|---|
| Agents editing shared files | The same paths in many branch diffs; conflicts piled on two or three files | Make those files integrator-only; regenerate generated files once |
| Duplicated work | Several units changing the same library paths, with different diffs | Move the shared code to an earlier wave with one owner |
| Drift from the plan | A few units with many times the median lines changed, or files outside their owned paths | Enforce owned paths in code: a PreToolUse hook that refuses edits elsewhere, and a CI path check |
| Cost blowout | A long tail: a few units hold most of the spend and turns, with the same tool result failing again and again | Per-run turn and budget caps; a capped run stops and is escalated |
| A flaky test failing every branch | One test red on every branch, including branches that never touch its code, and intermittently on main | Fix or quarantine it once on main, then rerun the affected units |
The last row is the one that wastes the most money, because it looks like twenty separate failures. Read it the way the verdict diagram does: when the same test fails on branches that share nothing except their base, the cause is in the base.
Twenty red branches, one cause
Notice the pattern in the fix column: every fix works on the plan or the environment, and every enforced rule lives outside the model. A prompt line saying "only edit your own service" is still worth writing, but the hook and the path check are what make it hold across 140 runs. A budget cap stops a runaway run; a note asking the agent to be economical does not.
The exam traps
Every trap here treats a fleet as twenty copies of one agent instead of a system with shared parts.
- ✗ Adding agents to finish a coupled task faster. ✓ Fan out only independent units, after a pilot on a few. On a shared component or a single failing whole, extra agents repeat and overwrite each other's work.
- ✗ Running parallel agents in one checkout or on one branch. ✓ Give each agent its own worktree and branch. A shared working directory lets one agent's commands sweep up another's edits.
- ✗ Letting every agent fix the shared library it runs into. ✓ Give shared code one owner in an earlier wave, and make generated files integrator-only. Many owners means duplicated, conflicting work.
- ✗ Merging every green branch at once and testing at the end. ✓ Merge through one integrator in dependency order, rebasing, retesting and running the full suite after each merge. Branch-level green says nothing about the combination.
- ✗ Retrying agents, or switching to a bigger model, when every branch fails the same test. ✓ Compare across branches; a failure shared by unrelated branches lives in the base. Fix or quarantine the flaky test once on main.
- ✗ Controlling drift and spend with prompt instructions alone. ✓ Enforce owned paths with a hook and a CI check, and cap each run's turns and budget. Code holds across 140 runs; an instruction may not.
Put it together: run a three-agent migration and break it
You now have every piece: the independence test, a plan by ownership, worktrees for isolation, an integrator's merge order, and a fleet table that exposes what single agents cannot see. The fastest way to own them is to run a tiny fleet, then break the plan on purpose and watch the conflict appear.
The rest of this domain builds on the fleet you can now run. Verification and AI code review (8.2) deals with the review queue that 140 branches create. Unattended operations (8.3) run waves like these on a schedule or in response to events, with no one watching. Organisation-wide configuration (8.4) puts the hooks, permissions and telemetry settings Ilse used into managed settings for every team.
Key takeaways
- ✓ Parallel agents pay off only on independent units; shared components go first with one owner, coupled tasks are made independent before splitting, and a pilot tests the plan.
- ✓ Decompose by file ownership so every changing path has exactly one owner, with a mechanical done test and an explicit out-of-scope list for each unit.
- ✓ Isolate each agent in its own git worktree with
--worktree,isolation: worktreeor/batch, and manage what a worktree does not isolate: dependencies, ignored files, shared services, the base commit and cleanup. - ✓ One integrator merges in dependency order, rebases and retests each unit, runs the full suite after every merge, and regenerates generated files instead of hand-merging them.
- ✓ Fleet failures show only across runs, so label each run with its unit and compare files changed, lines changed, spend and test results across branches.
- ✓ Fix fleet failures at the plan or the shared environment, and enforce ownership and spend with hooks, CI checks and per-run caps, not prompts alone.
Practise this
Practice questions for CCDV-P are being written and are not in this course yet. Read this lesson on the web to answer its check questions, with every option explained: https://claude.termidy.com/learn/ccdv-p/agent-fleet-operations/parallel-agent-orchestration/.