iCode Workbench · Guide · Parallel work

How to run multiple coding agents in parallel without merge chaos

Two agents, one repository, one checkout. One edits src/api/auth.ts while the other rewrites the same file from a stale read. Both report success. The merge undoes half of each change. The fix is operational: isolate the checkouts, scope the tasks, queue the fleet, review the diff, and merge one branch at a time.

New to the category? Start with what is an agent development environment?

This guide is currently available in English only.

What parallel coding agents are

Parallel coding agents means running two or more CLI coding agents at the same time on independent tasks. Each agent gets its own session, its own context, and — if the setup is correct — its own Git worktree. The unit of work is a task, not an agent. You do not “run five agents”; you run five tasks and assign an agent to each.

This is different from subagents inside one agent. Claude Code's agent teams and Codex's subagents split work inside a parent session; they share the parent's orchestration and often the same checkout. Parallel agents are separate sessions that can use different harnesses, different models, and different subscriptions. The isolation boundary is the worktree. For a concrete setup, read how to run Claude Code in parallel.

It is also different from a queue. Parallelism is concurrency: how many tasks run at once. A queue is work management: what is queued, what is running, what needs a person, what failed. You need both. Concurrency without a queue is a pile of terminals; a queue without concurrency is a to-do list.

The reason to run agents in parallel is wall-clock time on independent work. The reason it fails is almost never the model. It is collisions, merge order, unreviewed output, or a session that died with the work inside it. The rest of this guide is about those four failures.

The four failure modes

Most “parallel agents” attempts fail in one of four ways. Name them before you add a second agent.

  1. File collisions. Two agents edit the same file in the same checkout. One overwrites the other, or both report success and the second write wins. A worktree per task fixes this.
  2. Merge conflicts. Worktrees prevent overwrites, not conflicts. Two branches can change the same shared file — a route table, a manifest, an export list — and the merge fails or silently drops one side. Scoping and merge order fix most of it.
  3. Unreviewed output. The agent exits zero, the task turns green, and the diff reaches main without a person reading it. A green run proves the process exited; it does not prove the change is correct. The review gate fixes this.
  4. Lost sessions. The terminal dies, the app restarts, or the laptop sleeps, and the agent's work disappears with the process. A detached host and durable task state fix this.

Each failure has a different fix, and they compose in order: isolate the checkout, scope the task, queue the work, review the diff, merge in order. If you only fix one, the others will find you.

What worktrees isolate — and what they don't

A Git worktree is a separate working directory with its own branch, sharing the repository's history and object store. It is the standard way to run two agents in one repository without them overwriting each other's files.

IsolatedStill shared or missing
Files and working treePorts
Branch and checkoutLocal databases and caches
Uncommitted changesGitignored files (.env, node_modules)
Terminal working directoryCredentials and network access
Git hooks, stash, config

The right column is where most “parallel agents” attempts fail. For the mechanics, read Git worktrees for coding agents, explained, and for the comparison, read worktrees vs branches vs clones.

  • Ports. Two npm run dev processes both want 3000. Assign a fixed port per worktree, and make the dev server fail rather than silently pick another.
  • Databases. Migrations and seeds from one agent can corrupt another's test data. Use a separate database or schema per worktree.
  • Gitignored files. A fresh checkout does not contain .env. Copy it with a setup script, or use Claude Code's .worktreeinclude if you use --worktree.
  • Credentials and network. A worktree is not a sandbox. Agents still share your machine, your SSH keys, and your network. Use containers when you need process isolation or you are running untrusted code.
  • Git hooks, stash, and config. These are repository-level, not worktree-level. Do not stash in one worktree and expect another not to see it.

Anthropic's worktree documentation covers the mechanics in detail; Promptise's parallel-agents guide catalogs the shared-state failures with examples. Both are worth reading before you run more than two agents.

Is the work actually parallelizable?

Parallelism multiplies review load. Before creating a worktree, run this checklist:

  1. Do the tasks touch disjoint files? If two tasks edit the same file, they are one task until the shared change lands.
  2. Is there a shared contract that must land first? API schema, route table, shared types, migrations. Update the contract on main, then branch.
  3. Are the tests fast and trustworthy? If the suite is slow or flaky, a bad merge will not be caught, and every agent will look successful.
  4. Is there review capacity for every branch? A fleet of five agents can produce five diffs. If one person reviews them all, the bottleneck moved, it did not disappear.
  5. Can each task finish in a bounded session? A task that needs 40 files of context is not a good parallel unit.

If any answer is no, fix that before adding agents. The goal is not maximum concurrency; it is reviewed, mergeable work.

Parallel agents are a poor fit for broad migrations, overlapping interfaces, and work where one person must review every line. They are also a poor fit when the test suite is flaky: a green run becomes noise, and the review gate cannot rely on it. Start with two independent tasks, not five intertwined ones.

Set up one worktree per task

Start with Git directly if you are using any agent that works in a directory:

git worktree add ../project-auth -b feature-auth
git worktree add ../project-billing -b feature-billing
git worktree list

Each task gets one branch and one directory. Name both after the task, not the agent.

Then initialize the worktree:

cd ../project-auth
pnpm install
cp ../project/.env .env.local

For Claude Code, claude --worktree feature-auth creates the worktree and starts the session in one step. .worktreeinclude copies gitignored files into every new worktree. Codex has worktree support as well; git worktree add works with any directory-based agent.

Three setup details matter more than the command:

  • Dependencies. Each worktree needs its own install. Do not symlink node_modules unless you know the toolchain tolerates it.
  • Runtime resources. Assign a port and a database per worktree. Write them down.
  • Ignore the worktree directory. Add .claude/worktrees/ or your chosen parent directory to .gitignore so the main checkout does not see it as untracked.

Scope tasks so agents don't collide

A worktree prevents file overwrites. It does not prevent two agents from editing the same shared file on different branches and creating a semantic conflict. Give every task a scope:

## Task
Extract the report formatter from src/report/builder.ts into its own module.

## Owned paths
- src/report/**
- tests/report/**

## Shared files
- src/index.ts — coordinate; do not edit without announcing

## Done when
- pnpm test -- report passes
- The new module is imported by builder.ts and no callers break

## Out of scope
- Renaming public types
- Changing the report output format

The owned paths are a boundary, not a guarantee. Agents drift. Check the diff after the task and look specifically at shared registration files:

  • dependency manifests and lockfiles;
  • route tables and export lists;
  • migration directories;
  • shared types and API schemas;
  • test fixtures used by more than one task.

If two tasks must change the same shared file, merge that change first, then rebase both worktrees. Do not let two agents “coordinate” through commit messages.

Run the fleet

Once the worktrees exist, manage the work as a queue rather than a pile of terminals. A useful task queue gives you:

  • A bounded concurrency limit. Workbench uses a global 1–4 slot limit. Start at two; add slots only when review keeps up.
  • Explicit states. Queued, dispatching, running, waiting, completed, failed, cancelled. “Running” is not the same as “reviewed.”
  • Retries as new attempts. A retry does not erase the failed attempt, and it does not count as a review.
  • Review as a separate decision. Process exit is not approval. A task can complete and still be rejected.
  • Sessions that outlive the window. A detached host owns the terminal process, so closing the app does not kill a running agent. Sleep a session to stop the process and keep the checkout, then wake it to resume where the harness supports it.

iCode Workbench is built around this model: 44 CLI agents, each session in its own worktree, a cross-project task queue, and a sidebar that shows every session's state. 21 harnesses have managed status hooks; the rest stay unknown rather than guessing. That distinction matters when you are scanning a fleet — a false “running” is worse than “unknown.”

Per-agent setup: Claude Code, Codex, OpenCode, Cursor CLI, Gemini CLI, and GitHub Copilot.

For the state model, read agent task states, retries, and schedules. For sizing, read how many coding agents to run in parallel.

The queue also changes how you think about context. Each task gets a bounded session and its own checkout, so the agent does not carry unrelated branch state or another task's tool output. For the per-session view, see managing context in long coding-agent sessions.

Recurring work belongs in the same queue. A schedule creates an ordinary queued task on a cadence — once, daily, weekdays, weekly, or every few hours — with queue-or-skip overlap handling. That keeps a nightly audit from becoming a separate automation with its own failure modes. In Workbench, Mira reads the real queue and surfaces review-ready work, approvals, and failures; she has no shell and cannot approve, merge, push, or edit code. The judgment stays with you.

For the task model behind that queue, read durable tasks, not terminal tabs, and for the practical setup, read how to queue coding agent tasks.

Review where the agent worked

Review is the gate that makes parallelism safe. Do it in the checkout the agent used, against the baseline the task started from. A sequence that works:

  1. Read the task and the diff first. Not the agent's summary. The summary tells you what it intended; the diff tells you what it did.
  2. Check the owned paths, then the files it touched anyway. Drift is the norm, not the exception.
  3. Run the verification command yourself. A passing test in the agent's shell is evidence; a passing test in yours is proof.
  4. Leave line notes for anything that needs another pass. A note attached to the line is easier to act on than a paragraph in chat.
  5. Stage, commit, amend, or reject. Keep the review decision separate from process exit, and do not let a green task auto-merge.

Workbench puts Files, Search, and Source Control in the same checkout, with the diff against the session baseline, line notes, and commit/amend/push actions. The point is not that the UI reviews for you. The point is that the review happens where the work happened, before the branch disappears into main.

If you run different harnesses, review them the same way. The harness changes how the agent edits; it does not change what a mergeable diff looks like.

A common failure is a diff that looks clean in isolation. The task passes, the owned files are correct, and the agent has also changed a shared export that another branch changes. Review the files outside the owned paths before you approve, and test the combined result after each merge.

For the checklist itself, read the review gate, and for the workflow, read how to review AI-generated code. For a printable checklist, use the agent diff review checklist.

Merge one branch at a time

Parallel branches are not independent at merge time. Merge serially. For the conflict-prevention workflow, read parallel agents without merge conflicts.

git checkout main
git pull
git checkout feature-auth
git rebase main
pnpm test
git checkout main
git merge --ff-only feature-auth

Then repeat for the next branch. After each merge, run the tests on the combined result. Two branches can each pass alone and fail together.

Lockfiles deserve their own rule: do not hand-merge pnpm-lock.yaml, package-lock.json, or uv.lock. Restore the target branch's lockfile, re-run the package manager's add command, and commit the regenerated file.

Keep the branch until the change is verified in main. Then remove the worktree:

git worktree remove ../project-auth
git worktree prune

If the work is not merged, keep the checkout and the branch. Removing a worktree deletes uncommitted changes.

A worked example: five tasks, one fleet

Imagine a repository with five independent tasks: an auth fix, a billing refactor, a flaky checkout test, a database migration, and a docs update. The work is parallelizable, but only if the shared contracts land first.

TaskOwned pathsDone when
Auth fix src/auth/**, tests/auth/** Auth tests pass; token refresh is covered
Billing refactor src/billing/**, tests/billing/** Billing tests pass; public types unchanged
Flaky checkout test tests/e2e/checkout.spec.ts The test fails before the fix and passes after 20 runs
Migration db/migrations/**, src/db/** Migration runs forward and back on a copy
Docs update docs/** The new auth flow is documented
  1. Land the shared contract first. If auth and billing both need a new session type, merge that type to main before branching. Shared schema changes are not parallel work.
  2. Create one worktree and one branch per task. Name both after the task, not the agent. Copy the env file and assign a port and database per checkout.
  3. Queue the tasks with a slot limit of two. The limit is review capacity, not machine capacity. Two running tasks and three queued is a healthy fleet; five running and zero reviewed is not.
  4. Review each diff in its own checkout. Reject the flaky-test fix if it only skips the test. Reject the migration if it locks the table. A task can complete and still be rejected.
  5. Merge in dependency order. Migration first, then auth, then billing, then the test fix, then docs. Rebase each branch on main, run the tests, and merge one at a time.

The order is the point. If the migration lands last, every branch above it is rebased onto a schema that changed underneath it. If the auth contract lands after the billing branch, the billing branch invents its own session type and the merge becomes a design debate.

This is also where a queue earns its keep: the migration and the auth fix can run in parallel, but the docs update should wait until the auth flow is settled. A queue lets you express that dependency without holding five terminals in your head.

Checklist before you add another agent

  1. Are the tasks independent? If two tasks touch the same file, they are one task until the shared change lands.
  2. Is the shared contract already on main? Schema, types, route tables, migrations. Land them first.
  3. Does each task have disjoint owned paths? Write the paths and the out-of-scope list into the task.
  4. Is the test suite fast and trustworthy? A flaky suite turns every green run into noise.
  5. Is there review capacity for every branch? The bottleneck moves; it does not disappear.
  6. Can each task finish in a bounded session? A task that needs 40 files of context is not a parallel unit.
  7. Is there a rollback path? Keep the branch and the worktree until the change is verified in main.

If any answer is no, fix that before adding the agent. The goal is not maximum concurrency; it is reviewed, mergeable work. If you are still deciding whether to add a second agent, read from one agent to a fleet.

What to measure

Parallelism is an investment; measure whether it pays back.

  • Wall-clock time per task. From queue to merge, not from agent start to exit.
  • Review time per diff. If review time grows faster than execution time shrinks, you moved the bottleneck.
  • Merge failure rate. How often a branch fails to merge or needs rework. A rising rate means scoping or merge order is wrong.
  • Rework rate. How often a reviewed task is rejected or reopened. A high rate means the task statement or the tests are weak.
  • Queue wait time. If tasks wait longer than they run, the slot limit or review capacity is the constraint.
  • Cost per accepted change. Tokens plus review time divided by merged tasks. This is the number that decides whether the fleet is worth it.

Run the same five tasks sequentially for a week, then in parallel for a week. Compare the six numbers. If parallelism does not improve cost per accepted change, reduce the fleet or fix the review loop before adding more agents.

FAQ

How many coding agents can run in parallel on one repository?

The practical limit is review capacity and machine resources, not Git. Start with two, measure how long review takes, and add slots only when the queue is consistently empty and the diffs are still being read.

Do Git worktrees prevent merge conflicts?

No. They prevent file overwrites while the agents work. Two branches can still change the same shared file, and the merge can still conflict. Scoping and merge order prevent most of it.

What should each agent own?

A disjoint set of paths, a task statement, a verification command, and an explicit out-of-scope list. Shared registration files should be owned by one task or landed on main before the parallel work starts.

Can I run different CLI agents in the same repository?

Yes. Worktrees are harness-agnostic. Workbench runs 44 CLI agents, including Claude Code, Codex, and OpenCode, each session in its own worktree, with one review surface. The harness still decides how it edits and compacts; the worktree and the review gate stay the same.

Should I use worktrees or containers?

Use worktrees when the agents are trusted, the main risk is file collisions, and you want fast local setup. Use containers when you need process, network, or database isolation, or when the agent runs untrusted commands. The two can be combined: a container per worktree is a common setup for unsupervised runs.