Multiple AI Agents Created Conflicts

Two agents (Cursor + Claude Code) edited the same file. Merge cleanly, don't panic.

You ask Cursor to edit Header.tsx while a Claude Code session in a separate terminal is editing the same file; or you have Cursor’s Composer background mode plus the main chat running together; or two teammates fire up agents on the same code. The result: files clobbered, git status showing half-baked content that’s neither yours nor either agent’s complete intent. Cursor, Claude Code, and Aider don’t share file locks — each one reads, thinks, and writes against the snapshot it saw, and the last write wins. This article gives the fixed flow: stop everything → recover both intents → manually merge → prevent recurrence.

Common causes

Ordered by hit rate, highest first.

1. Two agents on the same workspace at once

The classic case: Cursor’s Chat / Composer plus Claude Code CLI in the same directory. Both “read → think → write” without coordinating.

How to spot it: git status shows a file that isn’t what you just typed and isn’t a clean output from either agent; the file mixes two different naming styles or comment voices.

2. Cursor background agent + foreground chat together

Cursor’s Background Agent runs a task while you edit the same file in the foreground. When the background task finishes, the disk has moved on, but its patch was built against the older version — apply fails or produces misaligned hunks.

How to spot it: Cursor reports “patch could not be applied cleanly” or “file has been modified externally.”

3. Multiple humans, each running their own agent on the same repo

Two devs on separate branches both use agents on the same module. At merge time the conflict markers look like two “AI styles” arguing.

How to spot it: git merge conflicts where neither side reads like a human wrote it, but each is “plausible yet structurally incompatible.”

4. Watch / autopilot triggers silent writes

Some agents (Cursor’s Auto Apply, Aider’s --auto-commits) write to disk without an explicit confirmation. You’re editing Header.tsx, the agent quietly edits it too, the IDE asks “file modified externally, reload?”

How to spot it: IDE prompts a “reload from disk” dialog for a file you didn’t touch in another window.

5. Different-model “style conflict”

GPT leans functional, Claude leans imperative-and-chunked. Two agents working the same module pull the refactor in opposite directions. Even without raw conflicts, the merged code is a “two-philosophies stitched together” mess.

How to spot it: git log -p on the two commits shows one converting if/else to switch, the other converting the same switch back to ternary.

Shortest path to fix

Step 1: Stop everything

Kill every running agent — quit Cursor (or at least close Composer / Background Agent), terminate the Claude Code CLI, kill autopilot / watch processes. Continuing to type only stacks more race conditions on top.

# Find suspect agent processes
ps aux | grep -E '(cursor|claude|aider|cline)' | grep -v grep

# Kill if needed
pkill -f "claude-code"
pkill -f "aider"

Wait until disk state stays still for 30 seconds before the next step.

Step 2: Snapshot everything, then read git status

So the merge below doesn’t lose anything else:

git stash push -u -m "multi-agent-mess-$(date +%s)"
# or
git branch backup/conflict-snapshot-$(date +%s)
git stash pop  # restore changes to working tree

Then see who touched what:

git status
git diff
git log --all --oneline -10

Step 3: Extract each agent’s “intent version” as a full file

Pull both sides into separate files for clean comparison:

# Assume Cursor already committed
git show <cursor-commit-sha>:src/Header.tsx > /tmp/cursor-version.tsx

# Claude Code's edits are still in the working tree
cp src/Header.tsx /tmp/claude-version.tsx

# Get the original (pre-agent) version
git show HEAD~2:src/Header.tsx > /tmp/original.tsx

Open all three in a 3-way diff:

code --diff /tmp/cursor-version.tsx /tmp/claude-version.tsx
# or
diff3 /tmp/cursor-version.tsx /tmp/original.tsx /tmp/claude-version.tsx

Step 4: Pick a source of truth, port the other side hunk-by-hunk

Choose the version with the clearer, broader intent as the base, then overlay the other side’s useful hunks:

# Write the base back to the working tree
cp /tmp/cursor-version.tsx src/Header.tsx

# Use add -p to interactively pick Claude's hunks
git diff --no-index src/Header.tsx /tmp/claude-version.tsx | less
# Manually copy the hunks you want into src/Header.tsx

More visually, use Cursor / VS Code’s “Source Control” panel: click ”+” on each hunk to stage what you want, skip conflict artifacts. When both sides touched the same line, the base version wins — don’t try to “blend” them. Blending introduces behavior neither side ever tested.

Step 5: Land it with a precise commit message

git add src/Header.tsx
git commit -m "merge: resolve cursor+claude divergence on Header.tsx

- kept cursor's restructuring of nav menu
- ported claude's a11y label fixes (lines 42-58)
- discarded both agents' duplicate handleClick implementations
- next: single agent per overlap file"

Spell out what stayed, what was dropped, and why. The next time something breaks, git log answers it directly.

Step 6: Enforce “one agent per overlap” going forward

Only one agent on a given file at a time. The simplest enforcement:

# Tool A: you, foreground Cursor — owns src/components/
# Tool B: Claude Code, background — owns scripts/, tests/, docs/

# Write it down in CLAUDE.md
echo "Owned by Cursor: src/components/, src/pages/" >> CLAUDE.md
echo "Owned by Claude Code: scripts/, tests/, docs/" >> CLAUDE.md

Or temporarily hide the other agent’s directories from Cursor via .cursorignore.

Prevention

  • One coding agent per workspace at a time; parallel agents are only OK in separate directories or git worktrees
  • Use git worktree to give each agent its own tree: git worktree add ../proj-claude feature-claude — fully isolated
  • Document directory ownership in CLAUDE.md / .cursorrules / AGENTS.md, e.g. src/api/ is Cursor’s, scripts/ is Claude Code’s
  • Commit immediately when an agent finishes a task before switching to the next agent; the commit is the handoff signal
  • Turn off features that allow silent writes: Cursor’s Auto Apply, Aider’s --auto-commits — require manual confirm
  • In team PRs, note which files were touched by which agent so reviewers and future merges know

Tags: #AI coding #Debug #Troubleshooting