How to run several AI coding agents at once with git worktrees
Short answer: give each agent its own git worktree, a separate folder checked out on its own branch from the same repository. Run git worktree add ../myapp-auth -b feat/auth, start the agent inside that folder, and repeat for each task. The agents share one git history but never touch each other's files. When a task is done, review its branch, merge it, and remove the worktree.
Why agents collide without worktrees
Two agents in the same folder edit the same working copy. One runs a formatter while the other is halfway through a change; one switches branch and the other's files vanish; both install packages at once. You end up with a mixed diff nobody can review.
A worktree fixes this at the git level. Each worktree has its own files and its own checked-out branch, but they share the repository's object store, so creating one is fast and costs almost no disk space for history.
Step 1: Create one worktree per task
From your main checkout:
git fetch origin
git worktree add ../myapp-auth -b feat/auth origin/main
git worktree add ../myapp-billing -b feat/billing-export origin/main
git worktree list
Each command creates a sibling folder on a new branch starting from the latest main. Keep the folders next to the repository, not inside it, so tools that scan the repo do not pick them up.
Step 2: Set each worktree up
A worktree has your tracked files, but not ignored ones. In each folder:
- Install dependencies (
pnpm install,uv sync,go mod download). Package managers with a shared store (pnpm, uv) make this quick. - Copy local config such as
.envfrom the main checkout. Never commit it. - Pick a different port if the agent will start a dev server, so two servers do not fight over port 3000.
Step 3: Start an agent in each
Open a terminal per worktree and start the agent there:
cd ../myapp-auth && claude
cd ../myapp-billing && codex
Recent versions of Claude Code can also create the worktree for you with claude --worktree <name>. Give every agent a clear, scoped task, and tell it which branch it is on and what "done" means (tests pass, lint clean).
Step 4: Review each branch as a pull request
When an agent finishes, review its work the way you would a teammate's:
git -C ../myapp-auth diff origin/main...HEAD
Or push the branch and open a pull request. Read the diff, run the tests, and follow a checklist like how to review AI-written code.
Step 5: Clean up
git worktree remove ../myapp-auth
git branch -d feat/auth
git worktree prune
remove refuses if the folder has uncommitted changes, which protects unfinished work.
How many agents at once?
Most people manage two to four comfortably. The limits are your attention for review, your model plan's rate limits, and your laptop's memory once several dev servers and test runs are going. Beyond that, time spent reviewing and merging outweighs the parallelism.
Tools that do this for you
Doing this by hand works, but it is a lot of terminals. Several apps automate it:
| Tool | What it does | Platforms |
|---|---|---|
| Zokie | Agent IDE: a worktree and branch per task, a Board of every task, diff review, sub-agents | macOS, Windows |
| Conductor | Runs Claude Code, Codex and others in parallel worktrees | macOS |
Claude Code --worktree | Creates one worktree per session | Anywhere Claude Code runs |
Disclosure: we build Zokie.
FAQ
What is a git worktree?
A second (or third) working folder for the same repository, each on its own branch. All worktrees share one history, so you can work on several branches at once without cloning the repo again.
Do worktrees use a lot of disk space?
No for history, which is shared. Yes for dependencies: each worktree needs its own node_modules or virtual environment unless your package manager links from a shared store.
Can two worktrees use the same branch?
No. Git refuses to check out a branch that is already checked out in another worktree, which is exactly what stops two agents editing the same branch.
Does this work with Codex, Gemini CLI and Cursor CLI?
Yes. Any agent that works on files in a folder works in a worktree.