Running Claude Code agents in parallel feels like multiplying your output. It works until their branches have to become one codebase. That is where the speed is won or lost. Writing the patches was never the hard part. The hard part is deciding whose version of a shared type, route or default becomes the real one.

Parallelism fails at the integration boundary

Three agents can each write a sensible patch and still leave you with one broken branch. Git worktrees give every Claude Code agent its own folder and branch, so their edits, tests and experiments do not overwrite each other. But worktrees do not decide which change wins.

So plan around the merge surface: the files, interfaces, schemas, settings and behaviour a task can change. Parallel work is safe when these surfaces do not overlap or the links between them are written down. It gets expensive as soon as two agents each reinterpret a shared type, fixture, route or validation rule.

Agents can work in parallel, but merging must happen one step at a time, in dependency order. Most of this article is about doing that on purpose. Access settings are a separate topic. If you need to design permission boundaries, see the guide to Claude Code MCP scopes at local, project, and user levels.

A worktree isolates edits and leaves decisions shared

A Git worktree is a second checkout of the same repository. It has its own branch and files but shares Git's object storage. With parallel Claude Code agents, it stops one agent from reformatting a file while another is halfway through a feature in the same checkout.

The pattern has four parts:

  1. A coordinator decomposes work into tasks with narrow change surfaces.
  2. Each agent uses a named branch in its own worktree.
  3. Agents record decisions affecting another task before dependent code is written.
  4. A human or designated integration owner merges in dependency order and runs a gate after each meaningful merge.

Teams usually skip step three. "Add account status to the API" hides several decisions: can it be empty, how is it validated, what do old clients see, what do test fixtures use? A settings-form agent can answer these differently without touching the same lines. Git reports no conflict, and the merged result is still wrong.

Treat every shared decision as an interface, even if it exists only as text. Write it in a file every agent reads before editing. Catching a disagreement there is far cheaper than finding it after the merge.

Choose parallelism by dependency shape

Not every task needs a worktree. The test is whether the work can merge on its own. How fast an agent can write the patch hardly matters.

Work model Suitable change shape Integration cost Failure mode
One shared branch A small, sequential fix Low at first Agents overwrite context or inherit unreviewed changes
Independent feature branches Separate components with stable contracts Moderate Hidden contract divergence reaches the merge stage
Governed worktrees Parallel tasks with declared ownership and ordered dependencies Planned and visible Coordination work is wasted if tasks were already independent

Managed worktrees are worth the effort when one task builds something another task uses: a data model, a public API contract, a feature flag, a shared UI component, a build setting or a migration. One decision there affects several branches at once. The split also shapes the code. Divide the agents along the wrong lines and the code grows seams in the same places, usually as duplicate types and adapter code.

Keep tightly linked work in one worktree. Splitting a 40-line refactor adds coordination and no speed. Split work only when agents can move forward on their own and the handoff between them fits a few clear rules.

There is a real limit here. Adding agents to a shared merge surface multiplies assumptions faster than useful output. The first warning sign is rarely a Git conflict. It is a scatter of "small" integration edits nobody owns: a renamed field, a changed default, an updated snapshot, a late tweak to error handling.

Trunk-based development would argue against all this. In "Accelerate" (2018), Forsgren, Humble and Kim report that high-performing teams keep few active branches and merge them into the main branch at least daily, because long-lived branches are where integration pain builds up. Three agent branches kept open for a week look like exactly what that research warns about. The key is how long branches live. Worktrees are cheap when each branch lives for hours and passes the gate the same day. They get expensive when they become a parking lot. A rule that fits both: if a task cannot reach the gate within one working day, split it again, or keep it in one worktree with one agent.

Silent contract drift causes the costly failures

Text conflicts are loud, and loud problems get fixed. The expensive failures merge cleanly: the branches touched different files but disagree about behaviour.

Take a team adding a status field to customer accounts. The contract agent defines active | suspended. The UI agent, starting from the same commit, shows any unknown value as active. The quality agent adds a pending fixture because the acceptance note made it sound useful. Every branch merges without a complaint. The bug appears later, when a suspended account is offered the wrong action, or when another service starts returning pending.

Four habits keep this from happening:

  • Give widely used files a single owner. One task owns src/domain/types.ts, a migration or a public schema until its branch merges. Everyone else proposes changes through the decisions file instead of editing it in parallel.
  • Write acceptance conditions as behaviour you can see. "Support status" is vague. "The API rejects unknown values; the UI shows a safe state for each allowed value; existing records get active" can be tested.
  • Separate exploring from final checking. A quality agent can study the baseline, find missing coverage and draft a test plan in parallel. But its final validation branch must start from the integrated candidate, because that is the product under review.
  • Do not auto-resolve with ours or theirs. Those pick lines, not intent. Work out which decision the conflict is about, and update the shared record if that decision changed.

Subagents make this worse when they wander outside their task: a dependency upgrade, a formatting pass, a test rewrite. Each extra change widens the merge surface and breaks a neighbour's assumptions. That is why the manifest must list both the allowed paths and the forbidden ones.

Build the companion repository before assigning agents

Use the layout below as a starting template. Then test it with one full integration run: three separate worktrees, clear task boundaries, a decision log, a merge order, a review checklist and a test gate you can run in CI or from the integration checkout.

Start from a clean main checkout and keep it reserved for integration.

git worktree add ../wt-contract -b agent/account-contract main
git worktree add ../wt-client -b agent/account-client main
git worktree add ../wt-quality -b agent/account-quality main

The layout is designed to make governance visible during review:

parallel-agent-demo/
├── docs/
│   ├── task-manifest.yml
│   ├── shared-decisions.md
│   ├── merge-order.md
│   └── review-checklist.md
├── scripts/
│   └── integration-gate.sh
├── src/
├── test/
├── package.json
└── README.md

Put task boundaries in a manifest

Write the manifest before you send a single prompt. You do not need a workflow engine; a readable file is enough.

release: account-status
base_ref: main
tasks:
  - id: contract
    branch: agent/account-contract
    worktree: ../wt-contract
    owner: contract-agent
    touch_paths:
      - src/domain/account.ts
      - src/api/account-schema.ts
    forbidden_paths:
      - src/client/
    produces:
      - AccountStatus enum
      - API validation rules
    depends_on: []
    verification:
      - npm test -- account-schema

  - id: client
    branch: agent/account-client
    worktree: ../wt-client
    owner: client-agent
    touch_paths:
      - src/client/account-status.tsx
      - test/client/account-status.test.tsx
    forbidden_paths:
      - src/domain/account.ts
    consumes:
      - AccountStatus enum
    depends_on:
      - contract
    verification:
      - npm test -- account-status

  - id: quality
    branch: agent/account-quality
    worktree: ../wt-quality
    owner: quality-agent
    touch_paths:
      - test/integration/account-status.test.ts
      - docs/review-checklist.md
    forbidden_paths:
      - src/
    depends_on:
      - contract
      - client
    verification:
      - npm test -- account-status

depends_on does not block the client agent from working. It only stops its branch from being approved as final before the contract lands. The client can build its layout, tests and call sites from the decision record. If the contract changes in review, it rebases and rechecks its diff.

Record decisions where every worktree can see them

A shared-decisions file lets people review the assumptions. Keep entries short, dated and linked to a task, so a reviewer can read the whole file in a minute.

# Shared decisions

## D-01 Account status contract
- Owner: contract-agent
- Consumers: client-agent, quality-agent
- Allowed values: `active` and `suspended`
- Default for existing accounts: `active`
- Unknown values: API validation rejects them; the client must not coerce them
- Change rule: update this entry before changing the public contract

Without the change rule at the bottom, agents treat the file as documentation that can fall behind the code. With it, a contract change becomes a clear integration event. A reviewer can then ask the key question: did every consumer recheck its branch after D-01 changed?

Make merge order a committed plan

A merge plan needs more than a list of branches. Say why a branch goes first, what must happen before the next one merges, and who can stop the sequence.

# Merge order

1. Merge `agent/account-contract` into an integration candidate.
   - Review D-01 and run the contract test.
2. Rebase `agent/account-client` onto that candidate.
   - Confirm the client uses the merged enum and rejects no new states.
   - Merge only after targeted client tests pass.
3. Rebase `agent/account-quality` onto the two merged changes.
   - Run the full integration gate.
4. Fast-forward or merge the verified candidate into `main`.

Integration owner: release engineer
Stop condition: any changed public contract, failing gate, or unowned file change.

Each place in that order has a reason. The contract goes first because many things depend on it. The client goes next because it uses the contract. Quality goes last because it can only judge behaviour once the pieces are together.

Give the merge candidate an executable gate

Save this as scripts/integration-gate.sh, run chmod +x scripts/integration-gate.sh, and adapt the two package commands to your project. Run it from a clean integration checkout after each dependency boundary.

#!/usr/bin/env bash
set -euo pipefail

BASE_REF="${1:-main}"

git rev-parse --verify "$BASE_REF" >/dev/null
test -z "$(git status --porcelain)" || {
  echo "Refusing to test a dirty integration checkout"
  exit 1
}

test -f docs/task-manifest.yml
test -f docs/shared-decisions.md
test -f docs/merge-order.md
test -f docs/review-checklist.md
grep -q "tasks:" docs/task-manifest.yml
git diff --check "$BASE_REF...HEAD"

npm run lint
npm test

echo "Integration gate passed against $BASE_REF"

The script cannot vouch for the product. It does catch a dirty checkout, a missing planning file, whitespace damage, a lint failure or a failing test. Because it runs the same way every time, an integration owner can reject a merge for a named reason, not on a vague feeling that it all came together too fast.

Review gates turn merge order into a control point

Without a review gate, merge order is just a to-do list. The gate is where you check that a branch still matches its task after all the rebases, conflict fixes and agent revisions.

Commit this as docs/review-checklist.md, and require reviewers to record any exception in the pull request or the release note.

# Review checklist

- [ ] The branch matches one manifest task and its allowed paths.
- [ ] The branch is rebased on the planned integration base.
- [ ] Public types, routes, migrations, and defaults match shared decisions.
- [ ] New or changed assumptions have a decision entry.
- [ ] Conflict resolution did not introduce unrelated edits.
- [ ] Targeted tests cover the declared acceptance conditions.
- [ ] The full integration gate passes in a clean checkout.
- [ ] The next branch has been told which commit and decisions it consumes.

Look at two diffs. The diff against the branch's original base shows what the agent meant to do. The diff against the current integration candidate shows what rebasing changed. The second view catches a branch that was correct three commits ago but became misleading after a contract or migration changed underneath it.

But do not ask for human review of every tiny internal commit. Review where it matters: where another agent uses a decision, where a widely used file changes, and before release. That keeps control tight without turning the worktrees into a queue.

Measure what integration costs

Raw agent output is a vanity number. It says nothing about whether the code can safely go into main. Measure what coordination costs instead.

Measure Formula or definition Diagnostic use
Integration lead time Gate start timestamp to verified merge timestamp Shows whether merge governance has become a release bottleneck
Rebase rework Files changed only during rebase or conflict resolution Reveals tasks split across the same merge surface
Gate pass rate Passed gate runs / total gate runs × 100 Distinguishes unstable integration from isolated test failures
Decision drift Decision entries changed after a consumer branch started Signals downstream work needs explicit revalidation
Unowned diff count Changed files absent from a task's allowed paths Detects agent scope creep early

Do not set targets before you have watched a few releases. A high gate pass rate can mean healthy work, or a gate too weak to catch anything. Read it together with review notes and the types of failing tests. Each time, ask whether a failure shows a missing task boundary, a missing decision or a gap in the tests.

Little's law (Little, 1961) explains why lead time matters. The average time an item spends in a system equals the work in progress divided by throughput. Say the integration owner can review and gate about four branches a day. If agents keep 12 branches waiting, each one waits about three days, however fast it was written. Double the agents to 24 open branches and the wait doubles to six days, with nothing shipped sooner. The gate is the bottleneck. So add review capacity or cut open branches before you add agents.

A first governed three-worktree run

Try the layout on one change that crosses a real boundary, for example one that touches an API contract, a client flow and integration tests. Use exactly three worktrees. Write the manifest and D-01 before you send any prompt. Merge the foundation first, rebase each consumer onto it, and run the gate from a clean checkout.

Besides the merged change, that run shows where the plan leaked. Look at unplanned edits and late decisions. A file that keeps showing up in unowned diffs needs a single owner. Decisions that keep changing after consumer branches have started mean the decision record came too late: it was written with the first prompt when it should have existed before it. The second run is usually tighter than the first, because its task split is based on what the first run showed.