Skip to content
Julian De Leon
Lab

A folder in every repository

3 min read

A factory runs several sessions at once, each in its own worktree. For that to work without a person preparing each one, a repository needs a setup where a new worktree is ready in seconds and leaves no trace in the code.

A folder of its own#

The factory keeps its things in .anturno/ at the root of each repository, as Claude Code keeps .claude/. A session's worktree goes in .anturno/worktrees/<name>.

[ REPOSITORY ]
  • factory/
  • .git/
  • .anturno/worktrees/
  • brisk-otter/a session
  • calm-river/another
  • package.json
Tree with 6 nodes

Worktrees used to live in the app's own folder, away from the code. Inside the repository, they sit next to what they are a copy of, and deleting the repository deletes them too.

Ignored without a commit#

Git has to ignore the folder, or every worktree shows up as a change. Adding it to .gitignore would mean a commit in every repository the factory touches. The factory writes it to .git/info/exclude instead: same syntax, never committed, local to that clone.

[ IGNORED ]
$ tail -1 .git/info/exclude
.anturno/
$ ls .anturno/worktrees
brisk-otter
$ git status -s | wc -l
0

If the folder is already ignored, by the repository or by the user's global config, nothing is written.

Files git doesn't track#

A fresh worktree has only what git tracks. A .env with local keys stays behind. A .worktreeinclude file at the root lists the ignored files a worktree should get, in .gitignore syntax, the same file Claude Code and Codex read.

[ INCLUDE ]
.worktreeinclude
ignored by git
copied

Only files that git also ignores are copied, so a tracked file is never overwritten.

Dependencies in place#

A worktree without node_modules can't run tests or a build, and the agent's first step becomes a full install. The factory fills it before the agent starts.

My first plan was to clone the checkout's node_modules as a copy-on-write copy, which takes no disk space. It was the slower option. Bun installs from its shared cache without downloading anything, and it follows the worktree's lockfile, which a copy of another branch's node_modules can't promise.

[ FACTORY REPO ]
  • 542

    packages

  • 2.7 s

    bun install

  • 14.6 s

    cow clone

So Bun and pnpm repositories get an install with the lockfile frozen. Other package managers, or an install that fails, get the clone.

[ NEW WORKTREE ]
$ bun install --frozen-lockfile
+ @biomejs/biome@2.6.3
+ typescript@7.0.2
542 packages installed [2.73s]

When a session ends#

The factory writes a marker into each worktree's git folder with the commit it started from. When the session ends, a worktree with no changes and no new commits is removed with its branch. One with work stays where it is. At launch, the factory sweeps leftovers a quit or a crash left behind, by the same rule.

[ ON EXIT ]
untouched
removed with branch
has work
kept

A worktree without the marker was not made by the factory and is never touched.