One worktree per task: parallel agents without collisions

· Harish Ganapathi · 2 min read

In short

Running two agents in one working tree is a merge conflict with extra steps. Give every task its own worktree, branch and session; merge finished work into an integration branch explicitly; and never resolve conflicts automatically.

The first time you run two coding agents at once in the same checkout, one of them will git stash the other’s work, or format a file the other is halfway through editing, or run the test suite while the other has the build broken. It feels like a bug in the agents. It is a bug in the setup.

Worktrees are the cheapest isolation you have

A Git worktree is a second working directory attached to the same repository. It shares history and objects but has its own files, its own index and its own checked-out branch. Creating one takes milliseconds. Deleting one leaves nothing behind.

That is precisely the unit of isolation an agent task needs. Each task gets:

  • its own worktree, so file edits cannot collide;
  • its own branch, so commits are attributable to the task;
  • its own provider session, so context does not leak between tasks.

Nothing about this is exotic. It is what a careful human does when working on two things at once. Agents just make the case for it undeniable, because they will happily work on eight things at once.

Integration is a merge, not a hope

Isolation solves collisions but creates a new question: how does task B, which depends on task A, see A’s work?

The answer that scales is an integration branch per run. When a task finishes, the engine commits its worktree and merges that branch into the run’s integration branch. A dependent task’s worktree is created from the integration branch, so it starts with its predecessors’ work already present. The dependency graph and the branch graph are the same shape.

Two rules make this safe:

  1. Only the engine commits. Agents edit files; they do not decide what constitutes a finished unit of work. The engine commits at task completion, so every commit on the integration branch corresponds to a task that ran to the end.
  2. Conflicts block. If a merge conflicts, the task is marked blocked and a human decides. No automatic resolution, no “prefer theirs” heuristic. Automatic conflict resolution is automatic damage with a clean log.

Retry in place

Worktrees also make recovery honest. If a task is interrupted, its worktree is a checkpoint. Retrying puts the task back in that same worktree with a note describing what happened, rather than starting from nothing. The partial work is preserved and visible, which is the difference between a resume and a restart.

The tax

Worktrees cost disk and, if your project has a heavy install step, time. A hundred-task plan is a hundred node_modules directories unless you share a cache. We consider that a fair price for never again watching one agent revert another’s work in real time.

Keep reading

One email a month

Engineering notes on running agents like a team. No launch spam.