Running several AI coding agents on one repo without collisions

By Shamaz Khan · 18 Nov 2026 · 6 min read

TL;DR

One agent is adding an export. Another is refactoring auth. A teammate is fixing a bug in billing. All three touch a shared utilities folder, and the third PR quietly undoes part of the first.

Where parallel agents go wrong

A setup that keeps them apart

1. One branch (or worktree) per agent

git worktree add ../app-export -b feat/export
git worktree add ../app-auth   -b refactor/auth

2. One scope per task, with no overlap

# in ../app-export
stet scope set "Add CSV export" --allow "src/export/**,tests/export/**"
# in ../app-auth
stet scope set "Refactor session handling" --allow "src/auth/**,tests/auth/**"

If a task genuinely needs a shared file, widen that one scope on purpose rather than letting both agents edit it:

stet scope add "src/lib/dates.ts"

3. Start from, and compare with, the up-to-date main

Stet fetches origin/main and warns when a branch is behind it, so an agent doesn't build on a stale base. Pull before starting:

git pull --rebase origin main

4. Check every PR against its own task

stet ci     # once per repo: guard, check and PR format on every pull request

Each PR is judged against its own scope, so out-of-task edits show up on the right PR, and the locked behaviours run before anything merges.

FAQ

Can I run multiple Claude Code agents on the same repository?

Yes. Give each its own branch or git worktree, a non-overlapping task scope, and check each pull request against its own scope before merging.

How do I stop AI agents from overwriting each other's changes?

Avoid overlapping scopes, keep branches up to date with main, and run a check on every PR that flags files outside its task.

Should agents share one branch?

No. Separate branches or worktrees keep each agent's diff reviewable and make conflicts visible instead of silent.

Put guardrails on your AI coding agent

Stet is a free, open-source CLI and MCP server for Claude Code, Cursor, Codex and Copilot. It runs locally: no account, your code never leaves your machine.

npx stet-cli init · Install · Setup guide · GitHub

Related