Guide

Run multiple AI coding agents on one repo without merge conflicts

Two agents editing the same file is the fastest way to lose an afternoon. Here is what actually keeps parallel agents apart, in the order it matters, and how Chain does each step for you.

Why parallel agents collide

One coding agent on a repo is fine. Two is where the trouble starts. They each read the same files, each decide the same helper needs a tweak, and each write it. Git only sees the damage at merge time, and only when the edits land on the same lines. When they land on different lines of the same function, the merge is clean and the code is broken.

Add teammates and it gets worse. Your agent and your colleague’s agent are on different laptops with no view of each other at all. The only coordination is whoever pushes first.

1. Give every agent its own worktree

The first fix is isolation. A git worktree is a second checkout of the same repository in its own folder, on its own branch. Give each agent one and they stop overwriting each other’s files on disk. Most tools that run agents in parallel, including Chain, start here.

$ git worktree add ../repo-reset-flow -b max/reset-flow
$ cd ../repo-reset-flow && claude

Worktrees only move the problem, though. The agents still touch the same files, just on different branches, and you still find out at merge time.

2. Claim paths before editing

The second fix is a shared board. Before an agent edits, it claims the paths it is about to change, like auth/* or email.ts, for a named task. Other agents read the board first. If a path is already held, they work on something else or queue behind it.

In Chain every co-work has one board of tasks, claims and a log, and it is the same board on every teammate’s Mac. Agents call board, claim, release and log as ordinary tools.

3. Enforce claims with a hook, not a prompt

Telling an agent “don’t touch files someone else is editing” in a rules file works most of the time. Most of the time is not enough on a shared repo. Claude Code, Codex and Cursor all expose a hook that runs before a tool call. Chain installs a pre-tool hook that refuses writes to claimed or blocked paths and tells the agent who holds the path and why. The agent gets a clear error instead of a silent overwrite.

4. Merge one branch at a time, and stop on real conflicts

When an agent finishes, something has to test its branch, merge it, and release its claims. Chain does this when the agent calls done: it runs your test command in the worktree, merges to the default branch if the tests pass and there is no conflict, pushes, and releases the claims. If two branches did touch the same lines, the merge pauses and shows both sides for a person to decide. Nothing moves until then.

5. Keep the agents where they already run

The last piece is not technical. Teammates should not need your API keys, and your code should not need to pass through a third party to be coordinated. Chain runs on each person’s Mac with their own agent and keys. The relay only carries the board. Code moves between Macs through your own GitHub or git remote.

Doing it with Chain

Open Chain, press New co-work on a repo, share the code with your team. Each person presses Open AI or runs chain open claude, and gets an agent in a fresh worktree with the board tools and the hook already wired in. The getting started guide walks through it in about five minutes.