# Parallel Claude Code agents: what still breaks after you add worktrees

<!--
title: "Parallel Claude Code agents: what still breaks after you add worktrees · Cork"
description: "Worktrees stop parallel Claude Code sessions from overwriting each other's files. What they don't stop: merge conflicts, clean merges that don't build, decisions that never reach the other session, shared memory and config, ports and databases, setup cost and git lock races. The fix for each."
canonical: "https://corkcli.com/blog/parallel-claude-code-agents-what-still-breaks"
last_updated: "2026-11-18"
published: "2026-11-18"
author: "Kevin Vera"
-->

Worktrees stop parallel Claude Code sessions from overwriting each other's files. What they don't stop: merge conflicts, clean merges that don't build, decisions that never reach the other session, shared memory and config, ports and databases, setup cost and git lock races. The fix for each.

By Kevin Vera · November 18, 2026 · [Guides](https://corkcli.com/blog/c/guides) · 7 min read

Ask how to run several Claude Code agents on one repository and the answer is nearly always the same: give each one a git worktree. Claude Code builds it in. `claude --worktree feature-auth` creates `.claude/worktrees/feature-auth/` on a new branch named `worktree-feature-auth` and starts the session there. Its documentation states the promise plainly: worktrees "isolate file edits."

That is all they isolate. This is what still breaks once your agents each have a worktree, where each problem comes from, and what to do about it.

## 1. Merge conflicts, found at merge time

Two sessions that change the same lines conflict when the second branch merges, whichever worktree they worked in. GitButler's Scott Chacon: "The worktrees are separate, so you can easily create merge conflicts between them without knowing."

**Fix:** check the branches against each other while the agents work (`git merge-tree --write-tree`, Git 2.38 or later), and land one branch at a time. The commands are in [git worktree merge conflicts with AI agents](https://corkcli.com/blog/git-worktree-merge-conflicts-ai-agents).

## 2. Clean merges that don't build

One session renames a function and another adds a call to the old name in a different file. Git merges both without a conflict, and the build fails. This is a [semantic merge conflict](https://corkcli.com/blog/semantic-merge-conflict), and worktrees make it more likely, because neither session can see the other's change until both have landed.

**Fix:** build and test the merged result before it lands, not each branch on its own.

## 3. Decisions stay in the session that made them

João Camarate made the case on dev.to. Worktrees solve the file conflicts, Camarate writes, but "each Claude Code session has its own context window." Camarate's example: "When agent A decides 'we prefix these functions with `handle_`,' that decision lives in agent A's session." Agent B, in its own worktree, "will make a different choice," and "not because it disagreed, but because it was never told." The conclusion: "You become the [coordination layer](https://corkcli.com/blog/coordination-layer-ai-coding-agents) that the agents cannot be for each other."

**Fix:** write shared decisions into `CLAUDE.md` before the sessions start, and pass the ones made along the way between sessions. Claude Code's cross-session messaging (v2.1.224 on macOS and Linux, v2.1.234 on native Windows) lets one session send another plain text on the same machine.

## 4. Two sessions build the same thing

The flip side of 3: each session notices the same gap and fills it. In one of our own test runs, two sessions were about to edit the same seven files, and both had noticed the same missing module and set out to write it. The worktrees would have let both finish, and one copy would have been thrown away at merge.

**Fix:** split the work up front by files or by feature, and have each session say what it is taking before it starts.

## 5. Shared files that aren't in the worktree

A worktree copies the repository's files, not everything Claude reads. The Claude Code docs list what a worktree still shares with the main checkout:
- the repository's `.git` directory;
- plugins installed at project scope;
- permission approvals, which are saved to the main checkout's `.claude/settings.local.json`.

Hooks see `${CLAUDE_PROJECT_DIR}` still pointing at the original project root. And the edit guard that keeps a worktree session out of the main checkout doesn't cover shell commands: "a command that writes into the main checkout without running git there, such as `cp` or a shell redirect, isn't refused."

Your user-level files are shared too. Ken Imoto ran three sessions in three worktrees for eight hours. In Imoto's words: "Each session got the same system context: my repo `CLAUDE.md`, my user-level `~/.claude/CLAUDE.md`, my `~/.claude/skills/`, and my `~/.claude/projects/<repo>/memory/` directory." Imoto reports two collisions, one in a skills file and one in a memory file, and "roughly $47 of Sonnet tokens" spent redoing work. Imoto's summary: "Worktrees isolate your source code. They do not isolate Claude's brain."

**Fix:** treat memory files, skills and `CLAUDE.md` as shared state. Change them from one session at a time, and keep task-specific notes in the worktree.

## 6. Ports, databases and services

Upsun's guide puts it in one sentence: worktrees "isolate code but not the runtime environment. You get separate file systems but shared ports, databases, and services." Two dev servers want the same port. Two agents share one local database, and Trigger.dev's example follows: "Agent A runs a migration. Agent B's schema is now out of sync."

**Fix:** give each worktree its own port through its environment file, a database or schema per worktree, and a separate Docker Compose project name. Or move that runtime into a per-branch preview environment.

## 7. Setup cost and disk

Every worktree needs its own install and its own build. Trigger.dev stopped using them for that reason: "When we tried worktrees for parallel Claude Code sessions, we spent more time on setup than shipping code." Their monorepo would need "its own PostgreSQL, Redis, ClickHouse, and Electric instance" per worktree. Both Upsun and Trigger.dev cite Cursor forum users who saw a 20-minute session with a codebase of about 2 GB use 9.82 GB of disk across its worktrees.

**Fix:** use a package manager with a shared store (pnpm, for example), copy prepared `.env` and build caches into each new worktree with a setup script, and delete worktrees as soon as their branch lands. If setup is still the bottleneck, see the [alternatives to worktrees](https://corkcli.com/blog/git-worktrees-alternatives-claude-code).

## 8. Git lock races

The worktrees share one `.git` directory, so parallel git commands contend for the same locks. Claude Code's own issue tracker has an example: parallel agents using worktree isolation "fail due to git config lock race condition" (#47266, now closed).

**Fix:** keep Claude Code up to date, and start parallel sessions a few seconds apart rather than all at once.

## A short checklist

Before you start N sessions in N worktrees:

1. Split the work so no two sessions own the same files or the same hot spot (route table, schema, lockfile).
2. Write the shared decisions into `CLAUDE.md` first.
3. Give each worktree its own port and database.
4. Check branches against each other with `git merge-tree` while they run.
5. Land one at a time: rebase, run the full tests on the result, merge.

## Where Cork fits

Cork covers 1 to 4 on this list, while the agents work, not at merge time:
- Its hooks report every write as it happens, so an agent hears about another agent's change on its next step.
- The [write gate](https://corkcli.com/blog/write-gate) holds an edit against code another agent is changing right now.
- A rename or signature change becomes a [semantic lint](https://corkcli.com/blog/semantic-lint) finding for the agents that use it.
- Each agent gets a briefing on the code it is about to touch, including what the others just changed.
- Notes anchored to code carry a decision to whichever agent touches that code next.

In the test run above, Cork flagged the overlap a minute in, and the sessions split the files between them. It works in one checkout or in many worktrees, across Claude Code, Codex and Cursor.

Cork doesn't help with 5 to 8. It doesn't isolate ports, databases or services, it doesn't make installs faster, and it doesn't change how git locks work. It does make a shared checkout workable when per-worktree setup is the problem.

## Sources

Checked 18 November 2026:

- Claude Code docs, "Run parallel sessions with worktrees": https://code.claude.com/docs/en/worktrees
- Claude Code docs, "Message your other Claude Code sessions": https://code.claude.com/docs/en/cross-session-messaging
- Scott Chacon, "[Git Worktrees](https://corkcli.com/blog/git-worktrees-parallel-ai-coding-agents) and GitButler", GitButler blog: https://blog.gitbutler.com/git-worktrees
- João Camarate, "Claude Code worktrees: parallel agents without the conflicts", dev.to: https://dev.to/jcamarate/claude-code-worktrees-parallel-agents-without-the-conflicts-3fnl
- Ken Imoto, "I Ran 3 Claude Code Sessions in Parallel for 8 Hours. They Overwrote Each Other's Context Twice.", dev.to: https://dev.to/kenimo49/i-ran-3-claude-code-sessions-in-parallel-for-8-hours-they-overwrote-each-others-context-twice-4bba
- Upsun, "Git worktrees for [parallel AI coding agents](https://corkcli.com/blog/parallel-ai-coding-agents)": https://developer.upsun.com/posts/ai/git-worktrees-for-parallel-ai-coding-agents
- Eric Allam, "We ditched worktrees for Claude Code. Here's what we use instead", Trigger.dev, 16 April 2026: https://trigger.dev/blog/parallel-agents-gitbutler
- anthropics/claude-code issue #47266: https://github.com/anthropics/claude-code/issues/47266

## Frequently asked questions

### Do worktrees stop parallel Claude Code agents from conflicting?

They stop them from overwriting each other's files while they work. They don't stop merge conflicts, clean merges that break the build, or two sessions making different decisions about the same code.

### How many Claude Code agents can I run in parallel with worktrees?

There is no fixed limit in Claude Code. The practical limits are setup cost, disk, ports and databases, and how many branches you can review and land. Past a few sessions, coordination between them becomes the bottleneck rather than the machine.

### Do worktree sessions share memory and CLAUDE.md?

They can. A worktree has its own copy of the repository's files, but user-level files such as `~/.claude/CLAUDE.md`, skills and the project memory directory are read by every session. Changes to them from one session reach the others.

### Is there a way to run parallel agents without worktrees?

Yes: one checkout with branches sorted at commit time (GitButler), subagents in one session, [Claude Code agent teams](https://corkcli.com/blog/cork-vs-claude-code-agent-teams), full clones, cloud sandboxes, or a shared checkout with a coordination layer. See [alternatives to git worktrees for Claude Code](https://corkcli.com/blog/git-worktrees-alternatives-claude-code).

## Related reading

- [Git worktree merge conflicts with AI agents: why worktrees don't stop them, and how to see them early](https://corkcli.com/blog/git-worktree-merge-conflicts-ai-agents): Git worktrees keep parallel AI coding agents out of each other's files, not out of each other's code. Why the merge conflicts still come, the ones git never reports, and a one-command check that finds them while the agents are still working.
- [Claude Code subagents vs parallel sessions: when to use which](https://corkcli.com/blog/claude-code-subagents-vs-parallel-sessions): Subagents or parallel Claude Code sessions? Compare context, control, file isolation and cost, with a decision checklist and setup for each, as of October 2026.
- [How to stop Claude Code agents from overwriting each other's changes](https://corkcli.com/blog/stop-claude-code-agents-overwriting-changes): Why parallel Claude Code agents overwrite each other's edits, and how to stop it with worktrees, file ownership, deny rules, PreToolUse hooks and a write gate.
- [Cork vs git worktrees: separate folders, or agents that know about each other](https://corkcli.com/blog/cork-vs-git-worktrees): Cork vs git worktrees for parallel AI coding agents: worktrees isolate files while agents work, Cork coordinates them so the work still fits at merge.

[All articles](https://corkcli.com/blog.md) · [Cork in Markdown](https://corkcli.com/index.md) · [llms.txt](https://corkcli.com/llms.txt)

This page in HTML: https://corkcli.com/blog/parallel-claude-code-agents-what-still-breaks
