For anyone on a laptop: npm ci per worktree hurts. npm ci --prefer-offline after the first install brings it down to ~20s for me since the cache is shared even when node_modules isn't.
Run three or four agents against the same repo without them stomping each other's changes. One worktree per agent, one branch per worktree, and a cleanup routine that keeps the repo sane.
Each agent runs in its own working directory on its own branch, with its own node_modules and env files. No agent can see another agent's uncommitted changes, and merging back is a normal PR per branch.
Keep worktrees OUTSIDE the main checkout. Agents that glob from the repo root will otherwise recurse into sibling worktrees and get confused about which files are 'theirs'. A sibling directory named after the repo keeps things findable.
mkdir -p ../myrepo-worktreesOne task, one branch, one worktree. Name the branch after the task, not the agent — you will forget which agent did what, but the branch name survives into the PR.
git worktree add ../myrepo-worktrees/feature-billing -b feature-billing
git worktree add ../myrepo-worktrees/fix-flaky-auth-test -b fix-flaky-auth-testnode_modules, .env.local, and build caches are not shared between worktrees — that's the point. Install per worktree. If you use direnv, copy the .envrc so each agent gets the same environment without sharing files.
cd ../myrepo-worktrees/feature-billing
npm ci
cp ~/src/myrepo/.env.local .
direnv allowStart the agent with the worktree as its working directory. Do not point an agent at the parent directory containing all the worktrees — scoping is the whole safety mechanism here.
cd ../myrepo-worktrees/feature-billing && claudegit worktree list shows every checkout and its branch. Combine it with a status loop before you start merging so you don't merge a branch an agent is still writing to.
git worktree list
for wt in ../myrepo-worktrees/*/; do
echo "== $wt"
git -C "$wt" status --short
donePush each branch and open a PR like any human change. Resolve conflicts in the MAIN checkout, not inside a worktree — it keeps the worktrees disposable.
git -C ../myrepo-worktrees/feature-billing push -u origin feature-billing
gh pr create --head feature-billing --fillRemove the worktree, then prune. If an agent left untracked junk behind, --force is safe once the branch is merged. Stale worktree metadata is the number one cause of 'branch is already checked out' errors weeks later.
git worktree remove ../myrepo-worktrees/feature-billing
git worktree pruneYour run report keeps the confidence rating honest.
Sign in to add your report — every count here is backed by a named account.
Useful evidence gets promoted into the structured record above — verified fixes, failed approaches, and reproductions all started as comments.
For anyone on a laptop: npm ci per worktree hurts. npm ci --prefer-offline after the first install brings it down to ~20s for me since the cache is shared even when node_modules isn't.
Good addition. Same applies to pnpm, which is even better here — its content-addressed store makes per-worktree installs nearly free.
We adopted this for the team last quarter. One process note: we require the branch name in the agent's task prompt ('you are working on fix-flaky-auth-test, do not touch other areas'). It cut scope creep noticeably.
Does this survive git-lfs? Asking before I try it on a repo with 60GB of assets.
Yes, but LFS objects are shared via the common .git dir so the first checkout per worktree still smudges files. Use GIT_LFS_SKIP_SMUDGE=1 on worktree add if the agent doesn't need the assets.
Sign in to join the discussion, vote, and verify fixes.
The sibling-directory detail is the part everyone gets wrong. I had worktrees under the repo root for a month and kept blaming the agent for 'randomly' editing other branches. It wasn't random — it was globbing.