Skip to content
86% off$349 $48.86code BF2026

Guides

Stop AI Coding Agents Overwriting Each Other in One Repo

Two AI coding agents overwriting each other in one repo? Give each its own git worktree and branch, check freshness, review the diff, then merge.

GuideUpdated 8 min read

On this page

You have two agents (or one agent resumed from last week) working in the same repo folder. Files change under you, one agent's fix disappears, and nobody can say which agent touched what. Reports describe exactly this: a stale session overwriting newer workspace contents across several files, with no conflict warning.

Why agents overwrite each other

The causes, most common first:

  1. Two agents share one working folder. An agent edits by writing files. Whoever writes last wins. Git is not involved yet, so there is no merge and no conflict marker.
  2. A resumed session works from an old picture of your files. Its context still holds the version it read earlier. If it rewrites a whole file from that memory, it replaces the newer content.
  3. Your own edits are in the same folder. If you edit in the checkout an agent is using, your uncommitted changes can be overwritten as well. Git can only restore what was committed or stashed.
  4. Competing edits to the same lines. Even with isolation, two agents given the same bug will produce changes that collide. With separate branches this shows up as a normal merge conflict, which is better than a silent loss.

A worktree is a separate working directory for the same repository. Worktrees let you work on multiple branches at the same time without stashing changes or cloning the repository again. Vendors recommend the same pattern. Anthropic's support article on Claude Code tips says the biggest productivity unlock is running 3–5 Claude sessions in parallel, each in its own git worktree. OpenAI's help page on using Codex in the terminal also lists keeping work for separate tasks in separate Git worktrees.

Fix 1: one git worktree per agent

You don't need an app for this. Git ships with git worktree.

  1. In your main checkout, commit or stash your own work first.

  2. Create one worktree and one new branch per agent:

    bash
    git worktree add -b agent/fix-login ../myapp-fix-login main

    This creates the folder ../myapp-fix-login with a new branch agent/fix-login started from main. Repeat with a different branch and folder for each agent.

  3. Open a terminal in each folder and start one agent per terminal:

    bash
    cd ../myapp-fix-login
  4. When an agent finishes, look at its work from your main checkout:

    bash
    git log --oneline main..agent/fix-login
    git diff main...agent/fix-login

    With one branch per agent, the branch name answers "which agent changed what".

  5. With main checked out in your main checkout, merge the branches you want:

    bash
    git merge --no-ff agent/fix-login
  6. Clean up. The first command removes the worktree folder, the second deletes the branch (and refuses if it isn't merged):

    bash
    git worktree remove ../myapp-fix-login
    git branch -d agent/fix-login

Git also refuses to check out the same branch in two worktrees at once, which works as a guardrail.

What a new worktree is missing

A worktree contains only tracked files. Anything git ignores is absent, such as .env files and node_modules, so the agent may fail on its first test run. Install dependencies and copy the env file into each worktree. Two dev servers will also fight over one port, so give each worktree its own.

Split the work by area

Worktrees stop silent overwrites. They don't stop competing changes to the same lines. Give agents different areas (one on the API, one on tests) rather than the same bug, unless you are deliberately comparing approaches.

Fix 2: check freshness before a session writes anything

This is the check people asked for after a stale session overwrote newer files. Do it before resuming any old session:

  1. In the folder it will work in, run git status and git diff and read what changed since the session last ran.
  2. Commit or stash your own changes.
  3. Tell the agent to re-read first, for example: "Before changing anything, run git status and git diff, and re-read every file you plan to edit."
  4. Resume it in its own worktree, not in the checkout you are working in.

Agents have their own resume commands, such as claude --resume <id> and codex resume <id>. Treat a resumed session as one that may hold an outdated view of your files, whichever tool you use. A separate worktree limits the damage to that branch, and the diff review catches the rest.

Fix 3: do it automatically in Sledbot

Sledbot runs several CLI coding agents in real terminals. When you start an agent from New task in a git repository, it gets its own worktree by default.

  1. Add your project with File ▸ Add Project Folder… (⌘O), or drag the folder onto the sidebar. It becomes a space.
  2. Press ⌘T to open New task and describe the task.
  3. Check that Work in a new worktree is on. It is on by default for git repos. The branch field shows agent/…, and "from <base>" sets the base branch.
  4. Choose the agent, then press ⌘↩ or the ↑ button.

The worktree lives at <repo>/.sledbot/worktrees/<branch>, with any / in the branch name replaced by -. Sledbot adds .sledbot/ to .git/info/exclude, so it stays out of git, and your own files stay as they are. Repeat for each agent. Each gets its own tab, and anything waiting for you shows under Needs you.

Run one task with several agents

To compare approaches, use Agents ▸ Compare Agents… (or ⌘K, "Compare agents…"). It runs the same task with 2 to 4 agents, each in its own worktree on a branch named compare/<slug>-<agent>-<n>, side by side in one tab. It needs a git repository.

Review per hunk, then merge

Open Review changes from the agent's header or inspector to compare its branch with its base.

  1. For each hunk choose Accept, Reject or Comment. Accept stages the hunk, Reject restores the original, and Comment sends the file, line and your note to the agent's terminal.
  2. Once every hunk is reviewed, Merge and Open PR become available.
  3. Merge asks you to confirm, commits any uncommitted changes in the agent's worktree, then runs git merge --no-ff --no-edit in your main checkout. That checkout must be on the base branch.
  4. Open PR pushes the branch and runs gh pr create --fill. It needs the GitHub CLI (gh).

Setup scripts and ports

Sledbot reads per-repo scripts from .sledbot/config.json (or sled.json) at the repo root:

json
{"setup": ["npm ci"], "copy": [".env"], "run": "npm run dev -- --port $SLED_PORT", "archive": "docker compose down"}

Worktree terminals get their own SLED_PORT (plus SLED_PORT_1 to SLED_PORT_9), SLED_WORKTREE, SLED_ROOT and SLED_BRANCH. Using $SLED_PORT in your dev-server command keeps two servers from colliding. The same scripts can be driven with sled worktree info|create|setup|run|archive.

Recover from a bad turn

At the end of each agent turn in a git work tree, Sled Core snapshots the working tree into private git refs without touching your index or HEAD, and keeps the last 50. There is no screen for this in the app. Use sled checkpoint ls|diff|restore|create in a terminal. A restore takes a safety checkpoint first.

Which approach to pick

ApproachStops silent overwritesSetupBest for
Plain git worktreeYesA command per agent, plus env files and ports2 or 3 agents, no new tools
Separate clonesYesFull copy per agent, more diskIf you'd rather not use worktrees
Sledbot New taskYes, for agents it startsAutomatic, optional setup scriptsMany agents, per-hunk review
Shared folder, careful promptingNoNoneOne agent at a time only

Plain git is enough for a couple of agents if you are comfortable with the commands. Sledbot pays off when you run many at once, want per-hunk review before merging, or run agents on remote machines too.

If agents still overwrite each other in Sledbot

Sledbot does not stop two agents from sharing one worktree. These are the usual ways that happens:

CauseWhat you seeFix
Worktree switch is offAgents edit the space folder directlyTurn on Work in a new worktree in New task
Teammate set to Shared or None (work in the space)Threads share a folderIn the teammate editor, set Worktrees to One per thread (the default)
Folder isn't a git repo"<space> isn't a git repository, so agents can't get separate worktrees."Run git init and make a first commit, then start again
Agent started by hand or with ShellIt works in whatever folder you openedStart it from New task instead
Main checkout isn't on the base branch"Merge failed: The main checkout is on X, not <base>."Check out the base branch, then merge

Other things to know:

  • A merge conflict appears. Two branches changed the same lines. Open the space in Code mode and use Source Control: Use Current (HEAD)…, Use Incoming…, Mark as Resolved.
  • Worktrees pile up. Use Clean up worktrees… from the space's context menu, or Insights ▸ Cleanup. Closing a running agent stops it but keeps its worktree and files.

Checklist before you start several agents

  • Your own work is committed or stashed.
  • Each agent has its own branch and worktree folder.
  • Each worktree has its dependencies and env file.
  • Each dev server uses a different port.
  • Agents have different areas, unless you are comparing approaches.
  • Any resumed session has re-read git status and git diff.

If nothing works

If agents still write over each other in Sledbot, contact support at macsuite.app/support. Include the exact message you saw, the path of the folder each agent ran in (shown in the agent's details rail), the output of git worktree list, and whether Work in a new worktree was on.

text
Subject: Two agents wrote to the same folder in Sledbot

Sledbot version: (Help or About window)
macOS version:
Project is a git repo: yes/no
Agents involved:
"Work in a new worktree" was: on/off
Output of `git worktree list`:
What I expected vs what happened:
Steps I already tried:

For a problem in a different tool, use that vendor's support channel and include the same details.

Sledbot is part of MacSuite and needs macOS 14 or later. You can try it free for 7 days. After the trial, starting or restarting agents needs a license. See starting agents and reviewing an agent's changes for the full options, and Claude Code worktrees if you use Claude Code.

Common questions

Can two agents work on the same branch?

Not in separate git worktrees, because git refuses to check out one branch twice. Give each agent its own branch and merge them afterwards.

Do worktrees prevent merge conflicts?

No. They turn a silent overwrite into a visible merge conflict. Splitting the work by area reduces how many you get.

Does this work with any agent?

Worktrees are plain git, so they work with any agent that runs in a terminal. Some agents also have a built-in switch: Anthropic's article mentions claude --worktree for Claude Code. In Sledbot, New task works with the CLI agents it detects, such as Claude Code, Codex CLI, Gemini CLI, GitHub Copilot CLI and Cursor CLI.

Will an agent still overwrite my main checkout?

Not if it runs in its own worktree, because it only writes to files on its own branch. Your main checkout changes only when you merge.

Every app.
One purchase.