Agent Tile BlogRunning a fleet of AI coding agents, well.

When Two AI Coding Agents Edit the Same File

· Claude Code, Git, parallel development

Two Claude Code sessions are making progress. One updates a component while another adjusts its validation logic. Then a change disappears, a test breaks, or the diff contains code neither session intended to produce.

The problem is shared mutable files. Before asking either agent to repair the damage, stop both from writing.

Why collisions happen

Sessions running in the same working directory share the same files and Git index. Separate terminal windows do not provide isolation.

An agent can read a file, plan an edit, and attempt to apply it after another session has changed that file. Depending on the editing operation, the result might be a rejected patch, overwritten content, or a syntactically valid combination with incorrect behavior.

Git does not necessarily display conflict markers here. Those markers usually appear during operations such as merging; concurrent edits in one working tree can produce an ordinary diff. Agents can also interfere through shared staging, branch changes, formatting, generated files, and dependency updates.

Preventing collisions before they happen

  1. Assign file ownership before starting. Give each session an explicit boundary: “Edit files under src/search/; do not change shared configuration.” Name one owner for files that cross task boundaries. If another session needs a change there, have it describe the required interface and wait for the owner.

  2. Use a separate worktree for each independent task. Each session gets its own working directory and branch. For example, run git worktree add ../repo-search -b task/search from your repository, then start the session inside that directory. This isolates working files and staging, although integration can still reveal conflicts. See the Git worktree workflow for the broader setup.

  3. Keep shared changes under one owner. Dependency manifests, lockfiles, central exports, and repository configuration attract unrelated edits. Designate one session to make those changes after the others report their needs. Avoid overlapping repository-wide formatters while other agents are editing.

  4. Establish a checkpoint before parallel work. Start from a reviewed commit where practical. If unfinished work must remain, preserve it separately and record what belongs to it. Ask sessions to produce small, focused commits in their own worktrees so you can inspect and integrate changes individually.

  5. Integrate sequentially. Review and merge one task before bringing in the next. Run the relevant checks after each integration. Isolation prevents agents from overwriting the same working files; it does not guarantee that their assumptions or interfaces agree.

What to do after a collision

First, pause every session that can write to the affected directory. Stop relevant watchers or formatters too. Tell each agent to report its intended changes without editing anything further.

Next, preserve the current state. Inspect git status, git diff, and git diff --cached. Save both diffs outside the working tree, and separately copy affected files, including untracked files. Patch files alone do not capture untracked content. Avoid reset, restore, or checkout commands until you have a recoverable copy.

Compare the saved state with the last known good commit and each session’s explanation. A diff shows what survived, not necessarily everything that was attempted. Reconstruct missing intent from available session history or earlier commits.

Choose one owner to reconcile the file. Give that session the intended behaviors, preserved changes, and explicit permission boundaries. Review the resulting diff yourself, then run focused tests and any broader checks affected by shared interfaces. Resume parallel work only after assigning separate ownership or worktrees.

Most of this discipline is bookkeeping: knowing which session owns which folder, and being able to see it at a glance instead of reconstructing it from scrollback. Naming carries a lot of that load — see session naming conventions. It is also why we built Agent Tile, a one-time $10 macOS app that tiles each Claude Code session with its project and folder visible at once and relaunches each one with --resume in its original directory. It will not reconcile a collision for you — but it makes the ownership you assigned visible, which is what keeps most collisions from starting.

Takeaway

Treat concurrent agents as concurrent developers sharing a filesystem. Give them explicit ownership, isolate independent tasks with worktrees, and integrate changes one at a time. When a collision happens, pause writes, preserve evidence, and let one owner reconcile the intended behavior before work resumes.

Agent Tile
Practical guides for running many Claude Code sessions in parallel on macOS — orchestration, review workflows, and staying sane with a fleet of AI coding agents.
Get Agent Tile — full source, $10 once →
Also from TechAthletes
  • IT-QA — Technical Q&A with AI-assisted answers and point bounties — for the questions that come up while you're running a fleet.