# Run multiple AI coding agents without breaking your code

> A guide to running Claude Code, Cursor and Codex agents in parallel using git worktrees, and detecting the merge conflicts they create.

Published 2026-11-29.

The setup is becoming standard: open three terminals, start an agent in each one, give each a task. One refactors
authentication, another adds the billing page, a third writes tests. Each works in its own git worktree so their
files don't collide on disk.

This gets you three times the output — until two of them merge and something breaks that neither one broke alone.

**Key takeaways:**

- Git worktrees give each agent its own directory and branch, preventing disk-level file conflicts but not semantic ones.
- Git's merge is line-based: a renamed function in one branch and a call to it in another merge silently and break at runtime.
- Three strategies work: assign non-overlapping areas, run combined checks in CI, or detect conflicts while agents work.
- Lanekeeper detects conflicts in real time (under 100 ms) using deterministic rules, without sending code anywhere.
- Properties to look for: deterministic, fast, local, fail-open, and agent-neutral.

## The worktree pattern

Git worktrees let multiple branches exist as directories on the same machine, sharing one `.git` history. Every
major coding agent supports them: Claude Code creates them with `--worktree`, Cursor opens them as separate
windows, Codex works in whatever directory you point it at.

The basic setup:

```sh
git worktree add ../auth   feature/auth
git worktree add ../billing feature/billing
git worktree add ../tests  feature/tests
```

Each agent sees its own files, makes its own commits, and doesn't interfere with another agent's work-in-progress.
This is the right starting point. But it doesn't prevent the agents from making changes that conflict at a higher
level than lines of text.

## Where git stops helping

Git's merge algorithm compares lines. When two branches edit the same lines of the same file, git reports a
conflict. When they edit different files, or different parts of the same file, git merges them silently.

That silence is the problem. Consider:

- Agent A renames `processPayment()` to `createCharge()` in `billing.ts`
- Agent B writes new code in `reports.ts` that calls `processPayment()`

Git merges these without complaint. The function no longer exists, the call points at nothing, and the error shows
up on main after both branches have landed.

Other variants:

- Two agents both add database migration `0042`
- One agent changes a function's signature from two parameters to three; another adds a call with two
- Two agents modify the same function in different directions, and whichever merges second wins
- Both agents add the same dependency at different versions to the lockfile

CI doesn't catch these either, because CI tests each branch against the base independently. It never builds the
combination before one of them is on main.

## Three strategies that work

### 1. Assign non-overlapping areas

The simplest prevention: tell each agent which files and modules it owns. If the auth agent only touches `src/auth/`
and the billing agent only touches `src/billing/`, their changes can't conflict.

This works until it doesn't. Real codebases have shared code — utility functions, types, configuration, database
schemas — that multiple features need to change.

### 2. Run a combined check in CI

Instead of testing each PR alone, test pairs of open PRs together. For each pair, merge them into a temporary
branch, build, and run the test suite. If the combination fails but each PR passes alone, you've found a
cross-branch conflict.

This is what Lanekeeper's [GitHub Action](https://lanekeeper.dev/docs/github-action) does. It compares each pull request with every other
open one, confirms real conflicts with an in-memory merge, and when given build and test commands, builds the risky
pairs together. When a pair breaks, the Action comments on both PRs with the conflict and suggests which one to
merge first.

### 3. Detect conflicts while agents work

The strategies above catch problems at merge time or in CI. But the cheapest time to catch a conflict is while the
agent is still writing code — before the edit lands.

A local daemon can watch every worktree, parse each lane's changes into code-level facts (this function was renamed,
this call was added, this migration number is taken), and compare lanes in real time. When a conflict appears, the
agent hears about it immediately through a hook or an MCP tool call, and can adapt its approach.

This is what [Lanekeeper](https://lanekeeper.dev/docs/quick-start) does. It runs ten deterministic rules across every lane, covering
renamed-but-used symbols, signature changes, lockfile conflicts, overlapping migrations, environment variable
collisions, and more. The analysis runs locally, finishes in under 100 milliseconds, and never sends source code
anywhere.

## What to look for in a solution

Whether you use Lanekeeper or build your own coordination, the properties that matter:

- **Deterministic**: the same changes should always produce the same answer. AI-based detection
  introduces randomness that makes debugging impossible.
- **Fast**: if the check takes longer than the agent's edit, agents will ignore it or the hook will time out.
  Under 100 ms is the target for in-editor detection.
- **Local**: sending source code to a third party for conflict analysis defeats the security model of local agents.
- **Fail-open**: if the detector is down or slow, agents should keep working. A broken safety net is worse than
  no safety net if it blocks all work.
- **Agent-neutral**: the solution should work with any coding agent, not just one vendor's tool.

## Getting started

Install Lanekeeper and initialize it in a repository:

```sh
npm i -g lanekeeper
cd your-repo
lk init
```

Create worktrees, start your agents, and run `lk status` to see the lane map. When two lanes clash, every agent
in a clashing lane is told what happened and what to do about it.

The [quick start](https://lanekeeper.dev/docs/quick-start) covers the full setup in about two minutes. The
[rules reference](https://lanekeeper.dev/docs/rules) explains every kind of conflict Lanekeeper detects.

## Further reading

- [Your agents are breaking each other's code](https://lanekeeper.dev/blog/agents-breaking-each-others-code): why git and CI miss cross-agent conflicts.
- [Ten rules for catching agent conflicts](https://lanekeeper.dev/blog/ten-rules-for-catching-agent-conflicts): how each rule works and how they're measured.
- [Concepts](https://lanekeeper.dev/docs/concepts): lanes, clashes, claims and the merge plan.
- [Claude Code integration](https://lanekeeper.dev/docs/claude-code): warn mode, block mode and the plugin.
- [GitHub Action](https://lanekeeper.dev/docs/github-action): combined CI for conflicting pull requests.
