The bottleneck in agentic coding is not the model anymore. It is you, sitting in one terminal, feeding one Claude Code session one task at a time while the other two features you wanted to ship this afternoon sit in your head waiting for a turn. The model can hold three independent problems in parallel. Your single checkout cannot.

Most people hit this wall and conclude agents do not parallelize. They do. The thing that does not parallelize is a single working directory. One repo, one branch checked out, one set of uncommitted changes. Two agents in that directory will overwrite each other’s edits, stage each other’s files, and leave you with a working tree that belongs to neither task. The fix is not a smarter model or a queue. It is git worktrees, a feature that has shipped with git since 2015 and that almost nobody uses until they try to run two agents at once.

This post walks through why the naive single-branch setup breaks, how worktrees give each agent its own isolated checkout, how to write prompts so agents do not collide on shared files, and the CI pattern that tests every worktree branch before it merges.

The Naive Setup and Exactly Where It Breaks

The naive approach is the obvious one. You have your repo. You want Claude to build feature A, and while it thinks, you want a second session on feature B. So you open two terminals in the same directory and start two sessions.

~/project   (branch: main)
  terminal 1: claude -> "add rate limiting to the API"
  terminal 2: claude -> "add CSV export to the reports page"

Here is the sequence of ways this falls apart, in the order you will actually hit them.

1. Shared uncommitted state. Both agents edit files in the same working tree. Agent A adds a middleware file and edits app.py. Agent B also edits app.py to wire up a new route. Neither of them knows the other exists. The second write wins. Now app.py has B’s route and lost A’s middleware import, and A’s next edit is computed against a file that B already changed underneath it. You get corruption that no merge tool will ever catch because it never became a conflict - it was a silent overwrite inside one branch.

2. Branch thrash. You try to be disciplined: agent A works on branch feat-a, agent B on feat-b. But there is one working directory and one HEAD. When A runs git checkout feat-a and B runs git checkout feat-b, they are fighting over the same pointer. One agent’s checkout yanks the files out from under the other mid-edit. git stash becomes a game of musical chairs and eventually someone’s changes end up on the wrong branch.

3. Test runs stomp on each other. Both agents run the test suite. They share the same __pycache__, the same node_modules, the same .pytest_cache, the same dev server port. Agent A’s test run imports agent B’s half-written module and fails for a reason that has nothing to do with A’s task. The agent then “fixes” a problem that does not exist in its own work.

4. Serialized review. Even if you avoid all of the above by just running one agent at a time, you are now serial. Feature B does not start until feature A is done. Three independent features that each take twenty minutes take an hour instead of twenty minutes, for no reason other than directory contention.

None of these are model failures. They are all the same root cause: one working directory cannot hold multiple independent lines of work. That is precisely the problem git worktrees exist to solve.

What a Worktree Actually Is

A git worktree is a second (or third, or tenth) working directory backed by the same .git object database. One repository, many checkouts. Each worktree has its own branch, its own HEAD, its own working files, its own index. They share history and objects, so you are not cloning gigabytes three times - the extra cost is only the checked-out files plus whatever each build generates.

.git/                     (one object store, shared)
project/                  (main worktree,   branch: main)
project-rate-limit/       (worktree,        branch: feat-rate-limit)
project-csv-export/       (worktree,        branch: feat-csv-export)
project-oauth/            (worktree,        branch: feat-oauth)

Each of those directories is a complete, independent checkout. An edit in project-csv-export/ is invisible to project-rate-limit/ until it is committed and merged through git the normal way. That is the whole trick. You are not coordinating agents through shared files. You are coordinating them through branches, which git already knows how to merge.

The commands are short. From inside the main repo:

# create a worktree with a brand new branch, off the current HEAD
git worktree add ../project-rate-limit -b feat-rate-limit
git worktree add ../project-csv-export -b feat-csv-export
git worktree add ../project-oauth      -b feat-oauth

# see what you have
git worktree list

# when a feature is merged and done, remove its worktree
git worktree remove ../project-rate-limit
git branch -d feat-rate-limit

Now you open one Claude Code session in each directory. Three agents, three isolated checkouts, three branches, zero shared mutable state.

The Setup That Actually Works

A worktree is only isolated for files git tracks. The things that bite you are the untracked, generated, or machine-local pieces: dependency folders, virtual environments, build caches, and ports. Get these right once and the rest is smooth.

Dependencies per worktree

A new worktree has no node_modules or .venv - those are gitignored, so they do not come along. Install them per worktree. This sounds wasteful but it is the point: isolated dependencies mean agent A upgrading a package does not break agent B’s test run.

cd ../project-csv-export
npm ci          # or: uv sync, poetry install, pip install -e .

If install time hurts, share the immutable cache, not the installed tree. For Node, point every worktree at one global store with pnpm. For Python, uv already uses a shared global cache, so each .venv is cheap to create. The rule: share the download cache, never share the writable install directory.

A per-worktree environment file

The one collision that survives file isolation is network ports. Three dev servers all trying to bind :3000 will fail. Give each worktree its own port and database schema through a local env file that is gitignored.

# project-csv-export/.env.local
PORT=3002
DATABASE_URL=postgres://localhost/app_csv_export
REDIS_DB=2

Tell each agent it is in a worktree

Drop a short CLAUDE.md note, or better, a path-scoped rule, so the agent knows its lane. The single most useful instruction is the one that stops an agent from wandering.

# CLAUDE.md (worktree: feat-csv-export)

You are working in an isolated git worktree on branch `feat-csv-export`.
Your task is CSV export for the reports page only.

- Only edit files needed for CSV export.
- Do NOT touch authentication, billing, or the rate-limit middleware.
- Run the dev server with the port in .env.local (3002), not 3000.
- Commit to this branch. Never checkout or merge other branches.

Structuring Prompts So Agents Do Not Collide

Worktrees isolate the filesystem. They do not isolate intent. If you point two agents at the same source file, both branches will edit it and you will get a real merge conflict at the end - which is fine, git handles it, but you want those conflicts to be rare and mechanical, not deep and semantic. The way you scope the prompts decides that.

The guiding idea: split work by surface area, not by layer. “You do the backend, you do the frontend” sounds clean but both features need both layers, so you have not actually split anything. Split by feature, end to end, and pick features whose files barely overlap.

Split strategyOverlap riskWhy
By layer (backend / frontend)HighEvery feature touches both; agents collide in each layer
By feature, end to endLowEach owns its route, model, UI, tests; shared files are minimal
By shared core fileVery highTwo agents editing one registry or router guarantees conflicts

When two features genuinely must touch one shared file - a route registry, a central config, a dependency list - do not let two agents edit it blind. Pick one agent to own the shared file and have the other add its entry as the final merge step, by hand or in a tiny follow-up. A good prompt makes the boundary explicit:

Task: Add CSV export to the reports page.

Scope:
- Create src/reports/csv_export.py and its tests.
- Add ONE route in src/routes/reports.py (append only; do not
  reorder or edit existing routes).
- Add the "csv" UI button in src/ui/ReportsToolbar.tsx.

Do not touch: src/routes/__init__.py (the shared registry - I will
wire the import in myself after merge), auth, billing, or any file
outside the reports feature.

That “append only, do not reorder” instruction is doing real work. Most merge conflicts between well-scoped feature branches come from two agents reformatting or reordering the same block for no functional reason. Tell them not to, and the three-way merge stays trivial.

The Merge and CI Pattern

Isolation buys you clean parallel work. It does not buy you a free guarantee that the three branches combine correctly - A and B can each be green on their own branch and still break when sitting in the same tree. So the merge step needs its own gate.

The pattern that has worked for me is a per-branch CI check plus an integration check before anything lands on main.

                 feat-rate-limit ──┐
feat tests (CI)  feat-csv-export ──┼──> each branch green on its own
                 feat-oauth ───────┘
                                    │
                        merge into integration branch
                                    │
                        full suite on the combined tree
                                    │
                             green? -> merge to main

Each feature branch runs the same CI any human PR would: lint, type-check, unit tests, and the feature’s own integration tests. Nothing special here; the worktree branch is an ordinary branch and your existing pipeline already knows how to test it.

# .github/workflows/ci.yml
name: ci
on:
  pull_request:
  push:
    branches: ['feat-**']
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: 'npm'
      - run: npm ci
      - run: npm run lint
      - run: npm run typecheck
      - run: npm test

The step people skip is the combined check. Three green branches can still conflict at the integration level: two of them bumped the same dependency to incompatible versions, or both registered a route on the same path, or one changed a shared type the other relied on. Catch that before main, not after.

A cheap way to do it locally, before you even open PRs, is to merge all three into a throwaway integration branch and run the full suite once:

git switch -c integration main
git merge --no-ff feat-rate-limit feat-csv-export feat-oauth
npm ci && npm test        # the real gate: do they coexist?

If that is green, merge the branches to main one at a time and delete the worktrees. If it is red, you have found a genuine integration bug while it is still cheap, and you know exactly which two features disagree. On a team, make the integration branch a required status check so no single feature PR can merge until it has been proven to combine with the others currently in flight.

A Realistic Three-Feature Run

Here is the end-to-end shape of an afternoon, concretely.

# 1. Spin up three isolated worktrees
git worktree add ../app-rate-limit -b feat-rate-limit
git worktree add ../app-csv        -b feat-csv-export
git worktree add ../app-oauth      -b feat-oauth

# 2. Prep each (deps + local env). Scripted once:
for d in app-rate-limit app-csv app-oauth; do
  (cd ../$d && npm ci && cp ../app/.env.example .env.local)
done
# then edit each .env.local to use ports 3001 / 3002 / 3003

# 3. One Claude Code session per directory, each with a scoped prompt
#    and a worktree-local CLAUDE.md. They run at the same time.

# 4. When each reports done and its branch CI is green, do the
#    combined integration check, then merge to main.

# 5. Clean up
git worktree remove ../app-rate-limit
git worktree remove ../app-csv
git worktree remove ../app-oauth
git branch -d feat-rate-limit feat-csv-export feat-oauth

Your job during step 3 is no longer typing. It is reviewing. You rotate between three sessions, reading diffs, answering the occasional “should this be configurable?” and keeping each agent inside its lane. That is the actual productivity change: you move from author to editor, and three editors’ worth of work flows through one person because the filesystem stopped being the bottleneck.

Honest Assessment

What works, genuinely: filesystem and branch isolation is real and complete. Two agents in two worktrees cannot corrupt each other’s files, full stop. For features that are independent - different pages, different endpoints, different modules - this turns an hour of serial work into twenty minutes of parallel work plus a review pass. The git mechanics are boring and stable; worktrees are a decade old and not going anywhere.

What does not work as cleanly as the pitch: anything that must edit a shared core file. A central route registry, a single config object, an OpenAPI spec, a migrations folder with ordered filenames - these are collision magnets, and no amount of isolation fixes a true semantic conflict. You manage those by hand, by designating an owner, or by designing the shared file to be append-only. Disk and dependency duplication is real too; three Node worktrees with full node_modules is a few gigabytes, so use pnpm or a shared cache if that matters to you.

And the honest ceiling: your attention does not parallelize the way the agents do. Three agents is about the most one person can review well. Past that you are rubber-stamping, which defeats the point. The win is not “ten agents.” It is “three features done in the time of one, each one actually reviewed.”

What to actually do: start with two worktrees, not three. Pick two features that touch different files. Give each its own branch, its own .env.local with a distinct port, and a CLAUDE.md that names its lane and forbids the other feature’s files. Run your existing CI on each branch, add one combined integration check before main, and only then scale to three. The setup takes ten minutes the first time and five minutes every time after, and it is the difference between agents that queue and agents that ship.