Updated

How to run coding agents in parallel

Give each agent its own git worktree on its own branch, start one agent per worktree in its own terminal, then review and merge each branch the way you would a pull request. The worktrees stop agents overwriting each other's files, and the branches keep their work apart until you decide what to keep.

You can do all of it by hand with git and tmux, and this page shows how. Further down it shows what an app does for you instead. Disclosure: that app, Agency, is ours, and this site is its home.

Why two agents in one checkout go wrong

A coding agent reads files, edits them and runs commands in whatever folder you start it in. Start two in the same folder and they share one working tree: one agent's half-finished edit is the other agent's starting point, a test run picks up changes neither agent meant to make, and a commit can sweep up the other agent's files. Nothing has to crash for the result to be wrong.

What a git worktree is

A git worktree is a second checkout of the same repository, in its own folder, on its own branch. All the worktrees share one history, so a commit made in one is visible from the others, but each has its own files on disk. An agent in one worktree cannot touch the files in another.

Run agents in parallel by hand

The commands assume a repository called myapp with a main branch, and two tasks: fixing login and adding search.

  1. Create a worktree and branch for each task

    Run these from inside myapp. Each makes a new folder next to it and a new branch from main.

    git worktree add -b agent/fix-login ../myapp-fix-login main
    git worktree add -b agent/search ../myapp-search main
  2. Set each one up

    A worktree is a fresh checkout, so it has no dependencies installed and none of your untracked files, such as .env. Install and copy what the project needs into each folder before an agent starts there.

  3. Start one agent per worktree

    Any agent CLI works, and they do not have to be the same one. With tmux, each gets its own window in one session:

    tmux new-session -d -s agents -c "$PWD/../myapp-fix-login" claude
    tmux new-window -t agents -c "$PWD/../myapp-search" codex
    tmux attach -t agents

    Some CLIs can make the worktree themselves. Claude Code's claude --worktree fix-login creates one under .claude/worktrees/fix-login on a branch called worktree-fix-login (its documentation).

  4. Review each branch on its own

    When an agent says it is done, read what it changed against the point it started from:

    git diff main...agent/fix-login
  5. Merge what is good, then clean up

    git merge agent/fix-login
    git worktree remove ../myapp-fix-login
    git branch -d agent/fix-login

    If two agents changed the same lines, the second merge stops with a conflict. Resolve it the usual way; the worktrees only kept the agents apart while they worked.

How many agents should you run at once?

Fewer than you think. The limit is rarely the machine: it is how many diffs you can read carefully, and the usage limits of the plan or API key behind each agent. Start with two or three tasks that touch different parts of the code. Every worktree is a full checkout with its own dependencies, so a large project also costs disk space per agent.

What gets hard by hand

  • Knowing which agent has finished and which is stuck waiting on a question
  • Remembering which folder and branch belongs to which task
  • Reading each diff in a terminal, then merging and removing the worktree
  • Comparing two agents' attempts at the same task and keeping the better one
  • Cleaning up worktrees and branches from runs you abandoned

Doing the same with Agency

Agency is a free, open-source desktop app for macOS and Linux that does this bookkeeping. It runs the same agent CLIs, in real terminals, so nothing about how the agents work changes.

StepBy handIn Agency
Isolate each taskgit worktree add per taskEvery run gets its own worktree and branch
Start the agentsA tmux window per worktreePick the agent per run; each opens in a real terminal you can type into
Know who needs youCheck each windowEach run shows whether its agent is working, waiting or done, with a desktop alert
Reviewgit diff per branchA per-run diff, with comments you can send back to the agent
Merge and clean upgit merge, worktree remove, branch -dMerge from the run, with conflict resolution in the app
Try one task several waysA worktree per attempt, compared by handA race sends one prompt to several agents; keep the branch you like

Who should not use it: anyone on Windows or an Intel Mac, which Agency does not support yet, and anyone happy in tmux who runs one or two agents at a time. The steps above are all you need there.

Going further

Questions

Can two agents edit the same file at the same time?

Yes, if each is in its own worktree. Each edits its own copy, and the two versions only meet when you merge, where git shows you any conflict.

Does each worktree copy the whole repository?

No. Worktrees share the repository's history and objects; each one holds only its own checked-out files. Dependencies and build output are per worktree, though.

Do the agents have to be the same CLI?

No. Each worktree is an ordinary folder, so you can run Claude Code in one, Codex in another and Gemini CLI in a third.