I asked an agent to investigate disk usage on the machine where I develop dotty-rs, a Scala 3 compiler written in Rust. The agent reported that the disk was 98% full. After checking issues, pull requests and running processes, it estimated that removing 138 directories had freed around 595 GiB.
I already had a resource manager, though I don’t know how many of those directories it had tracked. It could remove a registered worktree once its owner released it. To decide whether an idle checkout was ready to release, I needed to know where its issue stood. The agent that wrote the change might still be waiting for another agent to review it.
From Issue to Review
A coordinating agent follows each issue from scoping through review. If the scope is broad or unclear, it asks a planning agent to work out which changes belong in one pull request and which can be reviewed separately. Once the scope is settled, the implementer creates its own branch and Git worktree. It writes and tests the change in that directory, then opens a pull request.
Each review round starts with a fresh reviewer. For a local review, it checks out the proposed commit in a second worktree so it can build and test that revision independently. If the reviewer requests changes, the coordinator sends the findings back to the same implementer. The implementer makes those fixes in its original worktree, and the updated commit goes through another review. Even a single issue can need both checkouts at once.
The Cost of Parallel Worktrees
A worktree shares Git’s object database with the other linked worktrees. Build outputs are a different matter. When agents run Cargo in separate checkouts using the default target directory, each checkout accumulates its own compilation artifacts.
After the cleanup, I measured the space occupied by tracked files and Cargo build output in three worktrees.
| Worktree | Tracked files | target/ |
|---|---|---|
| Source conversion changes | 168 MiB | 104.21 GiB |
| TASTy audit fixes | 161 MiB | 27.76 GiB |
| Issue implementation | 161 MiB | 21.18 GiB |
In the largest example, target/ occupied about 635 times as much space as all tracked files combined. These are measurements of allocated filesystem blocks after different tasks, not the results of a controlled build benchmark.
On the machine running the agents, /tmp is a separate tmpfs mount. At the time of the inventory, it had only about 14 MiB free out of 14.58 GiB. Before starting a build, my agents had to point TMPDIR at a scratch directory on the main disk so tools that honor it had room for temporary files.
The First Approach: Instructions
Before I built the manager, my implementation and review skills told agents to work on a dedicated branch or worktree and preserve unrelated changes. Each agent decided where to put its checkout.
An inventory turned up worktrees nested several levels deep, each with its own build output. Even when the task that owned the outer directory was finished, it was hard to tell whether another task still needed one of the checkouts inside it.
I could spell out exactly where to create a worktree and how to record which task owned it. Following those instructions would still depend on each agent remembering both steps on every run. That’s why I started looking at a dedicated tool that would record ownership as part of creating the worktree.
Moving Operations into Code
I built a Python CLI that creates worktrees and scratch directories and records their owners in SQLite. The implementer uses the same run ID for its checkout and its scratch directory, so it can return to both after review.
The manager registers each new directory as ACTIVE. When the implementer hands off a pull request, it calls wait to mark both resources WAITING. On resume, the manager checks that the paths still point to the original directories before marking them ACTIVE again.
Calling release on an active or waiting run marks its resources RELEASED and leaves their directories on disk. When I run gc --apply --run-id <id>, the collector checks a worktree’s identity, inspects Git for local changes and looks for processes using the directory. A registered workspace nested inside it keeps the outer worktree RELEASED until the child is marked REMOVED. The collector marks a worktree REMOVED only once it confirms the directory is gone.
In one dry run across several projects, 369 of 674 registered resources qualified for removal. The collector counted everything else as blocked, including any resources still marked ACTIVE or WAITING.
When Is a Worktree Safe to Release?
When an implementer opens a pull request, it marks its resources WAITING before it exits. Its checkout can sit clean and idle until a reviewer asks for a fix. Once the coordinator verifies the published review against the commit and confirms the reviewer has stopped, it can release the reviewer’s worktree. The implementer still needs its own. The coordinator calls resume for that run and sends the implementer back to the checkout where its dependencies are already compiled.
Even after approval and a green CI run, I keep the implementer’s worktree. The coordinator releases it when the work is finished and the pull request has been merged or closed, or when I explicitly authorize an earlier release.
Today the coordinator still has to remember one last CLI call after the work is done. I’d move that call into the runtime that schedules the agents, so recording the end of a task also releases its worktree.

