agentleFS
justinwilliamesjustinwilliames/skills/disk-cleanup/SKILL.md

disk-cleanup

Skill1 starsChanged 5 months agoMITView on GitHub

Reclaim disk space on a Mac running heavy Claude Code workloads: scan, classify by risk, verify nothing live is using a target, purge staged, prove the result with df. Trigger on "disk is full", "clean up storage", "free up space", "disk cleanup", "/disk-cleanup", "storage almost full", or any macOS low-disk warning. Also covers the follow-on RAM/swap health check. Do NOT use for cleaning a single repo's build artifacts mid-task (just delete them), or for pruning agent memory files.

26 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use meta, api-design and 2 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • demithrasSkill

    meta

    Strategic decision analysis using CLEAR META framework. Use for architecture decisions, technology selection, strategic trade-offs.

    Also in 3 projects that use this

  • MicrosoftSkill

    api-design

    Guide for designing and documenting RESTful APIs. Use when asked to design an API, create endpoints, or document an API.

    Also in 3 projects that use this

  • GoogleSkill

    tdd

    Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.

    Also in 3 projects that use this

  • MicrosoftSkill

    release

    Use ONLY when the user explicitly asks to cut/publish a Huabu desktop release or tag a version. Performs an outward action — bumps the version in apps/desktop/package.json, commits + annotated-tags vX.Y.Z, and pushes the branch + tag. That tag push auto-builds the macOS/Windows installers and publishes a GitHub Release. Provides `status`, `bump`, `tag-push`, and a one-command `run` (bump → tag-push).

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 19 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Run scripts/disk-sweep.sh scan first — it produces the full inventory in one shot.

    line 18
  2. Very specific:

    Scratchpads: only UUID-named session dirs at depth 2 qualify — a bare glob also catches shared dirs like bundled-skills/ (observed).

    line 68

“Common” is measured: kept by at least 6 in 10 of the 19 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Disk Cleanup

The protocol: scan → classify by risk → check live consumers → purge in stages → prove with df. Nothing is deleted before its risk tier is known and its liveness checked. Nothing above Tier 1 is deleted without the user's explicit go.

Run scripts/disk-sweep.sh scan first — it produces the full inventory in one shot. scripts/disk-sweep.sh sweep executes Tier 1 only, with the liveness gates built in (suitable for a weekly launchd/cron job).

Ground truth first

  • Free space = df -h /System/Volumes/Data. NEVER df / — that's the sealed system snapshot and reads wildly wrong (12GB used vs a real 180GB, observed in practice).
  • A full disk breaks the scan itself: du/sort write temp files and fail with "no space left on device". If that happens, purge a known Tier 1 target immediately (npm cache is the fastest safe win), then resume scanning.
  • Swap health while you're here: sysctl vm.swapusage. Swap used beyond physical RAM means the real problem is memory residency, not disk — see "Swap follow-on" below.

Risk tiers

TierTargetsGate
1 — regenerable, purge on request~/.npm (npm cache clean --force), ~/.cache/* (tool runtimes, uv, puppeteer, prisma, pre-commit), idle ~/Library/Caches/* (Homebrew + brew cleanup --prune=all, playwright browsers, *.ShipIt updater blobs, pip, swiftpm), Swift/Xcode .build dirs, dead-session scratchpads under /private/tmp/claude-<uid>Liveness check only
2 — recoverable elsewhere, confirm firstClaude agent vm_bundles (re-downloaded on demand), stale local repos (see repo gate), stale-repo node_modules, stale .claude/worktreesExplicit yes per category
3 — history, confirm + protect~/.claude/projects transcripts, desktop-app session storesPinned-session protection (below); never touch app session stores while Claude Desktop runs
NeverCaches of currently-running browsers/apps (open handles), anything with unpushed commits or unrescued dirty files, agent memory dirs, the current session's own scratchpad/transcript—

Liveness gates (the step that makes this safe)

  1. Open handles: lsof +D <target> — empty means safe. One open _logs file in ~/.npm is fine (npm cache clean doesn't touch logs).
  2. Active builds: ps aux | grep -E 'swift-build|xcodebuild|npm (install|ci)'.
  3. Peer sessions: list running Claude sessions, then map each process's cwd via lsof -a -p <pid> -d cwd. No live session may sit inside a deletion target.
  4. Zombie-freshness trap: a scratchpad can look "recently modified" solely because an orphaned dev server is still writing logs into it (observed: three next-servers from one dead session pinning 4.4GB). Detect orphans by a log/cwd path pointing into a dead session's scratchpad; kill the process tree (the next-server parent, not just its workers), then delete. Kill-verify: ps -p <pid> after, not just kill's exit.

Category-specific gates

  • Repo deletion (Tier 2): all three or no delete — git status --porcelain empty, git log --branches --not --remotes empty, git ls-remote origin succeeds. A repo failing any check gets its node_modules stripped instead, never the repo.
  • Worktrees: git worktree list first; inspect dirty/untracked files — rescue unique artifacts into the main repo before git worktree remove --force + git worktree prune. Commits on worktree branches survive removal (shared .git); only uncommitted/untracked content is at risk.
  • Transcripts (Tier 3): find protected session UUIDs by grepping their titles in the desktop app's session store (~/Library/Application Support/Claude/claude-code-sessions/), then prune *.jsonl -mtime +7 excluding those UUIDs and the current session's. Verify survivors after. Automation should use +60 days — a paused-but-pinned session can sit untouched for weeks.
  • Scratchpads: only UUID-named session dirs at depth 2 qualify — a bare glob also catches shared dirs like bundled-skills/ (observed). Double gate: no file modified in 2 days AND no open handles. Current session always excluded.

Verification (no claim without this)

  • Freed space: df -h /System/Volumes/Data before and after, reported as numbers ("1.3GB → 39GB free"), never as "cleaned up".
  • Protected sessions: after a transcript prune, find the protected UUIDs and report the count found.
  • Kills: ps -p on every killed pid.

Escalation

  • Purge done but disk still tight → the remaining levers are Tier 3 app session stores (quit Claude Desktop first) and a storage audit outside the Claude footprint.
  • Disk fine but machine slow → swap follow-on: check vm.swapusage; the fixes are closing idle Claude sessions (each is a resident process), killing orphaned dev servers, running one browser instead of two, and a restart to drain swap. Physical RAM is the hardware ceiling — say so rather than promising software fixes.

Sync home

Sync home: this repo (github.com/justinwilliames/skills) is a sanitized distribution copy; the canonical copy lives in the author's private live library.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.