Skip to main content

Stop Two Coding Agents From Overwriting Each Other

Give each agent its own working directory. Two agents in one checkout share every file, every build and every test run.

The Fix​

Create one worktree per agent and start each agent inside its own directory:

git worktree add -b agent/api ../repo-api main
git worktree add -b agent/ui ../repo-ui main
cd ../repo-api && claude

Why It Happens​

An agent edits files and runs commands in the directory it starts in. Two agents in the same directory see each other's half-finished edits, and one agent's failing build becomes the other agent's problem. git status shows changes from both, so neither can commit only its own work. Separate branches in the same directory do not help, because switching branches changes the files under the other agent.

How Treq Handles It​

Treq creates a separate workspace per task and starts the agent inside it. Any supported agent works, and different workspaces can run different agents.