KUN // FIELD MAP
← the map
RUNNING MANY AGENTS · PAGE 06 OF 11treehouse · git worktrees · pools · leases

treehouse: worktrees without managing worktrees

Why parallel agents need separate checkouts, why the obvious ways to give them one are slow or messy, and how a pool of reusable worktrees fixes both.
TL;DR — Two agents editing one directory will trample each other, so each needs its own checkout. A git worktree is the cheap way to get one, but hand-made worktrees pile up as names to remember and directories to clean, and a brand-new one starts without your installed dependencies or build cache. treehouse keeps a pool of worktrees per repository: running treehouse hands you an idle one (or makes one), drops you into a shell inside it, and when you exit it is reset and put back for the next agent with its dependency folders still in place. It is a small Go CLI with no daemon, for macOS, Linux and Windows.

Once you run more than one coding agent at a time, the question of where each one works stops being trivial. treehouse is Kun's answer to that question, and its design is mostly a list of the ways the naive answers go wrong.

First, what a worktree is

A git repository normally has one working directory: the files you see and edit. A worktree is an additional working directory attached to the same repository. Each worktree has its own checked-out commit, its own branch (or none), its own staged changes and its own untracked files, but all of them share one object database, the store of every commit and file version. So a second worktree costs only the disk space of its checked-out files, not a second copy of the history, and a commit made in one is immediately visible from the others.

You make one with git worktree add <path> and remove it with git worktree remove <path>. That is the whole primitive. treehouse is a manager on top of it; it does not replace it.

Why parallel agents need isolation

An agent working on a task edits files, runs builds, runs tests and sometimes commits. Put two of them in the same directory and every one of those actions becomes a collision: one agent's half-finished edit breaks the other's test run, a formatter rewrites a file the other is mid-way through, and a commit sweeps up changes that belonged to someone else. In his workflow video Kun shows exactly this moment: one agent is already running in the repo, he wants to start another, and he notes that two agents in one directory will step on each other.

The fix is not clever coordination between agents. It is to give each one a directory nobody else touches, so that the only place their work meets is in git, through branches and pull requests, where conflicts are explicit and reviewable. The same thinking shows up elsewhere in his tools: no-mistakes runs its validation pipeline in a disposable worktree so nothing it does affects your checkout. treehouse applies it to the agent sessions themselves. (Note the scope: treehouse isolates files on disk. Giving each agent a fresh context window is a separate idea, handled by how you start the agent, not by treehouse.)

What the obvious approaches cost

There are three things people usually try, and the README opens by naming all three.

Or... are you starting a new worktree for every agent session, losing all your installed dependencies and build cache each time, and wondering why your agents are slow?treehouse README

There is also a human cost Kun dwells on in the same video. Every hand-made worktree needs a name, which nobody wants to invent. Come back to it later and you have to remember what it was for and whether an agent is still running in it. Eventually you have to remove it. He calls each one a kind of debt, and that bookkeeping is what treehouse is built to absorb.

The pool, the lease and the return

treehouse replaces “make a worktree, use it, delete it” with “borrow one from a pool, use it, give it back.” Each repository gets a pool, stored by default under ~/.treehouse/, with up to 16 slots unless you raise max_trees. Pool state is a small file on disk, written under a lock by whichever command is running; there is no background service.

The treehouse pool lifecycle: a worktree is leased from the pool to a session, used, reset and returned warm Pool ~/.treehouse/… Lease a slot reuse an idle, clean one or create one (cold) Session subshell or --lease Agent works edits and builds Return stop leftover processes, reset to base Warm slot node_modules, build cache kept back in the pool exit the shell or treehouse return dirty on exit: slot stays out (exit 3)
One slot's life. Reuse only happens when the slot is idle, unleased, clean and its commit has landed; otherwise treehouse makes a new, cold slot. Tracked files are reset on return, while gitignored output such as installed dependencies survives, which is what makes the next lease fast.

When you run treehouse inside a repository, it fetches from origin and then scans the pool for a slot it can safely reuse. “Safely” is strict: the slot must belong to this clone, have nothing running in it, hold no lease, have no uncommitted or untracked changes, and sit on a commit already merged into the target it will be reset to. If one qualifies, it is reset to the latest default branch. If none does, a new worktree is created and added to the pool. Either way it starts in detached HEAD (checked out at a commit, not on a branch) unless you ask for a branch with -b.

Then you are dropped into a shell inside the worktree. That shell is the lease. Start your agent there, let it work, and when the shell exits treehouse terminates any processes still running in the directory, checks none remain, resets the worktree and marks it available. The checked-out files go back to the base branch; the gitignored dependency folders and build output stay. The next agent to ask gets a worktree that already has its install done.

cd myproject
treehouse              # lease a slot, open a shell in it
claude                 # or any agent; it works in isolation
exit                   # slot is reset and returned warm
treehouse status       # which slots are in use, leased, free

For scripts and orchestrators that cannot sit in an interactive shell, treehouse get --lease reserves a slot durably and prints only its path (or JSON with a lease id), and treehouse return gives it back. Returns can be made conditional on the lease id, so a retried script cannot release a slot someone else has since acquired, and --if-clean refuses rather than discard uncommitted or unpushed work.

How it knows a slot is busy

The README's “conflict-free” claim is about in-use detection, not merge conflicts. treehouse decides a slot is taken by scanning running processes for any whose working directory is inside it, by honouring short-lived reservations while its own commands run, and by durable leases recorded in its state file. A slot that is busy by any of those measures is never handed out. If it cannot read the process table at all, it reports the slot as unverified rather than guessing. Two agents editing the same lines on different branches will still conflict when their work is merged; treehouse only guarantees they never share a directory.

Treehouse helps you manage a pool of reusable, isolated worktrees so each of your agents gets its own environment instantly — no cloning, no conflicts, no coordination overhead.treehouse README

Where the pool lives, and other knobs

The default global store keeps pools out of your project tree. --root . (or root = "." in a committed treehouse.toml) puts the pool at <repo>/.treehouse/ instead, git-ignored automatically, so deleting the project deletes its worktrees too; the trade-off is that treehouse prune --all only sweeps the global root. Other options cover cutting slots from a different base branch, placing worktrees at a custom path for tools that expect a fixed layout, copying selected gitignored files such as .env into each slot via a .worktreeinclude manifest, and running setup commands through a post_create hook.

Platforms and limits

In use: In Larry's setup, treehouse hands out pooled worktrees to coding agents working on the blog.
Next: gnhf and firstmate: overnight loops and a crew with one liaison · Back to the map.