If your disk keeps filling up
Situations that kept filling my Mac's disk while working with agents, and how I solved them. Find yours, hand the decision to your agent.
I measure each folder by the bytes that come back if it is deleted, not by du. Virtual machines are APFS clones of one template; each pruner runs inside the job that fills that place.
beforevirtual machine disks 96 GB · 12,240 leftover temp folders
aftervirtual machine disks 26.4 GB · 23.3 GB back from temp
measure what deleting a folder really frees, then prune the places AI agents fill: temp folders, Xcode builds and simulators, worktrees, virtual machine disksText for your agent · 38 lines
Situation: several AI agents work on the same Mac. Free space drops by tens of GB a week. du reports folders that add up to more than the disk holds, and deleting a big folder sometimes frees nothing.
Why: on APFS a clone (`cp -c`, git worktrees opened by clone, Chrome's code-sign copies) shares its blocks with the original. du counts every clone at full size, so deleting one clone frees only the blocks it does not share. I had 446 Chrome code-sign copies at 470 GB in du; deleting them freed about 0. A pool of agent worktrees showed 129 GB in du and freed 12 GB. du without `-x` also counts disk images mounted inside a folder: ~/Library/Developer showed 73.5 GB with plain du and 15.5 GB with `du -x`.
These places grow while agents work:
- /private/tmp and $TMPDIR (/var/folders/…/T/): every agent shell and test run leaves a folder there; macOS empties /private/tmp only at startup.
- ~/Library/Developer/Xcode/DerivedData: one full build per project path, so every worktree you build adds a copy.
- ~/Library/Developer/CoreSimulator/Devices and the simulator runtimes: Xcode downloads about 8 GB per iOS version and keeps the old one.
- git worktrees for parallel agents: small if they were opened by clone; a full copy each if they were not.
- virtual machine disks (Disk.img): about 25–35 GB used each. A second machine installed from the same macOS image holds the same system a second time.
- backup and package caches (~/Library/Caches/restic, ~/Library/Caches/org.swift.swiftpm).
Do:
1. Read free space before you delete anything. This is the only number that tells you what came back:
df -k /System/Volumes/Data | awk 'NR==2 {printf "%.1f GB free\n", $4/1048576}'
2. Find the big places. Use `-x` so mounted images are not counted:
du -skx /private/tmp "$TMPDIR" ~/Library/Developer/Xcode/DerivedData ~/Library/Developer/CoreSimulator/Devices ~/Library/Caches 2>/dev/null | sort -n
3. Delete the agent shell folders no process has open. Limit it to folders your agents write: $TMPDIR also holds other apps' folders, and an app that is not running has none open:
for d in /private/tmp/claude-$(id -u)/*/; do lsof +d "$d" >/dev/null 2>&1 || rm -rf "$d"; done
4. Remove Xcode build output and simulators Xcode can no longer use. DerivedData is rebuilt on the next build:
rm -rf ~/Library/Developer/Xcode/DerivedData/*
xcrun simctl delete unavailable
xcrun simctl runtime list
xcrun simctl runtime delete <id of a runtime no device uses>
5. Remove worktrees no agent is using:
git worktree list
git worktree remove <path>
git worktree prune
6. Turn virtual machines into clones of one template. Stop the machine first: a clone of a running disk carries half-written blocks. Clone the disk and its content files from a template of the same macOS version, and keep the machine's own MachineIdentifier and MACAddress:
cd <machine folder>
for f in Disk.img AuxiliaryStorage HardwareModel; do rm -f "$f"; cp -c <template folder>/"$f" "$f"; done
The machine starts fresh from the template and grows only by what it writes.
Verify:
- Run step 1 again. The difference is what you freed. A folder that looked big in du but freed nothing in df was made of clones.
- After step 6, both machines boot, and free space grew by roughly one machine's used size.
Don't: decide what to delete from du alone; it counts clones at full size. Don't prune agent transcripts (~/.claude/projects) or your own recordings: those are your data and cannot be rebuilt. Back them up instead. Don't delete temp folders by age ("older than n days"): age doesn't tell you whether an agent is still using the folder, an open file does.