Back to news

How to run multiple AI agents without overwriting each other

Short answer: give each AI agent its own copy of the project, on a separate branch, using git worktree. Without that isolation, two agents editing the same file overwrite each other with no error on screen, and the lost work only surfaces when a passing test starts failing.

Running two AI agents at once on the same project looks like a matter of opening two terminals. It works for about twenty minutes. Then one of them rewrites a file the other had just changed, and the lost work shows up nowhere.

That is what makes the failure expensive: it is silent. No error message, no conflict, no alert. The file simply goes back to what it was. You find out half an hour later, when a passing test starts failing, and you spend another half hour hunting a bug that never existed.

Why two AI agents overwrite each other

An AI coding agent does not work in transactions. It reads a file, thinks, and writes the whole file back with its own version. If two agents read the same version and wrote at different moments, the second one erases the first without ever knowing the first existed.

Neither agent did anything wrong. Both did exactly what they were asked. The problem is that they were standing on the same ground.

How to isolate each AI agent in the same repository

Every serious tool in this category solves it the same way, and it is worth understanding why: each agent gets its own copy of the project, on its own line of work. Git has a name for this, a worktree, and it is a real copy of the code on disk, tied to the same repository and to a separate branch.

In practice agent A and agent B never write to the same file, because there is no same file. There are two. And when both finish, you decide what goes in, with Git showing the difference side by side. That is exactly when a collision should surface: at merge time, in full view, instead of mid-work and hidden.

How CanvasCode isolates each AI agent

In CanvasCode the isolation is built in, and the difference is in what you can see without asking.

Every AI agent that goes off to work shows which line of work it is on, right on its own panel, next to the pull request status. You look at the canvas and know who is where, without running a command.

When two fronts start touching the same file, the warning comes first, not after. And when an agent finishes and is dismissed, its copy is not left lying around on disk: the app clears what is left and tells you what was still missing.

Isolation is also your call, not a rule imposed on you. It can be on everywhere, off for one specific project, and the instructions agents receive about working in isolation are text you write, not a constant buried in the program.

Do I need isolation if I use one AI agent at a time?

The opposite is worth saying too. If you use one AI agent at a time, none of this matters and the extra complexity does not pay for itself. Isolation exists for people with three, five, eight fronts open at once, which is when the gain from running in parallel starts to outweigh the cost of coordinating.

That is when the question stops being "can I open several?" and becomes "can I trust what they did?".

Worktree or container: which one to isolate AI agents?

A worktree is lighter and faster: it is files on the same disk, and the AI agent still sees the tools on your machine. A container isolates more deeply, including process and network, and it is what you want if you plan to leave an agent running unsupervised. Tools like JetBrains Air offer both; CanvasCode uses worktrees.

What if two AI agents need to touch the same file?

It will happen, and the right thing is for it to surface early. With isolation, both work in their own copies and the collision appears at merge time, with Git showing the two versions side by side. In CanvasCode the warning comes before that: when two fronts start touching the same file, the app says so while there is still time to split the work differently.

How many AI agents can you run in parallel?

Technically, as many as the machine holds: each agent is a process plus a copy of the project on disk. In practice the limit is human and arrives much sooner, because the bottleneck becomes how many you can follow. Six is where most people start losing track.