Dan Romero

Mac disk cleanup for iOS developers

Updated

A prompt that has a coding agent measure what fills a Mac’s disk, then clear it without losing work. Written for iOS development, where simulators and build output take most of the space.

979 words

Help me free disk space on this Mac without losing work. Measure first and delete nothing until I’ve chosen what goes. If you need something from me, such as where I keep my code, ask in one short message.

Rules

Measure

Start with free space, then a ranked map. -x keeps du on the real volume. This takes about a minute:

df -h /System/Volumes/Data
du -xhd 2 ~ 2>/dev/null | sort -rh | head -40

Then the places iOS development fills:

du -xsh ~/Library/Developer/Xcode/{DerivedData,Archives,"iOS DeviceSupport"} \
  ~/Library/Developer/CoreSimulator/{Devices,Caches} ~/Library/Caches 2>/dev/null
xcrun simctl runtime list

Simulators by size and last use:

xcrun simctl list devices -j | python3 -c '
import json, sys
for runtime, devices in json.load(sys.stdin)["devices"].items():
    for d in devices:
        print("%5.1f GB  %-9s %-10s  %s  %s" % (d.get("dataPathSize", 0) / 1e9, d["state"], d.get("lastUsedAt", "never")[:10], d["name"], d["udid"]))
' | sort -rn

In each folder where I keep code, list build output and dependencies: DerivedData folders inside projects, .build, node_modules, Pods, Python virtual environments, tmp folders, and Git worktrees (git worktree list), with each worktree’s last commit and whether its branch is merged.

Numbers that mislead

Report

Group what you found into three tiers, biggest first, each item with its size, why it’s in that tier, and the command that would clear it:

  1. Clear freely: rebuilds or re-downloads. DerivedData, stale build folders, caches of apps that aren’t running, simulators whose runtime is gone.
  2. Check first: costs something to lose. Simulators with app data, device support for iOS versions my devices still run, archives, test results, dependencies without a lockfile, worktrees with uncommitted changes.
  3. Leave alone: in use or personal.

Then ask which items to clear, and stop.

Simulators

These usually hold most of the space:

find ~/Library/Developer/CoreSimulator/Devices/<udid>/data/Library/Application\ Support/PRBPosterExtensionDataStore \
  -type d -name SnapshotCache.cachedb -prune -exec rm -rf {} +

Outside Xcode

Leave these out

After clearing

Scan again a few minutes later, report what came back, and run git status in each repository you cleared from.

Keep it from coming back

Offer to set these up, and add them to each project’s AGENTS.md or CLAUDE.md so other agents follow them: