I once watched one of two parallel agents sweep up the other agent's commit and push it.
Because I run several sites and apps in parallel as an indie developer, it is tempting to fire off many Antigravity 2.0 agents at once — one adding articles, another bumping dependencies. But when I ran both on the same clone, the dependency agent's git add -A scooped up article files that the other agent had not yet staged, and unintended content landed on main.
I reverted it quickly, but tracing the cause led to a design flaw: I had run agents in parallel while they shared a single work area. This article lays out an isolation design for running multiple agents safely against one repository.
Why sharing a working tree breaks under parallelism
A git repository is made of three parts: the .git directory that holds history, the working tree where the files you are editing live, and the index (staging area) that records what goes into the next commit. The problem is that a clone has exactly one index and one working tree.
When parallel agents share a clone, three kinds of collision occur.
The first is the index.lock collision. git creates .git/index.lock while it rewrites the index. If agent B starts an add while agent A is mid-commit, B fails with Unable to create '.git/index.lock': File exists. In unattended VM runs, that failure tends to be swallowed silently, leaving you "thinking you committed" while nothing happened.
The second is working-tree contamination. Agent B's checkout overwrites files agent A is editing, or wipes them with git checkout ..
The third is the branch mix-up. A working tree can only point at one branch. The moment A switches to a feature branch, B is also working on that branch, and the changes tangle.
Give each agent its own work area with worktrees
All three share one root cause: a shared index and working tree. git worktree lets you keep multiple independent working trees and indexes while sharing a single .git (history). Assign one worktree per agent and you cut the collisions off at the root.
# Derive per-agent worktrees from a normal (non-bare) clone
REPO="$HOME/repos/antigravitylab.net"
cd "$REPO"
# Create a dedicated branch + dedicated working tree per agent
git worktree add "../wt-agent-articles" -b agent/articles origin/main
git worktree add "../wt-agent-deps" -b agent/deps origin/main
# Each worktree has its own index
# ../wt-agent-articles … article-adding agent only
# ../wt-agent-deps … dependency-update agent onlyNow the article agent stages and commits only inside ../wt-agent-articles, and the dependency agent works only inside ../wt-agent-deps. Even a git add -A is scoped to that worktree's files. The incident I opened with simply could not happen with this separation in place.
Because worktrees share history, disk use is only the size of each working tree (tens of MB) — far lighter than holding two full clones.