Context Theory Get your growth audit

Answer

When should you use worktrees with coding agents?

When more than one run needs a working directory at the same time, and cloning the repository again would be wasteful.

When several runs need their own working directory at once. A worktree gives each one an independent checkout sharing a single repository, which is cheaper than repeated clones and stronger than sharing a directory.

The problem being solved is narrow and worth stating precisely: two runs need to have different files on disk at the same time, and they cannot share a directory without reading each other's unfinished work. The general solution is a second checkout. A worktree is a second checkout that shares the underlying repository, so the history, the objects and the remotes are common while the files and the current branch are not.

The practical benefits over separate clones are disk, time and coherence. There is one copy of the history rather than several. A branch fetched once is available in every worktree. And commits made in one are immediately visible to the others as commits, without a network round trip, which matters when work is being handed between runs.

The costs are real and mostly ergonomic. Build outputs, dependency directories and local configuration are per-checkout, so each worktree needs its own install and its own build, which for a large project is neither fast nor small. Tooling that assumes one checkout per repository sometimes behaves oddly. And a branch checked out in one worktree cannot be checked out in another, which is a guard rather than a defect but surprises people the first time.

For a single agent run, none of this applies and a branch in the ordinary working directory is sufficient. The mistake is treating worktrees as a best practice for agent work in general; they solve concurrency, and a single run has no concurrency to solve. Adopting them without the problem adds setup and confusion for no benefit.

The case where they are clearly right is several runs proceeding at once on independent pieces, each producing its own change, on a machine where cloning the repository repeatedly is expensive. That describes a large repository and a deliberate parallel arrangement, which is a real situation and not the common one.

There is a related pattern worth mentioning: a disposable worktree for a speculative attempt. Creating one, letting a run work in it, and removing it afterwards gives an experiment that cannot touch anything and leaves nothing behind. That is useful even without concurrency, and it is the one single-run case where the tool earns its place.

A worktree is the cheapest way to give a second agent its own floor to stand on without buying a second building.

Siddharth Sharma, Context Theory

Related questions

Are containers a better answer than worktrees?

They solve a different problem, which is what the run can reach rather than which files it sees. A container isolates the environment and its side effects; a worktree isolates the checkout. Where both matter — untrusted work with concurrency — the two combine rather than compete, and where only concurrency matters, the worktree is much lighter.

What happens to worktrees that are left behind?

They accumulate, hold stale branches and confuse both people and tooling about which checkout is current. Treating them as disposable rather than as long-lived is what keeps the arrangement clean: create for a piece of work, remove when the change is merged. Anything long-lived is better as a separate clone.

METHOD

Every figure below carries its source and the date it was verified. Nothing on this page is asserted.

The numbers on this page.

Datapoints
What Value Specific to
Sub-15-minute compliance — automated routing vs manual only62.5% vs 39.1%Category-wide
Close rate — response under 5 minutes vs over 24 hours32% vs 12%Category-wide

2026 speed-to-lead benchmark · verified

Optifai speed-to-lead benchmark · n=939 companies · Q2 2025–Q1 2026 · verified

What is specific to this page.

Evidence
Kind Claim Check it against
SoftwareA worktree provides an independent checkout and branch while sharing the repository's history, objects and remotes, so concurrent runs get separate files without duplicating the repository.Creating a second worktree and confirming that a commit made in one is immediately visible as a commit in the other without fetching.
ProcurementWorktrees carry per-checkout costs in dependency installation, build output and local configuration, so the saving relative to separate clones is in history rather than in the working environment.Measuring the disk and time cost of installing dependencies in a second worktree against a second clone.
WorkflowA single agent run has no concurrency to resolve, so a branch in the ordinary working directory is sufficient and adopting worktrees adds setup and tooling surprises without benefit.Identifying what a worktree provides for a single sequential run that a branch does not.
ResponseA disposable worktree gives a speculative run an environment that cannot affect anything and leaves nothing behind when removed, which is the one single-run case where the mechanism earns its cost.Creating a worktree for an experimental run and removing it, checking that the main checkout is unchanged.

Each row would be wrong on another industry's page. Where a sourced figure exists it is in the table above instead; these are the constraints that shape the work and do not happen to be numbers.

Start with the measurement.

Reading about a benchmark is not the same as knowing your own number. The audit produces yours, measured rather than estimated.

Get your growth audit

$497 · delivered in 5 business days · credited against month one