Merge Conflict Prevention When Multiple Agents Edit the Same Repo
Partition work by domain and share context files before agents start coding.

Merge conflicts in multi-agent repos are the predictable output of how parallel agents are built to work, and preventing them requires designing the work partition, the environment, and the merge sequence before any agent writes a line of code.
Why multi-agent repos produce merge conflicts
When several agents work on the same repository at once, conflicts are close to guaranteed by the architecture itself, not a sign that an agent made a mistake. The standard setup gives each agent its own git worktree so the agents cannot step on each other while they are actively working. That isolation buys safety during the run, but the bill comes due at merge time: if two agents touch the same file, or if they make incompatible decisions about a shared interface, the merge breaks in ways that neither branch shows on its own. A branch can pass every test in isolation and still be wrong the moment it sits next to another branch making a different assumption about the same piece of code.
This is not a rare edge case. Some platforms run multiple agent types in isolated environments, each with its own repository clone, which makes this architectural problem concrete: when agents from different coding harnesses operate on the same repository in parallel, the merge conflict becomes a predictable feature of the infrastructure, not a bug.
What conflicts: the three types of collision agents produce
Agent-generated conflicts split into three distinct kinds, and lumping them together is a large part of why reactive fixes keep falling short. Content conflicts happen when two agents edit overlapping lines in the same file. Add/add conflicts happen when two agents independently create files at the same path with different contents, usually because neither agent had any way of knowing what the other had already built.
The same research identifies three layers that stack on top of each other: textual conflicts, which git flags directly; build conflicts, where the merge goes through cleanly but the result fails to compile or lint; and semantic conflicts, where the code builds, the tests pass, and the combined logic is still wrong once it runs. Reactive conflict resolution cannot handle all three at once. Multi-agent platforms need conflict prevention built into work assignment and environment setup from the start.

Why worktree isolation is necessary but not sufficient
Worktree isolation stops the worst failure mode: two agents overwriting each other's in-progress edits in a shared directory. But it does nothing to stop conflicts that come from both branches touching the same files or landing on incompatible design decisions. Each agent gets its own directory, its own branch, its own index, and its own working file state, all drawing on the same repository's object store underneath. That separates the agents physically while they work, but their branches still have to come back together eventually, and isolation says nothing about what happens then.
Worktrees prevent a specific set of problems well: file collisions where a last write erases earlier edits, branch confusion where one agent switching branches changes the filesystem state out from under another, contamination where an agent reads another agent's uncommitted partial work, and lock conflicts from shared tooling. Git even enforces this at the branch level: two worktrees cannot check out the same branch at the same time, and trying throws a fatal error that the branch is already checked out. The gap is structural, built into how isolation works, and no amount of per-agent sandboxing closes it on its own.
The standard setup, one worktree per agent, each on its own branch, all cut from the same base, is the right starting point. It is only a starting point. Parallel speed only exists when the file scopes assigned to each agent are genuinely separate. Two agents working on overlapping files are not running in parallel at all; they are running a race condition that happens to look like parallel work until the merge.
Task decomposition as the first line of prevention: partitioning work before agents start
Most agent merge conflicts trace back to a decomposition problem, not a git configuration problem. Agents given overlapping domains will conflict no matter how well their environments are isolated from each other. The fix starts with assigning work by domain rather than by file: each agent owns a named concern, authentication, billing, the API layer, and the set of files it touches follows from that ownership.
That means writing an ownership manifest before any agent starts, mapping each agent to the paths it alone may write and a separate read-only set of shared interfaces it can see but not change. The manifest gets handed to each worker as part of its prompt, functioning as a contract. When a file truly needs to be touched by more than one agent, the right answer is to serialize those tasks, run them one after another and treat the file as a dependency boundary, not to force parallel work onto something that cannot support it. This decomposition work has to happen before launch, as a planning artifact, not something adjusted on the fly once agents are already running.
Some codebases make this harder than others. Task decomposition in those repos has to account for architectural hotspots directly, not just the usual feature boundaries a team might draw on a simpler project.
Shared context files as an architectural coordination layer
Even agents working on entirely separate files can still produce code that does not fit together if they make different assumptions about shared interfaces, naming, or architectural patterns, and the gap between cross-agent and same-agent conflict rates is a direct reflection of that problem.
Claude Code reads a CLAUDE.md file at the start of every session, holding bash commands, code style rules, workflow conventions, and architectural decisions specific to the project. For parallel agent work, the prescription is to keep that shared file consistent so every agent working at the same time makes the same choices. The same idea holds across other harnesses: Cursor rules files, Architecture Decision Records, and instruction files such as MEMORY.md all act as explicit, written constraints that every agent sees at the start of every session, regardless of whatever has built up in that agent's own episodic memory over time.
A known failure mode here is context poisoning: once incorrect information gets into an agent's episodic memory, it keeps reproducing at every step that follows. For tasks that stretch across session boundaries, this file is also the continuity mechanism: when an agent picks a task back up hours or days later, the instruction file is what keeps it lined up with decisions made in earlier sessions. These files should be maintained by the team as architecture artifacts in their own right, not generated by the agents themselves, since their value comes from being a fixed coordination layer that every parallel agent reads the same way.
Pre-write admission control: preventing conflicts before code is written
Task decomposition and shared context cut conflict risk substantially, but they cannot eliminate conflicts entirely when agent tasks genuinely depend on each other. A pre-write admission layer catches what is left over: it evaluates write intents before any code gets produced.
The ATM paper (arXiv:2607.00041) proposes a seven-layer hard admission gate that checks multi-agent write intents through CID identity, shared-surface overlap, read/write dependencies, file-range and virtual-atom refinement, ConflictKey and canMerge evaluation, CAS base-hash validation, and a fallback file lock. The point of the design is to stop merge conflicts before changes exist at all, rather than repair them once they have already landed. A related system showed that explicit file-claim coordination on a shared, conflict-aware workspace cuts agent abandonment by an order of magnitude and improves coding quality over solo and parallel baselines at matched compute, evidence that the coordination overhead pays for itself.
These systems represent where rigorous multi-agent infrastructure research is heading rather than something a team can install today as a finished product. The underlying idea still matters: an orchestrator that receives write intents from agents before execution can catch overlapping claims and either serialize the conflicting tasks or reject the lower-priority one, turning what would have been a merge-time failure into a scheduling decision made in advance. This layer complements decomposition. Decomposition shrinks the surface area that needs checking in the first place; admission control catches what decomposition cannot anticipate.
Merge sequencing and the rebase-before-PR gate
Once agents have already produced branches, the order in which those branches merge matters as much as how the work was divided up front. Merging sequentially through a single review gate, with each branch rebased against the current main before it gets submitted, keeps the kind of compounding drift that makes multi-agent merges expensive from building up.
The rebase-before-PR pattern works by detecting upstream drift against origin/main, running git fetch origin main followed by git rebase origin/main inside the agent's worktree, parsing any conflict markers and resolving the non-overlapping additions automatically, then pushing with git push --force-with-lease. The agent-manager project built exactly this as a working system: issue #96, merged through PR #115 on October 6, 2026, implements a rebase supervisor as a concrete automated workflow. The project holds the supervisor itself to under 250 lines of code, an anti-monolith constraint meant to keep the tool that manages conflicts from becoming a conflict-prone maintenance burden in its own right.
A single review gate, never straight to main, guarantees that every branch arrives as a clean, reviewable diff before it can affect shared history. For conflicts that make it past the automated resolver, the right move is a safe abort and a human alert, not an attempt to automate a resolution of something semantic, which calls for judgment the system does not have.
How sandboxed cloud environments change the conflict picture
The environment an agent runs in matters as much as how the work was split up. An agent that can install its own dependencies, run services, drive a browser, and check its own work against real tests is far more likely to produce a branch that passes CI cleanly than one running in an environment that was not properly configured for the task. Shared environments reintroduce exactly the interference that worktrees exist to prevent: if agents share a filesystem, a database, or a dependency cache, isolating them at the git layer does nothing to stop runtime collisions between them.
The right unit of isolation for a cloud coding agent is a fully configured Linux VM per run, with its own repository checkout, its own dependency state, and its own services, so the agent can check its work against a real environment before the branch ever reaches review. Replicas runs each agent in its own isolated VM configured with the team's environment, letting agents install dependencies and tooling, run services, and verify their own work before submission. The harness-agnostic design matters here too: when Claude Code, Codex, Cursor, and Opencode all run on the same environment primitives, a team can assign the right agent to each slice of work without the environment itself turning into a variable that causes inconsistent behavior between agents.
Run-level analytics, attribution down to source, person, harness, model, credential, and which skills and MCP servers an agent reached for during each minute it ran, give teams the data to see which agent assignments and task partitions actually produce the cleanest merges. That turns conflict prevention from a one-time setup choice into something a team can measure and improve over successive runs.
Building the prevention workflow end-to-end: what to do before, during, and after agent runs

Preventing merge conflicts across a multi-agent repo comes down to a clear sequence: partition the work before agents start, keep architectural context aligned across every agent, isolate each agent's environment, gate the merge through a rebase supervisor, and measure what actually lands in main. Before any agent starts, a team should find the architectural hotspots, the files with unusually high co-activity, and treat them as serialization boundaries, not as opportunities for parallel work. That planning stage also calls for an explicit ownership manifest that assigns each agent a named domain, a list of paths it alone may write, and a read-only set of shared interfaces, and for the shared context file, whether that is CLAUDE.md, Cursor rules, or a set of ADRs, to reflect the team's current architectural decisions so that agents working in parallel land on the same choices independently. The last piece of preparation is mechanical: one git worktree per agent, each on its own branch, all built from the same up-to-date base.
While agents are running, each one should work inside a fully isolated environment with its own dependencies and services, so it can verify its own changes before anything gets submitted for review. Teams should also watch for scope creep across agents during the run itself: if one agent's work starts expanding into territory assigned to another, the right response is to pause and repartition the work before the overlap accumulates.
At merge time, the rebase supervisor should run before any PR goes up, detecting upstream drift, rebasing against main, resolving additive and non-overlapping conflicts automatically, and aborting safely with a human alert the moment a conflict looks semantic. A failed merge is a signal about how the original task partition was drawn. Feed that signal back into the ownership manifest for the next round of work.
Conflict prevention, built this way, becomes a system a team can actually improve over time rather than a fixed set of rules applied once and left alone.
Sources
- [GIT]: Autonomous Multi-Agent Worktree Rebase & Merge Conflict Resolver · Issue #96 · BowenMichael/agent-manager
- AgenticFlict: A Large-Scale Dataset of Merge Conflicts in AI Coding Agent Pull Requests on GitHub
- ATM: CID-Brokered Pre-Write Admission for Multi-Agent Code Co-Synthesis
- CooperBench: Why Coding Agents Cannot be Your Teammates Yet
- AI Agent Pull Requests on GitHub: Frequency, Structure, and Merge Conflict Rates


