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.
-
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 frommain.git worktree add -b agent/fix-login ../myapp-fix-login main git worktree add -b agent/search ../myapp-search main -
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. -
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 agentsSome CLIs can make the worktree themselves. Claude Code's
claude --worktree fix-logincreates one under.claude/worktrees/fix-loginon a branch calledworktree-fix-login(its documentation). -
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 -
Merge what is good, then clean up
git merge agent/fix-login git worktree remove ../myapp-fix-login git branch -d agent/fix-loginIf 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.
| Step | By hand | In Agency |
|---|---|---|
| Isolate each task | git worktree add per task | Every run gets its own worktree and branch |
| Start the agents | A tmux window per worktree | Pick the agent per run; each opens in a real terminal you can type into |
| Know who needs you | Check each window | Each run shows whether its agent is working, waiting or done, with a desktop alert |
| Review | git diff per branch | A per-run diff, with comments you can send back to the agent |
| Merge and clean up | git merge, worktree remove, branch -d | Merge from the run, with conflict resolution in the app |
| Try one task several ways | A worktree per attempt, compared by hand | A 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
- Git worktrees for AI coding agents: what a worktree does not copy, and how to clean up.
- Race several agents on one prompt and keep the best attempt.
- Loop an agent until the tests pass, with caps on attempts, time and tokens.
- A markdown issue tracker your agents can work, one file per issue.
- The agent CLIs Agency supports: install, resume, loop and MCP for each.
- Run coding agents in parallel on Linux, with the install per distribution.
- Choosing a tool to run coding agents in parallel: the criteria, and when the answer is not Agency.
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.