How to Run Parallel AI Coding Agents With Git Worktrees
The short answer
One task, one agent, one worktree. A git worktree is an extra working directory on its own branch that shares your repository’s history. Put each agent in its own worktree and they cannot overwrite each other’s files. As of November 2026 the fastest way is:
# Claude Code: one isolated session per terminal
claude --worktree feature-auth
claude --worktree fix-billing-bug
# Any agent, plain git
git worktree add ../myapp-feature-auth -b feature-auth
cd ../myapp-feature-auth && codex
Then review each branch, merge what works and delete the rest.
Step 1: Prepare the repository
- Commit first. Worktrees are created from a commit; in a repository with no commits,
claude --worktreefails withFailed to resolve base branch "HEAD". - Ignore the worktree folder. Claude Code creates worktrees under
.claude/worktrees/<name>/; add.claude/worktrees/to.gitignoreso they do not show up as untracked files. - Split the work. Agents in parallel only help on tasks that touch different files: a feature, a bug fix, a test backfill, a dependency bump. Two agents refactoring the same module will produce a merge conflict you have to resolve yourself.
Step 2: Create one worktree per agent
Claude Code. claude --worktree <name> (or -w) creates .claude/worktrees/<name>/ on a new branch worktree-<name> and starts Claude there. Omit the name and Claude invents one. Inside a session you can also say “work in a worktree” and Claude creates one with its EnterWorktree tool. Interactive runs need workspace trust, so run claude once in the repository first.
Plain git, for any agent (Codex, Gemini CLI, OpenCode, Aider…):
git worktree add ../myapp-task-1 -b task-1
git worktree add ../myapp-task-2 -b task-2
git worktree list
Worktrunk makes this one command and starts the agent too: wt switch -c -x claude feature-a creates the branch and worktree and launches Claude in it (our Worktrunk review).
Step 3: Set up each worktree’s environment
A worktree is a fresh checkout. Before the agent runs tests it needs:
- Gitignored files —
.env, local certificates. Claude Code copies anything listed in.worktreeincludeinto every new worktree. With plain git, a two-line setup script does it. - Dependencies —
npm install,uv syncor equivalent, per worktree. Ask the agent to do it as its first step. - Separate ports — two dev servers cannot both bind port 3000. Pass
PORT=3001and so on. - Separate test state — if tests write to a local database, give each worktree its own database name or schema.
Step 4: Watch and review
Keep one terminal per agent, or use something that shows them side by side. Claude Code’s background agents let you monitor parallel sessions from one screen. Desktop apps such as Orca, Paradev and T3 Code show each agent’s status and diff and open the PR for you; they replace Conductor, whose cloud service shuts down on November 20, 2026 after its team joined Meta (Conductor alternatives).
Review each branch like a colleague’s PR: run the tests yourself, read the diff, and throw away branches that went sideways. Rerunning a task in a fresh worktree is usually cheaper than rescuing a confused one.
Step 5: Merge and clean up
git switch main
git merge --no-ff task-1 # or open a PR from the branch
git worktree remove ../myapp-task-1
git branch -d task-1
git worktree prune # drop entries for folders you deleted by hand
When you exit a Claude Code worktree session, Claude checks it for uncommitted files and new commits: a clean worktree from an unnamed session is removed automatically with its branch; otherwise Claude asks whether to keep or remove it, and prints a claude --worktree <name> --resume command if you keep it. With Worktrunk, wt merge main and wt remove do the same.
Common problems
| Problem | Fix |
|---|---|
| ”fatal: ‘feature-a’ is already checked out” | A branch can be checked out in only one worktree. Use a new branch name per agent. |
| Agent edits the main checkout instead | Start the agent from inside the worktree folder; for Claude Code use --worktree rather than cd. |
| Tests fail only in the worktree | Missing .env or dependencies: add them to .worktreeinclude or your setup script. |
| Disk filling up | Each worktree holds its own node_modules or virtualenv; remove finished worktrees promptly. |
| Two agents changed the same file | Merge one branch, rebase the other on main, and let the second agent resolve the conflict. |
When worktrees are not enough
Worktrees isolate files on one machine. Long tasks that should run while your laptop sleeps belong in cloud agents (Codex cloud, Cursor cloud agents, Claude Code cloud sessions); see best AI coding agents for parallel development. And parallel agents use your plan’s allowance in parallel, so watch usage before scaling from three agents to ten.
Last verified: November 6, 2026, against the Claude Code worktree documentation, the git-worktree manual and the Worktrunk README.