AID-63Recommended
Give every parallel agent its own working copy
Run each agent that works at the same time as another in its own worktree or container, on its own branch. Never let two agents edit one checkout.
How to do it
Two agents in one folder overwrite each other's files and mix their changes into one commit. A git worktree is a second checkout of the same repository on its own branch, so it costs seconds and little disk. Some agent tools create one per session, such as claude --worktree <name> in Claude Code. Cloud agents start a fresh container for every task. Give each copy its own port, database name and settings file, or two test servers collide. Delete the copy when its branch merges or closes. Each copy still runs inside a sandbox, as Run agents in a sandbox says. It commits on its own branch, as Work on a branch and commit often says.
Examples
Shell example
# start-agent.sh <task-name>: one worktree, branch and port per agent
task="$1"
git worktree add "../wt-$task" -b "agent/$task" origin/main
port=$((4000 + $(git worktree list | wc -l)))
echo "PORT=$port" > "../wt-$task/.env.local"
How to check
Start two agents with the team's start script. git worktree list shows two new paths on two different branches, neither of them the main checkout. Their test servers listen on different ports.
Sources
Related rules
- AID-23 Run agents in a sandbox in AI-assisted development
- AID-10 Work on a branch and commit often in AI-assisted development
- AID-67 Split work between agents by files and merge through one lead in AI-assisted development
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-assisted-development/running-agents-at-scale/parallel-agent-workspaces">Agent Wranglers AI-assisted development playbook</a>. In code you write, add a comment next to it with the same link.