You start a second agent to get more done in the same afternoon. Twenty minutes later the first one commits a file the second one was halfway through rewriting, and the diff you review contains two unrelated changes — one of them truncated. The agents did nothing wrong. They shared a directory.
Why a shared checkout cannot work
Three things in a git checkout are single-instance by design:
- HEAD.
git switchin one session changes the branch for every process reading that directory. The other agent’s next commit lands on the wrong branch, or fails. - The index. Staging is repo-wide, not process-wide.
git add -Afrom agent A stages whatever agent B has written so far, including files B is still mid-write. - The working tree. Two editors, one file: the last writer wins, silently.
Rate limits are a separate matter and nothing here fixes them. Parallel agents on one account still draw on the same quota, so four sessions do not buy four times the throughput — they buy four places to wait.
One worktree per task
A worktree gives a branch its own directory while sharing the object database. Creating one costs the checkout, not a full clone.
cd ~/repos/api
git fetch origin
# A branch and a directory per task, both named after the task
git worktree add -b fix/session-expiry ~/work/session-expiry origin/main
git worktree add -b feat/invoice-pdf ~/work/invoice-pdf origin/main
git worktree list
Two rules make this hold up:
- Branch from the same base.
origin/mainexplicitly, notHEAD, or the worktrees start from whatever the main checkout happened to have checked out. - Never touch the same files in two worktrees. Git will happily let two branches modify
src/api/client.ts, and the conflict arrives at merge time when you have forgotten both changes. Split by module, not by mood.
If a task has to build on another’s output, it is not parallel work. Run it after the merge.
One agent per window
Keep the same naming in tmux as in the filesystem, so the window title tells you which worktree you are looking at.
tmux new -d -s expiry -c ~/work/session-expiry 'claude'
tmux new -d -s invoice -c ~/work/invoice-pdf 'claude'
tmux ls
tmux attach -t expiry # Ctrl-b n / Ctrl-b p to move between windows in one session
Detaching with Ctrl-b d leaves both running. If the machine is a laptop, they stop when it sleeps, which is the argument for putting this on a machine that stays on rather than on the one you carry.
For unattended runs, use the non-interactive form so a permission prompt cannot park an agent for six hours:
cd ~/work/session-expiry
claude -p "Fix the session expiry bug. Run the auth tests. Commit on the current branch." \
--permission-mode acceptEdits
Write the task down before you launch
An agent that wakes up with no memory of yesterday needs the acceptance criteria in the repository, not in your head. A short block at the top of the task file pays for itself the first time you resume:
<!-- CLAUDE.md, task section -->
## Task: session expiry
- Symptom: refresh token accepted 30s after expiry.
- Fix in `src/auth/session.ts` only. Do not touch the login flow.
- Done when `npm test -- auth` is green and the diff adds a regression test.
- Commit on this branch. Do not push until reviewed.
The “do not touch” line matters more than the goal. Two agents given adjacent modules tend to reach into the same shared helper, and that is where the merge conflict comes from.
Review, merge, remove
Review a worktree the way you would review a pull request, because that is what it is:
cd ~/work/session-expiry
git diff origin/main --stat # what changed, before reading any of it
git log --oneline origin/main.. # what the agent decided to commit
gh pr create --fill --draft # or push and open it in the browser
Then, after the merge:
cd ~/repos/api
git worktree remove ~/work/session-expiry
git branch -d fix/session-expiry
git worktree prune # clears entries for directories you deleted by hand
git worktree remove refuses when the worktree has uncommitted changes. That refusal is the feature: it is the last chance to notice the agent left work behind. Deleting the directory with rm -rf and forgetting to prune is how people end up with a git worktree list full of ghosts and a branch list nobody dares clean.
The limits that show up in week two
| Symptom | Cause | Fix |
|---|---|---|
| Everything slows down at once | CPU contention, not the model | Fewer agents, or a bigger machine |
Killed in a build log |
OOM killer took the test runner | More RAM, or swap, or run the suite once at the end |
| Merge conflict in a shared helper | Two tasks touched one file | Split by module; re-run one task after the merge |
| Agent waits forever | A permission prompt nobody answered | Non-interactive mode, or a policy in CLAUDE.md |
| Disk full | Each worktree has its own node_modules and build cache |
git worktree remove promptly; share the package cache |
That last row is the one that surprises people. Four worktrees of a JavaScript monorepo can be 20 GB of dependencies, three of which are duplicates.
Where Cubs fits
Cubs does the bookkeeping this guide does by hand: a worktree per task is a menu item rather than three git commands, each worktree gets an agent terminal, and each agent gets a status dot so you can see which is working, which is waiting on you and which has finished. The machine is one you size once and keep, so four worktrees do not mean four bills, and pausing keeps the disk so the worktrees and their caches are still there tomorrow.