Merged with the Factory engine (
factory/engine/src/agents/trees, part agents). It ships with the next gizzi and Desktop runtime release. Until your installed gizzi has gizzi agents tree, use the plain git steps in AGENTS.md.gizzi agents tree gives every agent its own git worktree, called a tree. A tree has an owner, a state and a lease. It starts from fresh origin/main, gets its build output from a warm base, saves a checkpoint after each edit, and is removed by one command when its work is on main.
Why trees exist
Plain worktrees worked, but every rule around them was a paragraph inAGENTS.md that each agent had to follow by hand. They often didn’t:
- The disk filled. On 2026-09-30 about 127 worktrees filled the disk to 100%. Each one kept its own
target/andnode_modules/after the session ended. - Cold rebuilds. A new worktree started with no build output. A cold
cargo checkof the Factory engine took 101 s. - False passes. The shared
.shared-targetlet a worktree’s cargo run reuse another worktree’s output, so a check could pass on code it never compiled. - Shared-checkout damage. Sessions committed and switched branches in the shared checkout, or re-pointed a worktree they did not own.
- Manual cleanup. Landing meant stopping processes, deleting build output, removing the worktree, deleting the branch here and on origin, then running the discipline check. Steps got skipped.
- Dev servers. Old
viteandwrangler devservers ran for days. On 2026-10-25 they pushedfseventsdto 32 GB and the Mac into heavy swap.
Lifecycle
newchecks the branch name (nevermain), checks free disk, fetchesorigin/main, writes a lease, makes the worktree and seeds it. Runningnewagain for the same branch reuses the tree. A worktree you made by hand on that branch is adopted (leased to you) instead.- Work. The CLI hooks save a checkpoint after each edit.
rewindputs the files back to any checkpoint. donelands the tree when its work is onorigin/main.pausekeeps a tree whose work is not merged yet.resumemakes it active again.
<repo parent>/<repo>-<branch slug>, so session/abc123 in allternit becomes allternit-session-abc123, the same name the session hook has always used. The tree id is <repo>~<branch slug>, for example allternit~session-abc123.
Leases live in <factory home>/trees/leases.json. A lease lasts 24 hours (1 hour for a --once tree) and every checkpoint, sync or resume pushes it out again.
What done does
In order:
- Checks the work is on
origin/main. The branch tip must be an ancestor oforigin/main, orghmust report a merged PR for the branch (for squash merges). - Refuses if the work is not merged or has uncommitted files. The message tells you to merge first,
pauseto keep it, or pass--abandon. With--abandon, the whole state (commits and uncommitted files, as one commit) is first pushed tosalvage/<branch>-<date>. - Stops the processes running in the tree. Agent CLIs (gizzi,
gizzi-codeand the other coding-agent CLIs the Factory drives) and your own process chain are never signalled. - Deletes build output (the
[clean] build_dirsnames, only where git ignores them, so a trackedrelease/folder stays). - Runs
git worktree removewithout--force. If git refuses,donestops and nothing is forced. Only--abandonmay force the removal, and only after all the work is pushed to itssalvage/branch. - Deletes the branch here and on origin, deletes the tree’s checkpoint refs here and on origin, and drops the lease.
- Runs
scripts/git-discipline-check.shwhen the repo has one and prints PASS or FAIL.
done inside a worktree made by hand leases it to you first, then lands it.
Factory bots
gizzi agents up gives each Terminal bot that asks for a worktree a tree on branch ao/<slug>, owned by bot:<slug>, seeded source only (workers write code, the orchestrator builds). If the fetch fails it uses the last fetched main.
gizzi agents down <bot> --rm-worktree lands the bot’s tree. If the tree holds unmerged or uncommitted work, it is paused instead and the reason is printed. It is never force-deleted. A worktree from before trees is removed only if a plain git worktree remove succeeds.
Verbs
[tree] is a tree id (it contains ~) or a path. Without it, the command acts on the tree you are in.
Flags for new:
Every verb takes
--json and uses the Factory exit codes.
The warm base and seeding
The base is a clean, detached worktree onorigin/main at <repo parent>/.agent-trees-base/<repo>. It keeps its build output.
A new tree on a new branch is seeded like this:
git worktree add --no-checkoutat the base’s commit.- The base’s files are cloned in with their mtimes: an APFS clone (
cp -c) on macOS, a reflink (cp --reflink=always) on Linux..git,node_modulesand the[seed] excludeentries are skipped. - The index is filled from HEAD, and the tree fast-forwards to
origin/main. Git rewrites only the files that changed. - The
[[seed.deps]]steps run (unless--source-only).
A clone shares blocks with the base, so it costs only the blocks that later change.
node_modules is never cloned. pnpm already hardlinks it from its store, and an offline install (43 s) was faster than cloning its many small files (56 s). An install also has no stale absolute bin paths.
A plain checkout is used instead when:
- the branch already exists (locally or on origin),
--plainor--onceis passed,- there is no base, or the base has uncommitted changes,
- the machine can’t clone. The engine probes with a real one-file clone, so ext4 (no reflink) falls back to a plain checkout instead of a full copy. Windows always gets a plain checkout.
list shows how each tree was seeded (clone or plain) and how long it took.
Keeping the base fresh
refresh makes the base if it is missing, or fast-forwards it to origin/main. It refuses if the base has changed files. Then it runs the deps steps. With --build it runs the [base] build commands, through scripts/build-queue when the repo has one, so the base build waits its turn with other builds.
The tree env
new also writes these lines to <tree>/.allternit-tree/env. The folder is added to the repo’s info/exclude, so git never sees it.
Ownership
Every tree has an owner:session:<id>, bot:<name> or human:<name>. The caller is resolved from --owner, then ALLTERNIT_TREE_OWNER, then the Factory bot this terminal is (bot@team), then $USER.
Only the owner may rewind, pause, resume or done a tree. Anyone else is refused with the owner’s name and told to message them. A person can pass --as-owner to override. The HTTP rewind route needs no flag, because the app’s caller is the person.
Sync is forward only
sync fast-forwards a tree to origin/main. It refuses when the tree has uncommitted files, or when the tree has commits origin/main doesn’t (it can’t fast-forward). It never rebases, merges or resets. The owner does that.
Checkpoints and rewind
A checkpoint is the tree’s full working state (tracked edits and untracked files, not ignored ones) saved as a commit underrefs/checkpoints/<repo>/<slug>/<n>. It is written through a throwaway index, so your real index, HEAD and files are not touched. An unchanged tree is not saved twice. A tree that still matches its commit has nothing to save.
rewind <n> first saves the current state as a new checkpoint, then puts the files back to checkpoint n. Files that were not in checkpoint n are deleted. The restored state shows as uncommitted changes against HEAD. Because the current state was saved first, a rewind can itself be undone by rewinding to the checkpoint it printed.
pause pushes the checkpoint refs to origin so another machine can resume. done deletes them here and on origin.
Overlaps
overlap (and list) compares the files each live tree changed against origin/main: committed since the fork, plus uncommitted. Two trees of the same repo that touch the same file are listed with the files. It is an early warning, not a lock.
Reap
reap checks every worktree of every repo that has a lease, plus the repo you run it from. The shared checkout, the base, and worktrees git marks prunable or whose folder is gone are skipped. For each worktree, in this order:
- Stopped: dev servers running longer than
dev_server_hours, whatever the tree’s state. Agent CLIs are never stopped. - Kept: paused trees.
- Kept: detached worktrees (build trees). A
--oncetree is not exempt. - Kept: locked worktrees.
- Kept: any tree with a process still running in it.
- Kept: merged and clean, but not idle yet (“in use or new, removed once idle”).
- Kept: merged, clean and idle, but a file in it is open.
- Removed: merged into
origin/main, no uncommitted files, nothing unpushed, idle. It is landed the waydonelands it (without the discipline check). If landing fails, it is kept with the reason. - Cleaned: not merged (or with uncommitted or unpushed work) and idle. Its build output is deleted and the tree is kept. If it has no build output it is just listed as kept.
- Kept: everything else (“in use”).
- its lease has expired, or it has no lease,
- it is not new: its
.gitfile is older thanidle_hours. A new tree has no commits of its own, so it looks merged, and a cloned one keeps old mtimes. New trees are kept until idle. - no source file (outside
.gitand build output) was touched inidle_hours.
--apply, reap also runs git worktree prune and drops leases whose folder was removed by hand. It prints free disk before and after.
Scheduled reaper
reap --apply --size, so each lease’s disk use stays current for the Tree card. Install it from the folder that holds your repos (for example the workspace root) and it covers every repo directly inside it, or from one repo to cover only that repo. It runs through the launcher <factory home>/trees/reaper-run.sh, which looks for the engine on every run (newest Desktop runtime, the app bundle, Homebrew, the binary that ran the install, then PATH) and uses the first one that has agents tree. Runtime updates and brew upgrade move the binary, so a fixed path would stop working after the next update. On macOS this installs the launchd agent com.allternit.agent-trees-reaper (low priority I/O, Nice 10, log in <factory home>/trees/reaper.log). On Linux it installs the systemd user timer allternit-agent-trees-reaper.timer. Other systems are refused.
Hooks
.steering/bin/tree-hook.sh runs the Factory engine directly. Outside a tree, or with an engine too old to know agents tree, it exits 0, so a hook never blocks an agent.
Who gets them:
The session hook (
.steering/bin/session-worktree.sh) tells a session in the shared checkout to run gizzi agents tree new "session/<id>" --owner "session:<id>" when the installed gizzi has the tree verb, and the plain git worktree add steps when it doesn’t.
agent-trees.toml
Optional, at the repo root. Unset keys keep their defaults. A file that does not parse is an error, so a tree is never seeded the wrong way.
The platform repo’s file adds
.shared-target, .gw-target and surfaces/allternit-desktop/release to exclude, and sets [base] build to cargo check --workspace --all-targets, cargo build -p allternit-api and cargo build -p allternit-factory. Build each package with its own command, the same way agents build it: building two packages in one command unifies their features differently, so shared crates get other artifact names and every new tree rebuilds them.
Machine warnings
list (and the Tree card) adds warnings when:
- free disk is under
min_free_gb, - a dev server in a tree has run longer than
dev_server_hours, - on macOS,
fseventsdholds more than 8 GB (the 2026-10-25 slowdown).
HTTP API
Served by the Factory engine and proxied by allternit-api for Desktop, web and phone. Fields are camelCase. Errors use the Factory error shape and codes (usage, refused, not_found, transport, internal).
GET /api/factory/trees?path=&all=
path limits the answer to the tree containing that path. all=true adds worktrees with no lease.
state is active, paused or done. owner.kind is session, bot or human. seed.strategy is clone or plain. A worktree with no lease has leased: false and owner label no lease.
GET /api/factory/trees/:id/checkpoints
tool is what the checkpoint followed (null when saved by hand).
POST /api/factory/trees/:id/rewind
Body:
tree is the full tree object shown above (shortened here). An unknown tree or checkpoint is not_found.
Code sessions: the Worktree switch
In Code, the Worktree switch on the Environment card makes a local session run in its own tree. When the session starts, Desktop asks gizzi forisolation: "worktree". gizzi then runs gizzi agents tree new session/<id> --owner session:<id> from the session’s folder, creates the session inside the tree, and keeps that folder for every later turn, so tools, builds and checkpoints all happen in the tree. The switch is set when the session starts: once its first turn has run, the switch shows the choice and can’t move a running session. Start a new session to change it.
Tree card in the Code session panel
The Code session panel shows a Tree card for the session’s tree: the one gizzi made for it with the Worktree switch, or the tree its folder sits in. It is in Desktop, the ai.allternit.com phone layout and the m.allternit.com PWA (on the phone the facts wrap in the sheet instead of truncating). It shows:- the branch, the state (Active, Paused, Done), how far it is behind main, its size when known, and the owner,
- the processes running in it, with dev servers marked,
- a warning when another tree changed the same files,
- the machine warnings,
- the checkpoints, newest first, with Show all past the first few. Each has Rewind, confirmed in place. After a rewind the card offers Undo, which rewinds to the checkpoint the rewind saved.
Limits
- No crash journal. Git is the store: the worktree, the branch and the checkpoint refs survive a crash on their own. The lease file is the only extra state, and
newre-adopts a worktree it lost. ducounts clones in full. It can’t see shared blocks, solist --sizeand the reaper’s sizes overstate what a cloned tree really uses. Free disk (before and afterreap) is the true figure.- Size is measured, not live.
list --size,reap --sizeand the scheduled reaper store each lease’s size. The HTTP list and the Tree card show the last stored figure and when it was taken. - Windows. There is no clone backend (plain checkouts only), no free-disk gate (free space can’t be read), no process detection, and no scheduled reaper.
- Disk gate.
newchecks free space only (min_free_gb). TheAGENTS.mdrule to stop when the workspace is over 150 GB is still yours to check.