Shepherd
Many coding agents, every machine, one codebase
52 s
Ten agents on one repository usually means ten copies of node_modules, ten build caches and ten dev servers, all resident until the machine starts to swap. Then two of the agents edit the same file, and nobody finds out until the second branch tries to merge.
Shepherd is a daemon that runs on each of your machines, with a shepherd command that talks to it. It gives every agent its own worktree, decides when heavy commands such as type checks and tests may start, moves waiting work to a machine with room, and lands finished branches in the order that conflicts least. Claude Code, Codex and Cursor reach it through hooks they already have, so the agents themselves do not change.
- 4.7 s
- To create a worktree whose dependencies are already built, in a pnpm monorepo with 33,667 dependency files
- 46 to 56 MB
- Disk each of those worktrees owns, with about 1 GB shared
- 56 to 92 ms
- To give a worktree its own copy of a 307 MB Postgres template, using no extra disk
How it works
- 01
Each agent gets a worktree
Shepherd installs with one command. A new worktree starts from shared layers that hold the source at a commit, the installed dependencies for a lockfile and the build outputs of a commit. Every worktree on the same lockfile shares one dependency layer, and the install runs once. A content store keeps each file's bytes once on disk. On macOS a worktree gets them by clonefile, and on Linux it is an overlay mount, with reflinks as the fallback.
- 02
Heavy commands wait for memory
Type checks, linters, tests and builds go through a memory gate. Each one starts only when its observed peak memory fits the budget and the memory the machine has free at that moment, which keeps the machine out of swap. On a real repository, four checks started at once finished in about 230 seconds instead of 336, and six of six finished where none had before. A check that already ran on the same content returns the stored result in 3.3 seconds instead of 53.
- 03
A waiting check moves to a machine with room
After a check has waited 20 seconds, its daemon asks the other machines in the pool for their free memory and open slots, and one with room takes it. The job travels as a commit of the worktree, and git sends only the objects the other machine lacks, usually a few kilobytes. That machine keeps warm checkouts with dependencies installed. Only checks whose results can be cached travel. Builds and tests stay home, and so does any worktree that holds an untracked .env or key. When every Mac is full, Shepherd can wake a Linux machine over your own ssh, run the check there and put it back to sleep. The pool can span a whole team, with each person getting a fair share of the machines.
- 04
Collisions are caught on the edit
Every edit is test-merged against the other worktrees, which took 0.18 seconds on a repository with 81 of them. If the edit would conflict, the agent hears about it on that edit, while changing course is still cheap, and the warning reaches agents on other people's laptops too. Finished branches join a train. Shepherd merges each one onto the cars ahead of it, runs the repository's checks on the merged tree, and tells the agent its verdict on its next tool call, so a red agent fixes its own work.
- 05
Work survives an agent that stops
When someone runs out of tokens, their agents stop mid-task. Shepherd snapshots each worktree, stops its servers and frees the memory, then writes a handover note that says what was done, what is left and what is failing. A free agent picks the work up from there. If two agents reach for the same task, the first claim keeps it and the second gets the note.
Decisions
Shepherd changes nothing in the agent. Claude Code finds a shim first on its PATH rather than getting a rewritten command, so its permission rules still match what the agent wrote. If the daemon is down, the command runs the plain way and prints one line saying what Shepherd could not do.
Agents never talk to each other directly. Warnings, results and verdicts all go through Shepherd, which orders, checks and logs every message.
Every request to the daemon carries a request key. A client that retries after a timeout gets the first run's result, so a crash or a retry never runs a step twice.
Nothing destructive happens without a gate. Evicting or removing a worktree snapshots its changes first. A branch of yours moves only when you promote the train from a terminal you type in, which an agent's shell cannot do, or when the repository opts in to letting green cars land on their own.