I'd planned it carefully. Several agents dispatched at once, each with an explicitly assigned set of files. I checked the sets for overlap. There was none — different directories, different modules, no shared file anywhere.
One agent, partway through, decided to get a clean baseline before running a check.
git stash
Git stashes the working tree. Not your files. Not the files you were assigned. Every uncommitted change in the repository, including several other agents' in-flight work and my own.
The Assumption That Was Wrong
I had reasoned about file conflicts and concluded the plan was safe. Two agents editing the same file is obviously a problem. Two agents editing different files obviously isn't.
That reasoning is correct and insufficient, because a git repository has repo-scoped operations, and those don't care about your partition:
git stash— takes everything uncommittedgit restore .— discards everything uncommittedgit reset --hard— same, plus moves HEADgit clean -fd— deletes untracked files anywheregit checkout <branch>— changes the tree under everyone- Even
npm installrewriting a lockfile is shared state
Any one of these from any agent affects every agent. The blast radius is the repository, and I had partitioned at the file level.
The uncomfortable part: the agent did nothing wrong. Stashing before a clean check is standard, sensible practice. It's what I'd do. It's only destructive because of a fact about the environment the agent had no way to know — that several other processes were editing the same tree simultaneously.
You can't fix this by writing smarter agents. Every agent is reasoning correctly about a repository it believes it has to itself.
Why It's Worse With Agents Than With People
Humans share repositories constantly without this happening, and it's worth being precise about why.
Humans have out-of-band coordination. You see a teammate is mid-refactor. You ask before force-pushing. You notice uncommitted changes that aren't yours and stop. And crucially, humans mostly work in separate clones — the shared thing is the remote, where git's actual concurrency model lives.
Agents in one tree have none of that. No awareness of each other, no ambient signals, and they operate at a speed where the damage is done before anything surfaces. They're also more likely to run cleanup commands, because "ensure a clean state before verifying" is good practice that appears everywhere in training data.
Git's concurrency model was designed for distributed clones synchronizing through a remote. Running N concurrent writers inside one working tree uses it against its design and expects the design to protect you.
What Actually Fixes It
Worktree isolation. git worktree add gives each agent a real, separate directory with its own index and working tree. A discard, a checkout, or a hard reset in one worktree cannot touch another's files. This is the actual fix — it makes the destructive commands safe by making their blast radius correct.
With one sharp exception, and I only learned it by watching an agent walk right up to it. Worktrees share more than the object database — they share the stash stack. git stash in worktree A and git stash pop in worktree B will happily pop A's entry into B. The stash is a repo-level structure, not a worktree-level one, so the one destructive command most likely to be reached for is precisely the one isolation doesn't isolate.
So the rule needs a rider: inside a worktree, never use bare git stash / git stash pop. Set work aside with a throwaway WIP commit instead — it's worktree-local and strictly safer. If you genuinely must stash, tag it (git stash push -u -m "<unique-tag>"), find your own entry's SHA, and git stash apply <sha> rather than popping whatever happens to be on top.
The cost of worktrees is merge work at the end, which is ordinary branch merging and a problem git is genuinely good at. Much better problem than silent data loss.
Or serialize. If the work is small or the pieces are interdependent, run them one at a time. Parallelism has real coordination cost and it isn't always worth paying.
Ban destructive git in the dispatch prompt. Belt and braces even with isolation. I now explicitly list the forbidden commands in every parallel dispatch. Not because a good agent needs the instruction, but because the cost of it being ignored is bounded and the cost of staying quiet isn't.
Commit each wave the moment it's green. Uncommitted work is the only work at risk. A commit is a durable checkpoint that survives nearly everything on that list. Long-lived uncommitted state across a parallel run is the actual vulnerability, and shortening that window shrinks the exposure more than any rule does.
The General Shape
I keep meeting versions of this and it's always the same mistake.
Isolation has to happen at the level where shared mutable state lives.
I isolated at the file level. The shared mutable state was the working tree. The partition was one layer too shallow, and everything above that layer was undefended.
It's the same error as scoping a database policy to a row when the grant is per-table — I made that one too, on a table where "update your own row" quietly included updating your own role column. Right idea, wrong granularity, and the gap stays invisible until something walks through it.
So the question to ask before parallelizing anything: what does the shared substrate actually cover? Not "will these two touch the same file" but "what is the widest thing either of them can affect."
For a git repo, that's the whole repo. Always was.
The Rules I Run Now
- Parallel agents that edit get separate worktrees. No exceptions, no "the file sets are disjoint."
- Destructive git commands are explicitly forbidden in every dispatch prompt — and that list includes
stash, even under isolation, because the stack is shared. - Prefer a throwaway WIP commit over a stash for setting work aside.
- Commit the moment a wave is green.
- Read-only agents can share a tree freely — they have no blast radius.
That last one matters for throughput. Most fan-out work is search and analysis, and that parallelizes for free. It's only the writers that need walls.
I got the work back, which is the only reason this reads as a lesson rather than a disaster. The stash list still had it.
I'd rather not find out what the version without a recoverable stash feels like.