---
title: "494 agent worktrees filled a Mac to 100%. What we fixed — lysosome"
description: "Two days after we measured 150 GB of agent worktrees, the same Mac hit 2.7 GB free. What lysosome missed, what changed, and how to clean up on merge."
image: "https://lysosome.dev/og.png"
---

1. [lysosome](/)
2. [Blog](/blog/)
3. Worktrees, two days later

Blog · data-story

# 494 agent worktrees filled a Mac to 100%. What we fixed

Published November 30, 2026 · by lysosome

Remove a git worktree when its pull request merges, not when it has been idle for a month: check that the PR is merged, that the worktree has no uncommitted or untracked files, and that its branch head is the commit the PR merged, then run `git worktree remove` (never `--force`). On the Mac we measure, coding agents created 494 worktrees in two days and filled the disk to 100%, and a 30-day idle rule flagged none of them, because none was a month old. The script for the merge rule is at the end of this post.

## What happened

On November 27 we [measured this Mac](/blog/where-coding-agents-leave-disk-behind): 161 git worktrees holding 150 GB, almost all made by Claude Code. Two days later, on November 29, it had 2.7 GB free of 926 GB. The worktree count had gone from 161 to 494, and they held 336 GB.

It's one machine, one developer running Claude Code in parallel worktrees across a portfolio of repositories. Every number below comes from the `--json` output of lysosome 0.4.1, the version installed that day, or from `du` and `df` where lysosome didn't look. Sizes are in GB (10⁹ bytes).

## Why the idle rule missed all of them

lysosome's default rule calls a worktree dormant after 30 days without activity, and only a dormant, clean, pushed worktree is removable. That rule was written for people, who open a worktree for a long-lived branch and forget it. Agents work the other way: a task takes an hour, its pull request merges the same day, and the worktree, with its own `node_modules` or `target/`, stays.

With the default 30 days, the scan found **0 of 494** worktrees removable. Every one was ACTIVE. Rerun with a 3-day threshold, it found 57 removable (67 GB); 52 were removed and 50.6 GB came back.

A fresh scan later the same day, after that cleanup, shows the shape of the problem:

| Worktrees on November 29 (after the cleanup)       | Count   | Size        |
| -------------------------------------------------- | ------- | ----------- |
| All linked worktrees                               | 466     | 276.4 GB    |
| Touched today                                      | 293     | 126.4 GB    |
| Touched 1 to 7 days ago                            | 164     | 125.2 GB    |
| Touched 8 days ago or more                         | 9       | 24.8 GB     |
| **Merged, clean and pushed**                       | **217** | **84.8 GB** |
| of which: git-ignored build and dependency folders |         | 61.6 GB     |
| Removable under the 30-day rule                    | 0       | 0 GB        |

217 worktrees were finished work: the branch merged, nothing uncommitted, nothing unpushed. They held 84.8 GB, and the idle rule saw none of them, because "merged" and "old" are different questions. For agent worktrees, merged is the one that matters.

## What lysosome got right, and what it missed

The cleanup took the Mac from 2.7 GB to 39 GB free. lysosome did most of it, but an agent had to step in by hand every time lysosome fell short, so here is the full list.

**It got right:** nothing with uncommitted, untracked or unpushed work was touched; everything went to the Trash, not `rm`; every item was re-checked right before it was removed.

**It missed:**

- **Merged worktrees younger than 30 days.** Above: 0 of 494 at the default.
- **Cache sizes were upper bounds.** The dry run planned 15.2 GB of cache cleanup; 2.3 GB was freed. The pnpm store was planned at 7.0 GB and freed 321 MB, because `pnpm store prune` only drops packages nothing references, and agent worktrees reference most of them. Conda was planned at 3.5 GB and freed nothing.
- **A failed command was reported as done.** `brew cleanup -s` printed an error about an untrusted tap, exited, and lysosome recorded the item as "done" with 0 bytes freed.
- **A missing tool meant a skipped cache.** The Yarn cache (1.2 GB) was skipped because `yarn` was no longer on `PATH`; the agent deleted `~/Library/Caches/Yarn` by hand.
- **Workspace worktrees were skipped.** 5 worktrees made by `claude --worktree` at the root of a multi-repo workspace hold a checkout of each sub-repo. lysosome saw a git checkout inside and refused, even though every nested repo was clean and pushed.
- **Trashed isn't freed.** lysosome counted trashed items as freed space, but macOS doesn't give the space back until the Trash is emptied.
- **The scan was too big for an agent.** Scanning the code folder returned 2.5 MB of JSON, too much for an MCP client to read, and a confirmed clean meant typing all 57 item ids back and ran past the client's 120-second timeout.
- **About 132 GB it never looked at.** From `du`: `~/Library/Application Support` 69 GB, `~/Library/Containers` 23 GB, `~/.docker` 21 GB (the `Docker.raw` disk image, which doesn't shrink when you delete images) and `~/Library/Caches` 19 GB.

## What changed in lysosome

Every item on that list is fixed in [lysosome 0.5.1](https://github.com/lysosome-dev/cli/releases/tag/v0.5.1?utm%5Fsource=lysosome.dev&utm%5Fmedium=blog&utm%5Fcampaign=494-worktrees), out on November 30\. From its changelog:

- **Merged worktrees are REMOVABLE at any age**: clean, unlocked, merged into the default branch (or squash-merged, checked through `gh`), and left alone for a day. `--days` now only protects work that isn't merged. A clean worktree whose every commit is pushed and that has no open PR is removable too; an open PR keeps it ACTIVE and names the PR.
- **A running agent session keeps its worktree.** lysosome reads Claude Code's session records and treats any worktree a live session works in as ACTIVE, whatever its idle time, and checks again right before each removal. We added this after the cleanup above removed two clean, pushed worktrees whose sessions had been idle for 5 days but were still running. Nothing was lost, but those sessions were left pointing at a missing folder.
- **Measured sizes.** The dry run measures what pnpm, conda and Homebrew would really free before it shows the plan, and marks anything it can't measure as "up to".
- **Failures say failed.** A cleanup command that prints `Error:` or `fatal:` is reported `failed` with that line, even when it exits 0\. For the Homebrew tap case it names the `brew trust` command to run.
- **A missing tool no longer skips its cache.** When Yarn, npm, bun, pip, uv, Go, Homebrew or CocoaPods is gone from `PATH`, the cache folder goes to the Trash instead.
- **Workspace worktrees** are removable when every nested worktree is, and `clean` removes each one through its own repository before the outer one.
- **Trash is reported separately.** Results show `trashed_bytes`, and `clean --empty-own-trash` empties only what lysosome itself moved to the Trash.
- **Home-folder finders.** A new `app_caches` category covers `~/Library/Caches`, browser and Electron app caches and sandboxed apps' caches. Docker's `Docker.raw` is reported with the space it holds beyond what Docker says it uses (lysosome never touches it).
- **Agent-sized output.** `scan --summary` returns totals and the biggest items instead of every finding, `clean --plan-token` turns a dry run into a token that `clean --plan <token> --yes` cleans exactly, and a long clean over MCP keeps running in the background instead of hitting the client's timeout.

The merge rule is also what our own fleet now runs: a scheduled job on this Mac, built on lysosome, that removes finished worktrees as their work lands. Its first full pass removed 151 of them and took the disk from 47 GB to 91 GB free.

Scanned again with 0.5.1 and its default options the next evening, the Mac had 135 worktrees holding 182.5 GB. 96 of them had a Claude Code session running in them, 3 had an open pull request, and 1 was finished and REMOVABLE. The finished work was gone; what's left is work in progress. And the disk was back down to 41 GB free, because the agents keep building in the worktrees that stay: 83.6 GB of the 182.5 GB is git-ignored build output.

## How to never get there

Cleanup after the disk fills is the wrong time. Chain it to the loop that makes the worktrees.

**1\. Remove a worktree when its pull request merges.** For one repository, with git and a signed-in `gh`. It removes a worktree only when its PR is merged, its branch head is the commit the PR merged (so no work was added after), and `git worktree remove` agrees it is clean:

```
git worktree list --porcelain | awk '/^worktree /{p=$2} /^branch /{sub("refs/heads/","",$2); print p, $2}' |
while read -r path branch; do
  pr=$(gh pr view "$branch" --json state,headRefOid -q 'select(.state=="MERGED") | .headRefOid' 2>/dev/null) || continue
  [ -n "$pr" ] && [ "$pr" = "$(git -C "$path" rev-parse HEAD)" ] || continue
  git worktree remove "$path" && echo "removed $path ($branch)"
done
git worktree prune

```

Squash merges are why it asks `gh` instead of `git branch --merged`: git reports a squash-merged branch as unmerged. Run it from a session-end hook, a post-merge job, or by hand. With lysosome 0.5.1 installed, `lysosome clean --worktrees ~/code` applies the same rule across every repository, skips worktrees with a running agent session, and is a dry run until you add `--yes`.

**2\. Strip build output from the worktrees that stay.** Work in progress still holds most of the space. `lysosome clean --strip-artifacts --tier regenerable_expensive ~/code` takes the git-ignored `node_modules`, `target`, `dist` and similar folders out of worktrees left alone for a day with no session running, and keeps the worktree and every other file in it.

**3\. Run the safe tier every hour, and alarm before the disk is full.** A launchd job on macOS (a systemd timer on Linux) that cleans only what rebuilds by itself and warns when free space drops under a threshold:

```
#!/bin/sh
# ~/bin/lysosome-hourly: regenerable items only, files go to the Trash
lysosome clean ~/code --tier regenerable --yes --progress off
free_gb=$(df -k / | awk 'NR==2 {print int($4 * 1024 / 1e9)}')
[ "$free_gb" -lt 50 ] && osascript -e "display notification \"$free_gb GB free\" with title \"Disk low\""

```

Maintained versions, with a Claude Code `SessionEnd` hook that removes a session's worktree when its PR merges, a Claude Code plugin, a launchd agent, a systemd timer and MCP configs for Claude Code, Claude Desktop, Cursor and Codex, are in the open-source [lysosome integrations folder](https://github.com/lysosome-dev/cli/tree/main/integrations?utm%5Fsource=lysosome.dev&utm%5Fmedium=blog&utm%5Fcampaign=494-worktrees). Each has a README you can follow in two minutes.

**4\. Look outside your code folder once a month.** On this Mac, 132 GB sat in `~/Library` and Docker's disk image. The [Docker guide](/guides/docker-disk-usage-mac) covers shrinking `Docker.raw`; the [worktree guide](/guides/clean-up-git-worktrees) covers the rest of the worktree checks.

## The takeaway

If agents make your worktrees, an idle threshold will never catch up with them: 494 appeared in two days, and none was 30 days old. Tie removal to the merge. On this Mac, the 30-day rule covered none of the 217 finished worktrees (84.8 GB); the merge rule, run on a schedule, removed the finished ones, and the next day's scan found 1 left. Then strip the build output from the ones still in progress, because that's where the space goes next.

Open-source CLI · Mac app: 14-day free trial

## See what your machine is holding.

`lysosome scan` is read-only: it lists dormant worktrees, ignored build output, caches and models with their sizes and a safety label for each. `lysosome clean` is a dry run until you add `--yes`, and files go to the Trash.

`brew install lysosome-dev/tap/lysosome` 

Or `curl -fsSL https://lysosome.dev/install.sh | sh`, or `cargo install --locked lysosome`. Source and releases on [GitHub](https://github.com/lysosome-dev/cli).

## Related

- [Where coding agents leave disk behind, and how to reclaim it](/blog/where-coding-agents-leave-disk-behind)
- [Clean up the git worktrees your coding agents left behind](/guides/clean-up-git-worktrees)
- [Docker disk usage on a Mac: find it and reclaim it safely](/guides/docker-disk-usage-mac)

```json
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "BlogPosting",
      "@id": "https://lysosome.dev/blog/494-agent-worktrees-filled-a-mac#article",
      "headline": "494 agent worktrees filled a Mac to 100%. What we fixed",
      "description": "Two days after we measured 150 GB of agent worktrees, the same Mac hit 2.7 GB free. What lysosome missed, what changed, and how to clean up on merge.",
      "url": "https://lysosome.dev/blog/494-agent-worktrees-filled-a-mac",
      "mainEntityOfPage": "https://lysosome.dev/blog/494-agent-worktrees-filled-a-mac",
      "datePublished": "2026-11-30",
      "dateModified": "2026-11-30",
      "inLanguage": "en",
      "keywords": "remove git worktree after pr merged",
      "articleSection": "data-story",
      "image": "https://lysosome.dev/og.png",
      "author": {
        "@id": "https://lysosome.dev/#org"
      },
      "publisher": {
        "@id": "https://lysosome.dev/#org"
      },
      "isPartOf": {
        "@id": "https://lysosome.dev/blog/#blog"
      }
    },
    {
      "@type": "BreadcrumbList",
      "itemListElement": [
        {
          "@type": "ListItem",
          "position": 1,
          "name": "lysosome",
          "item": "https://lysosome.dev/"
        },
        {
          "@type": "ListItem",
          "position": 2,
          "name": "Blog",
          "item": "https://lysosome.dev/blog/"
        },
        {
          "@type": "ListItem",
          "position": 3,
          "name": "Worktrees, two days later",
          "item": "https://lysosome.dev/blog/494-agent-worktrees-filled-a-mac"
        }
      ]
    },
    {
      "@type": "Organization",
      "@id": "https://lysosome.dev/#org",
      "name": "lysosome",
      "url": "https://lysosome.dev/",
      "logo": "https://lysosome.dev/apple-touch-icon.png",
      "sameAs": [
        "https://github.com/lysosome-dev"
      ]
    }
  ]
}
```
