iCode Workbench · Guide · Claude Code

How to run Claude Code in parallel

Two Claude Code sessions in one checkout will overwrite each other. The fix is not a bigger context window; it is one worktree per task, a scoped task statement, and a review decision before anything merges.

This guide is the worktree model: separate Claude Code sessions, each in its own checkout, working on independent tasks. For Claude Code's in-session agent teams, see the distinction below.

This guide is currently available in English only.

Prerequisites

  • Claude Code installed and working in one checkout. Run it once in the repository before you parallelize. For the Workbench-specific setup, see Claude Code in iCode Workbench.
  • A Git repository with a clean main branch and a test command you trust.
  • Two independent tasks. Different files, different tests, no shared schema change. If they share a file, they are one task.
  • A setup path for each checkout. Dependencies, .env, ports, and a database or schema per task.

If the test suite is flaky, fix that first. A green run you do not trust is not a review signal.

Create one worktree per task

Claude Code can create the worktree and start the session in one step:

claude --worktree feature-auth
claude --worktree feature-billing

Or create the worktrees with Git and launch Claude Code inside each one:

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

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

cd ../project-billing
pnpm install
cp ../project/.env .env.local
claude

Name the worktree and branch after the task, not the agent. If you use --worktree, .worktreeinclude can copy gitignored files such as .env into each new checkout.

For the mechanics and pitfalls, read Git worktrees for coding agents, explained.

A concrete two-session setup

Two tasks: an auth refresh fix and a billing retry. They touch different files and have different tests. Start both sessions:

claude --worktree feature-auth
claude --worktree feature-billing

Before either session starts, set up the checkout:

  • Dependencies: pnpm install in each worktree. Do not share node_modules unless you know the toolchain tolerates it.
  • Env: copy .env into each checkout, or use .worktreeinclude.
  • Ports: auth on 3001, billing on 3002. Make the dev server fail on a conflict rather than pick another port.
  • Databases: app_auth and app_billing. Do not let two sessions run migrations against the same database.

Then give each session its task statement: goal, owned paths, done-when command, and out-of-scope list. The auth session should not touch src/billing/**; the billing session should not touch src/auth/**.

When both finish, review the auth diff first. Rebase the billing branch on main after the auth merge, run the tests, then merge billing. The order matters even when the files are disjoint, because the shared dependencies may have changed.

Scope the tasks

A worktree prevents file overwrites. It does not prevent two sessions from changing the same shared file on different branches. Give each task a scope before the agent starts:

  • A goal in one sentence. “Fix the token refresh path,” not “improve auth.”
  • Owned paths. The files the session may change. Everything else is out of scope.
  • A done-when command. The test or verification the session must run.
  • An out-of-scope list. Public types, route tables, migrations, formatting. This is where drift gets caught.
  • A baseline. The commit or worktree state the task started from, so review can compare against it.

If both tasks need a shared contract — a new type, a route entry, a schema change — land that change on main first, then branch.

Launch and monitor

Run each session in its own terminal or in a workbench that shows all of them. The important part is not the UI; it is that you can see:

  • which task is running, queued, or waiting for you;
  • which checkout each session owns;
  • which session has finished but not been reviewed.

With two sessions, a pair of terminals can work. With three or more, use a queue: a list with explicit states, a slot limit, and a review decision. The queue is what keeps “running” from being confused with “done.”

For the queue model, read how to queue coding agent tasks.

When a session stalls

A stalled session is not always a failed one. Three states look similar from a terminal and require different responses:

  • Waiting for you. The agent asked a question or needs an approval. Read the prompt and answer. Do not kill the session; you will lose the context that produced the question.
  • Running slowly. The agent is still working. Check the last tool call or file it touched before you assume it is stuck.
  • Failed or looping. The process is repeating the same action or has exited with an error. Stop it, keep the branch, and read the diff before retrying. A retry without a change produces the same failure.

This is one reason a queue is useful even with two sessions: it tells you which state each task is in, so you do not interrupt a waiting session or wait on a failed one.

Review before you merge

When a session finishes, review the diff in its checkout. Run the done-when command yourself, check the files outside the owned paths, and look for deleted or weakened tests.

The review decision is separate from the process exit. A completed session can still be rejected or sent back for revision. Do not merge just because Claude Code exited zero.

For the full review workflow, read how to review AI-generated code.

Merge in order

Merge one branch at a time. Rebase each branch on main, run the tests, and merge the combined result. Two branches can pass alone and fail together.

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. Keep the worktree and branch until the change is verified in main; removing a worktree deletes uncommitted changes.

Claude Code agent teams vs parallel sessions

Claude Code also supports agent teams: a lead session spawns named teammates that share a task list and can message each other. That is a different model. Agent teams orchestrate subagents inside a parent session; the parallel-session model runs separate sessions, often in separate worktrees, and lets you mix harnesses.

Use agent teams when the work is one coordinated effort that benefits from a lead and shared context. Use separate worktrees when the tasks are independent, the sessions may use different agents or subscriptions, and you want each diff reviewed on its own. Both can be valid; do not mix them without knowing which one owns the checkout.

Anthropic's documentation covers agent teams and worktrees.

When to move to a workbench

Two sessions in two terminals can work. The setup starts to break when:

  • you have more tasks than terminals and track states in your head;
  • a session is waiting while another is running and you miss the waiting one;
  • review becomes the bottleneck and you need a visible queue of unreviewed diffs;
  • you want the task state to survive an app restart.

A workbench is not a different workflow; it makes the workflow the default: worktrees, explicit task states, a bounded queue, and review in the session checkout. If the two-session setup is working, keep it. If you are losing track, move the queue into a tool before you add a third session.

Common mistakes

  • Two sessions in one checkout. They will overwrite each other. Use one worktree per task.
  • Two tasks on the same file. A worktree does not prevent a semantic conflict. Land the shared change first.
  • Forgetting .env and dependencies. A fresh worktree is a clean checkout, not a working environment.
  • Port and database collisions. Assign a port and a database or schema per checkout.
  • Merging without review. A green session is not an accepted change.
  • Long-lived worktrees. Rebase after every merge; the longer a branch lives, the more the merge becomes a design decision.