Guide

Parallel AI coding agents with git worktrees

Git worktrees are the missing primitive for multi-agent development: each agent gets its own directory and its own branch, from one repository. Here's the manual recipe, and what it costs to run by hand.

By Kylian Migot · Updated July 2026 · 8 min read

Quick answer

Git worktrees let one repository check out multiple branches at once, each in its own directory. That's the isolation primitive that lets several AI coding agents work in parallel without stepping on each other's files. You can manage worktrees by hand with three git commands, or let an orchestrator like AIDEN create one per task automatically.
The primitive
git worktree add, one repo, many branches checked out in parallel dirs
Why for AI agents
No file, index, or dev-server collisions between concurrent agents
Since when
Git 2.5 (2015), stable, built-in, no plugins needed
What AIDEN does
Auto-creates a worktree per story, runs the agent inside it, opens the PR
01

What are git worktrees?

A git worktree is a linked working directory attached to an existing repository. Unlike a second clone, which duplicates the whole object database, a worktree shares history and objects with the main checkout while giving you a fully independent directory on a different branch. Git has shipped worktrees since version 2.5 in 2015; most developers never needed them until background coding agents made "several branches checked out at once" the normal case.

# create a worktree one level up, on a new branch
git worktree add ../my-feature feature/my-feature

# list all worktrees attached to this repo
git worktree list

# remove when done, then clean up stale metadata
git worktree remove ../my-feature
git worktree prune

What each worktree owns, and what all of them share:

Per worktree (isolated)Shared across all worktrees
Working directory and filesCommit history and object store
Checked-out branch and HEADRemotes and fetched refs
Index (staging area)Stashes and most git config
node_modules, venvs, dev-server portsDisk cost: a checkout, not a full clone
02

Why shared checkouts fail parallel agents

The most common mistake when running multiple AI agents is pointing them all at the same branch in the same directory. Three failure modes show up almost immediately:

File conflicts

Agent A is modifying src/lib/auth.ts. Agent B opens the same file for an unrelated change. One agent's writes overwrite the other's mid-execution, and neither notices; each just proceeds with corrupted context.

Index collisions

Claude Code and Codex both stage files before committing. Two agents staging different versions of the same file in one shared index produce a commit that neither agent designed.

Dev-server conflicts

Agents that run tests or start dev servers fight over ports 3000 and 8080. The second server fails to bind, tests time out, and the agent loops trying to recover or reports false failures.

Worktrees eliminate all three. Each agent gets its own directory, its own branch, its own index, and its own ports. The only coordination point is shared git history, which agents read until they push their own branch, agents share nothing except the foundation they branched from. That isolation is one of the few hard guarantees in a multi-agent coding workflow; most other safeguards are conventions.

Ship your first agent today

Download AIDEN free and point it at your existing Claude Code or Codex setup. No credit card, running in minutes.

Download AIDEN free

Free to start · macOS 12+ · No credit card required

03

Manual setup: parallel Claude Code agents in 5 steps

This is the workflow many experienced developers run today, and it's the foundation an orchestrator automates. It works with Claude Code, Codex CLI, or a mix.

  1. 1

    Create a worktree per task

    From your main checkout, create one worktree and branch for each parallel task. Each directory gets a fresh checkout of its own new branch.
    git worktree add ../project-auth feature/auth
    git worktree add ../project-payments feature/payments
    git worktree add ../project-notifications feature/notifications
  2. 2

    Open a terminal in each worktree

    cd into each directory in its own terminal tab or tmux pane. Every command from here on, npm install, npm run dev, git commit, affects only that worktree's branch.
  3. 3

    Launch an agent in each

    Run claude (or codex) in each terminal and give each agent its task. Isolated directory, isolated branch: the agent can commit, run tests, and start a dev server without coordinating with anyone.
    cd ../project-auth && claude
    cd ../project-payments && claude
    cd ../project-notifications && codex
  4. 4

    Track progress by hand

    This is where the manual approach strains. With three panes it's manageable; with five you're constantly cycling tabs to find out which agent is blocked, which committed, and which is waiting on you.
  5. 5

    Push, open PRs, clean up

    For each finished task: push the branch, open a PR, remove the worktree. At five parallel tasks this is 15+ commands per cycle.
    git push -u origin feature/auth
    gh pr create
    git worktree remove ../project-auth
    git worktree prune

The workflow is entirely valid, nothing here is a hack. The cost is bookkeeping: worktree lifecycle, terminal juggling, and per-branch PR ceremony, multiplied by every parallel task, every cycle.

04

Automating the worktree lifecycle

An orchestrator's job is to make steps 1, 4, and 5 disappear. AIDEN, a desktop workspace that runs your existing Claude Code and Codex CLIs, handles the worktree and PR plumbing around each task. The broader session-management picture is covered in Claude Code orchestration.

Worktree per story, automatically

Launching a story from the kanban board creates the branch and worktree, named after the story. Cleanup happens when the story closes, no dangling directories to prune by hand.

Spec-gated launch

Before any agent starts, you approve a written spec, an enforced gate since v1.5.21. The agent begins inside its worktree with that spec as context.

Board instead of tabs

Each story is a card with a branch and a status: Stories, Spec Review, In Progress, Review, Done. You review diffs in the git panel, not keystrokes in five terminals.

One-click PR

Approve the diff and AIDEN pushes the branch and opens the pull request, with an optional LLM review pass first. The full story-to-merge pipeline is described in AI PR automation.
05

How many parallel agents can you actually run?

Git isn't the constraint, it handles hundreds of worktrees without complaint. The honest answer is "it depends", on three things you can reason about:

Repo size and machine

Each worktree is a full checkout, and each agent is a subprocess, plus node_modules or a venv per directory if agents install dependencies. Big monorepos and dev servers per worktree add up faster than small services.

Model rate limits

Anthropic and OpenAI apply per-minute token limits by plan tier. Launch too many agents at once and some will stall on rate-limit errors rather than fail loudly. Stagger launches if you're on a lower tier.

Your review throughput

The real bottleneck. Every parallel agent produces a diff that deserves an attentive read. If PRs pile up faster than you can review them, more agents just means a bigger unreviewed queue.

In practice most people cap out on review attention long before hardware. Start with two or three parallel stories, notice where your queue backs up, and scale from there, the goal of an agentic IDE workflow is more reviewed, merged work, not more concurrent processes.

FAQ

What is a git worktree?
A git worktree is a linked working directory attached to an existing repository. It lets you check out a different branch in a separate directory without cloning the repo again. You can have as many worktrees as you need, each on a different branch, all sharing the same underlying git history and object store.
How many AI agents can run in parallel with worktrees?
Git itself handles hundreds of worktrees. The real limits are your machine's resources, your model provider's rate limits, and, most of all, how many diffs you can review with attention. Most developers cap out on review throughput well before hardware.
Do parallel agents interfere with each other in worktrees?
No, that's exactly what worktrees prevent. Each agent operates in its own directory on its own branch, with its own index and HEAD. Agents cannot see each other's uncommitted changes. The only shared surface is git history, which they read from and only add to when they commit and push their own branch.
Git worktree vs multiple clones, which is better for agents?
Worktrees. A second clone duplicates the entire object database and has no automatic link to your local branches; a worktree shares the object store, costs little to create, and shows up in git worktree list so cleanup is trackable. Clones only win if you need fully separate git configs or hooks per agent.
Does AIDEN manage worktrees automatically?
Yes. AIDEN creates a branch/worktree for each story you launch, starts your Claude Code or Codex CLI inside it with the approved spec as context, shows status on a kanban board, and opens the PR when you approve the diff. You never type git worktree add or remove yourself.

Keep reading

Skip the worktree bookkeeping

AIDEN creates a worktree per story, runs your Claude Code or Codex CLI inside it, and opens the PR. Free for 1 project.

macOS 12+ · Bring your own Claude Code or Codex · Your code stays local