Software Engineering / Version Control & Review
Isolate parallel agents with worktrees and branches
- MUST give each agent working at the same time its own working directory: a git worktree (or a separate clone) on its own branch. Never let two agents edit the same working tree.
- MUST create each worktree from the latest default branch, fetched just before.
- MUST split parallel tasks so they touch different files and decisions (BP-0008 rule 9). If two tasks must change the same file, run them one after the other.
- MUST integrate finished branches one at a time: update the next branch from the newly updated default branch, re-run tests, then merge. Do not merge several agent branches blind.
- MUST keep per-worktree state out of the repository (local environment files, ports, caches, databases), so parallel worktrees do not collide; give each its own ports or data directory where services run.
- SHOULD name worktrees and branches after the task (
../repo-issue-42,feat/issue-42-…) so ownership is obvious. - SHOULD remove worktrees and delete merged branches when the task ends (
git worktree remove,git worktree prune). - SHOULD record which agent owns which worktree in the run’s ledger or workflow memory (BP-0013).
When to apply
Section titled “When to apply”An orchestrator running several coding agents at once, or a person running more than one agent session on the same repository.
Procedure
Section titled “Procedure”git fetch origingit worktree add -b feat/issue-42-json ../repo-issue-42 origin/maingit worktree add -b feat/issue-43-exit-codes ../repo-issue-43 origin/main# … agents work in ../repo-issue-42 and ../repo-issue-43 …# integrate one at a time, then:git worktree remove ../repo-issue-42git branch -d feat/issue-42-jsongit worktree pruneAnti-patterns
Section titled “Anti-patterns”- Two agents in one checkout overwriting each other’s edits.
- Parallel tasks that both edit
package.jsonand the same module. - Merging five agent branches in one go and debugging the combined failure.
- Dozens of stale worktrees left on disk.
Checklist
Section titled “Checklist”- One worktree and branch per concurrent agent, from a fresh base
- Parallel tasks file-disjoint
- Integrated one at a time with tests re-run
- Local state and ports isolated per worktree
- Worktrees and merged branches cleaned up