lysosome

Blog · data-story

Where coding agents leave disk behind, and how to reclaim it

Published · by lysosome

Coding agents mostly leave disk behind in git worktrees, and the worktree itself is the small part: on the machine we measured, 161 worktrees held 150 GB, and 68 GB of that was node_modules, dist and other build output installed inside them. Most of it was a week old or less, so it wasn't forgotten yet, just piling up. The fix that frees the most space without touching anyone's work is to keep the worktrees and delete only their ignored build folders, then remove the worktrees whose branches are merged.

What we measured

On November 27, 2026 we ran the read-only lysosome worktrees and lysosome caches scans on the Mac this product is built on. It belongs to one developer who runs Claude Code in parallel worktrees all day, across a portfolio of about two dozen repositories. It's one machine, not a survey, but every number below comes straight from the scan's --json output. Sizes are in GB (10⁹ bytes).

Worktrees Count Size
Created by Claude Code (<repo>/.claude/worktrees/) 155 146.6 GB
Created by scripts in ~/.worktrees/ 6 3.1 GB
All linked worktrees 161 149.8 GB
of which: git-ignored build and dependency folders inside them 68.1 GB

They were spread over 22 repositories; the busiest one had 32 worktrees. The median worktree took 0.28 GB and the largest took 18.1 GB, so a handful of big ones (with a full dependency install and build output) do most of the damage.

Most of it is recent, and that is the problem

The usual advice is "delete the old ones". Here, almost nothing was old:

Last activity Worktrees Size Build output inside Already merged
Today 89 53.0 GB 23.9 GB 37
1 to 7 days ago 55 50.1 GB 29.5 GB 12
7 to 14 days ago 2 18.7 GB 1.3 GB 1
14 to 30 days ago 11 26.5 GB 11.9 GB 1
30+ days ago 4 1.5 GB 1.5 GB 3

With the default rule (a worktree is dormant after 30 idle days), only 3 worktrees, 1.5 GB, were safe to remove: idle, clean and merged. One more was idle but had an untracked file, so it went to REVIEW. Everything else was still "active".

Agents create worktrees faster than any reasonable idle threshold expires them. 144 of the 161 had been touched in the past week, and at least 54 were on branches that were already merged. A task finishes, the pull request merges, and the worktree, with its own full npm install or cargo build, stays on disk until someone notices.

Worktrees are not the only thing agents fill

The same machine's caches and tool data, from lysosome caches:

Category Size
Xcode (DerivedData, simulator runtimes, archives) 42.7 GB
Package manager caches (pnpm store, npm, conda, Gradle, Homebrew, Yarn and others) 25.5 GB
Docker images and volumes 10.4 GB
Android emulators and system images 8.9 GB

Agents add to these too: every worktree that runs npm install or a fresh build warms the shared caches. But caches are shared and rebuildable, and each tool has its own cleanup command. The worktree builds are per task and duplicated: the same dependency tree installed a dozen times.

How to reclaim it without losing work

1. Strip build output from worktrees, keep the worktrees. This is where the space is, and it is the safest step: dependency and build folders come back with the next install or build. By hand, in a worktree you aren't using right now:

git -C <worktree> check-ignore -q node_modules && rm -rf <worktree>/node_modules

With lysosome, for every worktree idle 7 days or more (a dry run until you add --yes, and files go to the Trash):

lysosome clean ~/code --strip-artifacts --tier regenerable_expensive --days 7

2. Remove the worktrees whose work is done. A worktree is safe to remove when git status is clean and its commits are merged or pushed. git worktree remove <path> (never --force) refuses dirty ones. Squash merges are the trap: git reports a squash-merged branch as unmerged, so check the pull request. lysosome worktrees ~/code --days 7 runs those checks across every repository, including the squash-merge lookup through your signed-in gh, and labels each worktree REMOVABLE or REVIEW with the reason. The worktree guide walks through both.

3. Prune stale records. When a worktree folder is deleted by hand, the repository keeps a record of it. This machine had 61 such records in 4 repositories. They take no real space, but they clutter git worktree list. git worktree prune clears them.

4. Then look at caches. Xcode DerivedData and old simulator runtimes were the largest single items here. The Xcode guide covers which are safe to delete.

The takeaway

If you run agents in worktrees, measure the build output inside them, not just the worktree count. On this machine, stripping that output from worktrees idle a week or more (17 worktrees) would free about 15 GB today, with no worktree, branch or commit touched. Removing the merged ones as their pull requests land keeps the rest from piling up.