Skip to content

Run coding agents in parallel with git worktrees.

Two agents in one checkout overwrite each other’s files and mix their changes in one diff. Give each agent its own git worktree on its own branch, and they can work side by side on the same repository.

Applies to Claude Code, Codex, OpenCode, Cursor Agent, Gemini CLI and any CLI agent6 min read

Why worktrees

A git worktree is a second working folder for the same repository, checked out on its own branch. Every worktree shares one history and one object store, so it costs little disk and no clone. An agent in its own worktree works on its own files, runs its own tests and commits to its own branch; another agent’s half-done edits never show up there.

This works the same for every agent with a CLI: Claude Code, Codex, OpenCode, Cursor Agent, Gemini CLI, Aider or your own.

By hand

  1. Make a worktree per task, on a new branch from main.
    Terminal
    cd ~/code/payments-api
    git worktree add -b refund-retries ../payments-api-refund-retries main
    git worktree add -b ledger-export ../payments-api-ledger-export main
  2. Prepare each one.A new worktree has no node_modules and no untracked files such as .env.
    Terminal
    cd ~/code/payments-api-refund-retries
    pnpm install
    cp ../payments-api/.env .env
    
    cd ~/code/payments-api-ledger-export
    pnpm install
    cp ../payments-api/.env .env
  3. Start one agent per worktree, each in its own tmux session.
    Terminal
    tmux new-session -d -s refund-retries -c ~/code/payments-api-refund-retries claude
    tmux new-session -d -s ledger-export -c ~/code/payments-api-ledger-export codex
    tmux attach -t refund-retries
    Ctrl-b, then a lowercase d, leaves the session and brings you back to your shell; tmux attach -t ledger-export visits the other agent.
  4. See what you have.
    Terminal
    git worktree list
    tmux ls

Cleaning up

When a branch is on main and its agent has stopped, remove its worktree and the branch. git worktree remove refuses a worktree with uncommitted changes, which protects work you have not looked at yet. A squash merge leaves the branch looking unmerged to git, so delete it with -D.

Terminal
cd ~/code/payments-api
git worktree remove ../payments-api-refund-retries
git branch -D refund-retries

How many agents

As many as you can follow. Each agent asks questions, waits for answers and produces a diff someone has to read. Three agents you follow well get more merged than ten you check on now and then. The limits that bite first are usually your attention, your usage limits and your laptop’s memory.

With Dockazor

New Worktree… ⇧⌘N does the first three steps in one sheet. It makes the worktree at <project>/.dockazor/worktrees/<name> on a new branch from main, runs your setup command, and opens a chat on the default chat preset. Type a brief and it becomes the chat’s first message.

  • Each chat is the agent’s own CLI in a terminal. Dockazor sends nothing to a model you did not ask for.
  • The New Chat menu adds a chat on another agent to the same worktree, for a reviewer or a different model; ⌘N starts the default preset.
  • Every worktree of every project sits in one sidebar, each chat marked Working, Needs you or Idle.
  • Archive removes the worktree’s folder and its branch, on your Mac and on origin.
Plain git underneath

The worktrees and branches Dockazor makes are ordinary git. git worktree list shows them, and your work stays usable with git alone.