← Back to Payloads
Tutorial

Git Worktrees for Parallel Coding Agents

You are running Claude Code on a refactor, Aider on a test fix, and a Cursor Background Agent on a dep bump. All three want the same working tree. All three will collide. Git worktrees are the five-minute fix that turns one engineer with one terminal into a team of concurrent agents — one branch per agent, no destructive checkouts, no shared-state races.
Quick Access
Install command
$ mrt install git
Browse related skills

Git Worktrees for Parallel Coding Agents

You are running Claude Code on a refactor. While it works, you want Aider on a test fix and a Cursor Background Agent on a dep bump. All three are about to land on `main`, and you have a half-finished session that cannot safely close.

The fix is a five-minute setup: **git worktrees**. One branch per agent, isolated working directories sharing one `.git` database. No destructive `checkout`, no shared-state races.

Why Serial Agent Work Is Broken

A coding agent wants exclusive access to a working tree — it reads, writes diffs, runs tests. Launch a second agent on the same checkout and they race on the same files, both try to run the test suite, and you spend the next hour cleaning up nonsense diffs.

The default workaround is branches. The problem: switching mid-session is destructive. In-flight agent state — open files, partial edits, unsaved work — gets clobbered the moment you `git checkout` away from the branch the agent is working on.

Worktrees solve this. Each is a separate working directory bound to its own branch, all sharing one `.git` database. Five worktrees, five agents, no branch switching.

The Setup

Nothing to install. Worktrees ship with git.

git config --global worktree.guessRemote true

cd ~/projects/myapp

git worktree add ../myapp-agent-a -b feat/api-refactor

git worktree add ../myapp-agent-b -b fix/test-flakes

git worktree add ../myapp-agent-c -b chore/bump-deps

Three directories, three branches, one shared `.git` database.

The Workflow

Open each worktree in its own terminal tab, IDE window, or tmux pane. Launch a different agent in each:

Terminal 1

cd ~/projects/myapp-agent-a

claude "Refactor the auth module to use the new token format"

Terminal 2

cd ~/projects/myapp-agent-b

aider src/tests/ --model claude-sonnet-4-5

Terminal 3 — Cursor Background Agent

Configure the worktree path in Cursor's agent settings

Each agent reads, writes, and tests in its own directory. The shared `.git` database keeps the branches aware of each other, but the working trees never collide. When agent A finishes, you merge from the main checkout. When two branches conflict, git tells you where.

A Real Run

Yesterday I ran three agents on the same monorepo in parallel:

  • **Claude Code**: refactoring `auth/session.py` to async/await (12 min)
  • **Aider**: fixing 14 flaky tests in `tests/integration/` (8 min)
  • **Cursor Background Agent**: bumping `package.json` deps and running `npm audit fix` (4 min, run-and-forget)

Total wall-clock: 12 minutes. Sequential would have been 24+ minutes, plus re-running agent A's tests after agent C's `npm audit` rewrote the lockfile. The merge had one conflict — in `requirements.txt`, where the refactor and the dep bump both touched the same version specifier. Resolved in 30 seconds.

The Gotchas

**Each worktree must be on its own branch.** Two worktrees on the same branch will corrupt git's state.

**Your IDE may not auto-detect new worktrees.** VS Code's "Open Folder" works fine; some JetBrains versions need a restart.

**Disk space doubles per worktree.** A 2GB monorepo times three is 6GB.

**Cleanup matters.** `git worktree remove ../myapp-agent-a` deletes the directory and the branch reference. `git worktree list` shows what is mounted. Forgotten worktrees pile up fast.

The Take

Git worktrees are the most underused tool in the multi-agent workflow. Five minutes of setup, one config command, and the payoff is the difference between running agents in series and running them in parallel. Do it before your next refactor.