Running Agents in Parallel: Worktrees, Commits and Cherry-Picks
What happens when several agents share one working tree, and the git habits that stopped it happening again
Once the roles were in place, the next step was to run several at once. The backlog was full of independent items, and parallel agents finish before lunch what a sequential run takes a day over.
It worked, mostly. Then it didn’t.
The frustrating afternoon it went wrong
Two agents in the same checkout. One was doing a theme round: padding, a colour token, the regenerated override CSS. The other was hardening the related filter across every generated API template, which meant dozens of Liquid files.
The theme agent ran git status, saw a pile of Liquid templates it hadn’t touched, and reasoned: the build regenerates CSS from the token file, so the build must have changed these too, so reset them. It ran git checkout -- on the lot. A few minutes later it did it again.
The build does not touch Liquid. The other agent’s changes were gone, uncommitted, so they stayed gone. Like poof out in thin air gone. It finished its run, reported success, and the diff it described didn’t exist.
Nobody was malicious. One agent saw changes it couldn’t explain and guessed confidently. That’s the failure mode, and it’s a human one.
The rules that came out of it
This is one of those learning by failing incidents. Every brief for an agent running alongside others now carries the same paragraph. Other agents are working in this checkout. Never run git checkout, git stash, git reset or git restore on a file you didn’t change. If git status shows changes you don’t recognise, report them and carry on. Reverting is not your call.
The second rule took longer. git add my-file && git commit commits everything staged, including whatever a sibling staged a minute earlier. I found this when a documentation commit turned up with another agent’s half-finished git rm in it. Commits now name their paths, git commit -m "..." -- path/one path/two.
And the habit that catches the rest: after every agent reports, run git status --short before you believe it. If another agent’s files are missing, suspect a revert before you suspect the report.
Worktrees for anything big – treat it as a human team of developers
Rules help, but the fix is not sharing the working tree. Anything that touches more than a handful of files gets its own worktree, in a gitignored folder, on a wip/ branch.
I create them myself rather than letting the tooling do it. The built-in isolation branches from origin/main, and my local main is usually ahead because I push deliberately. So the agents got a worktree without the morning’s work, checked the base commit as briefed, correctly refused to start, and the tooling tidied the worktrees away before I’d read the report.
git worktree add .claude/worktrees/casting-filters -b wip/casting-filters main
The agent gets the absolute path, starts every command from it, confirms the base with git log --oneline -1, and commits on its own branch as it goes. Nothing it does can reach the main checkout.
Delivery is a cherry-pick
Back in the day I worked at Trolltech. This is where i was introduced to Git and all the potential missory this wonderfull tool presents. An open source project with hundreds of developers contributing, and a few people cherry-picking out the best contributions for the product (Qt). This is no less relevant to managing a team of agents.
This is where the worktree idea diverges from a normal software team, where the branch becomes a pull request and the PR gets merged. On a Power Pages project the dev loop is main checkout, upload to the dev site, click around, and a fix that lives only on a branch is invisible to that upload. I lost a morning concluding a fix didn’t work when it was sitting on a branch I hadn’t picked.
So the last step of every worktree job is a cherry-pick of the agent’s commits into main, in my checkout, then the tests, then the upload. The branch can go to a draft PR as a review trail. It is never the delivery.
Two checks after the pick: git diff wip/casting-filters -- <paths>, because a pick drops lines if the worktree was cut from a different base than main has now, and then remove the worktree and branch so the next run starts clean.
The compiled-bundle trap
One more, specific to this platform. In my projects the client components are TypeScript compiled to one JavaScript web file. Two parallel branches that both change TypeScript each build a bundle with only their own changes. Cherry-pick the second bundle on top of the first and you’ve regressed the first branch, with a merge conflict in a minified file for good measure.
Cherry-pick the source, rebuild once from the combined tree, commit the bundle separately, and grep the output for both changes before you upload. Never cherry-pick the built file.
How to make a mess and fix it
An agent’s work vanished and nobody ran a destructive command. Somebody did. Look for checkout or restore in the other agents’ transcripts.
A commit contains files the agent never mentioned. Staged by a sibling. Name paths on the commit line.
Worktree agents refuse to start. The base is stale. Create the worktree from local main yourself.
The fix doesn’t work on dev. It’s on a branch. Cherry-pick it into main and upload again.
Useful links
- git worktree
- git cherry-pick
- git commit, including the pathspec form
- Common workflows in Claude Code
- About protected branches on GitHub
Next: the day a batch of nine agents lost eight agents’ worth of work, and how I supervise the supervisor now.