Mr Elokusa
tech shortcuts

Git worktrees: run three Claude Code agents on one repo without collisions

Worktrees give each agent its own isolated checkout that shares the same .git. Three agents, three branches, zero merge chaos. The cleanest parallelism trick I know.

The problem

You want to run multiple agents in parallel — one refactoring auth, one writing tests, one drafting a README. Cloning the repo three times wastes disk and drifts remotes. Switching branches in one checkout serializes the work.

Worktrees

A worktree is a second (third, fourth...) working directory backed by the same .git. Different branches, shared history, independent filesystems.
# from the main checkout
git worktree add ../myproj-auth feature/auth-refactor
git worktree add ../myproj-tests feature/test-coverage
git worktree add ../myproj-docs feature/readme-pass

# launch an agent in each
cd ../myproj-auth   && claude
cd ../myproj-tests  && claude
cd ../myproj-docs   && claude

When you're done

git worktree list
git worktree remove ../myproj-auth
# or prune all stale ones
git worktree prune
One pitfall: node_modules is per-worktree, so each one re-installs. Fix with pnpm (content-addressable store) or a shared node_modules symlink if you trust your agents not to fight over it.

Discussion

(0)

Join the first cohort. Unlock badges.

Sign In to Comment