agentleFS
qiaoshouqingqiaoshouqing/skills/macos-disk-cleanup/SKILL.md

macos-disk-cleanup

Skill1 starsChanged 4 months agoMITView on GitHub

Safely analyze and clean a nearly full macOS disk, with special handling for Git Worktrees, Codex/Claude worktrees, Conductor workspaces, build artifacts, package caches, Xcode/CoreSimulator data, Android AVDs, installers, temporary directories, active processes, and root-owned residues. Use when the user says the Mac disk is full, asks for a deep disk-space analysis, wants cleanup candidates graded by safety, approves P0/high-confidence cleanup, or suspects many project Worktrees are consuming space.

3 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions3 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 3

    1. himynameisben/macos-disk-cleanup★ 34same name
    2. choism4/macos-disk-cleanup★ 2same name
    3. liush2yuxjtu/macos-disk-cleanup-skill★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository6 other files it gives its agents.

The file

Show its rules and text

We split this skill into the rules it gives an agent

28 rules. About 0 are common, 23 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈23

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do not delete during an analysis-only request.

    line 13
  2. Distinctive:

    Never classify a Worktree as finished from age, name, or a clean status alone.

    line 14
  3. Distinctive:

    Before every Worktree removal, require all three:

    line 15
  4. Distinctive:

    no process has a current working directory inside it.

    line 16
  5. Very specific:

    Use git worktree remove <exact-path> without --force, then git worktree prune.

    line 20
  6. Very specific:

    Never run destructive commands against $HOME, ~, a workspace root, a glob, a command substitution, or an unresolved variable.

    line 21
  7. Very specific:

    Do not invoke sudo, change ownership, or weaken permissions automatically.

    line 22
  8. Distinctive:

    Do not delete active caches, open files, personal media, messages, browser profiles, virtual machines, app sessions, common simulators, …

    line 23
  9. Distinctive:

    Read references/cleanup-policy.md when assigning risk tiers, handling Conductor workspaces, or deciding what must remain.

    line 26
  10. Distinctive:

    Start with read-only checks:

    line 30
  11. Distinctive:

    Check SMART status and local APFS snapshots.

    line 33
  12. Distinctive:

    Check Trash without assuming it is large.

    line 35
  13. Distinctive:

    Never chain analysis into deletion unless the user already authorized execution.

    line 39
  14. Distinctive:

    Run the bundled read-only auditor with every main repository root:

    line 45
  15. Very specific:

    Use --sizes only when per-worktree sizing is worth the scan cost.

    line 53
  16. Distinctive:

    When multiple repositories are cleaned concurrently, use at most one removal worker per repository root.

    line 66
  17. Distinctive:

    If Git unregisters a Worktree but leaves root-owned generated files, label it as an unregistered filesystem residue rather than a preserved …

    line 92
  18. Distinctive:

    Create a recovery archive containing source and non-rebuildable files.

    line 99
  19. Very specific:

    Verify the archive with gzip -t, list its members, and confirm every intended workspace root appears.

    line 101
  20. Distinctive:

    Delete only the archived exact roots.

    line 103
  21. Distinctive:

    Do not claim an orphan directory was fully removed when only its user-owned portion disappeared.

    line 106
  22. Distinctive:

    Before deleting each exact cache:

    line 110
  23. Distinctive:

    verify it is not a symlink.

    line 112
  24. Distinctive:

    check for open files and active project roots.

    line 113
  25. Distinctive:

    delete only the exact generated directory.

    line 115
  26. Distinctive:

    verify it is absent or measure the residue.

    line 116
  27. Distinctive:

    verify devices still exist afterward.

    line 124
  28. Distinctive:

    Do not call the cleanup complete until all checks pass:

    line 130

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

macOS Disk Cleanup

Perform a two-phase, evidence-driven cleanup: analyze and rank first, then execute only the scope the user approves. Treat source code, personal data, active developer state, and simulator/device data as protected by default.

Non-negotiable rules

  • Measure live state every run. Never reuse old sizes, process state, PR state, or free-space figures as current truth.
  • Do not delete during an analysis-only request.
  • Never classify a Worktree as finished from age, name, or a clean status alone.
  • Before every Worktree removal, require all three:
    1. no process has a current working directory inside it;
    2. git status --porcelain=v1 --untracked-files=normal is empty;
    3. its HEAD is contained in a verified-current remote main ref, or its matching GitHub PR is merged.
  • Recheck those conditions immediately before deletion. A preflight snapshot is not enough.
  • Use git worktree remove <exact-path> without --force, then git worktree prune. Do not delete branches unless separately requested.
  • Never run destructive commands against $HOME, ~, a workspace root, a glob, a command substitution, or an unresolved variable. Resolve and validate every exact target first.
  • Do not invoke sudo, change ownership, or weaken permissions automatically. Report root-owned residues separately.
  • Do not delete active caches, open files, personal media, messages, browser profiles, virtual machines, app sessions, common simulators, Android AVDs, or data with uncertain recovery value.
  • Preserve dirty worktrees even when their PR is merged or HEAD is in main.

Read references/cleanup-policy.md when assigning risk tiers, handling Conductor workspaces, or deciding what must remain.

Phase 1: Establish live truth

Start with read-only checks:

  1. Record /System/Volumes/Data capacity, used space, free space, and percentage.
  2. Check SMART status and local APFS snapshots. Treat OS update snapshots separately from user-data snapshots.
  3. List active process current working directories with lsof.
  4. Check Trash without assuming it is large.
  5. Measure targeted high-yield paths before broad scans. Prefer gdu, du -x, max-depth scans, and exact known directories over unrestricted recursive scans.
  6. Inspect package/build caches, /private/tmp, the user's per-session /private/var/folders/.../X, developer directories, Downloads installers, and project/worktree roots.

Never chain analysis into deletion unless the user already authorized execution.

Phase 2: Audit Worktrees

Discover the real repository families first. Include ordinary repos and their .codex, .claude, sibling, and /private/tmp worktrees.

Run the bundled read-only auditor with every main repository root:

python3 scripts/audit_worktrees.py --online \
  --root /absolute/path/to/repo-a \
  --root /absolute/path/to/repo-b

Use --sizes only when per-worktree sizing is worth the scan cost. Use --json for machine-readable output.

Interpret classifications conservatively:

  • SAFE_MAIN_CONTAINS: clean, inactive, and HEAD is in a local origin/main that exactly matches live ls-remote.
  • SAFE_PR_MERGED: clean, inactive, and the branch has a merged GitHub PR.
  • KEEP_ACTIVE: a process CWD is inside the Worktree.
  • KEEP_DIRTY: tracked or untracked changes exist.
  • KEEP_CLEAN_UNPROVEN: clean and inactive, but merge/completion proof is missing.
  • KEEP_ACTIVE_UNKNOWN: active-process detection was unavailable; do not delete.

An initially active Worktree may become eligible later only after a fresh audit proves it inactive, clean, and merged/current-main. State this explicitly in the report.

When multiple repositories are cleaned concurrently, use at most one removal worker per repository root. Never run concurrent git worktree mutations against the same repository metadata.

Phase 3: Build a graded plan

Report actual measured sizes and separate overlap where possible.

  • P0 / high confidence: proven-finished Worktrees; inactive generated .next, .open-next, build, dist, DerivedData, package caches; verified installed-app installers; old unregistered temporary copies after source recovery; inactive Xcode caches while preserving devices/runtimes.
  • P1 / conditional: recent temp data, general app caches, browser models, stopped-but-unproven project copies, simulator devices the user may still need.
  • Keep: active/dirty/unproven Worktrees, WeChat/messages, photos/videos, browser profiles, VMs, Claude/Codex sessions, current npm/build caches, common simulators, Android AVDs, and unknown data.
  • Admin-only residue: root-owned generated files that normal permissions cannot remove.

Include a reclaim estimate, but distinguish logical directory totals from APFS free-space change and hardlink-deduplicated totals.

Phase 4: Execute approved P0 in stages

1. Standard Git Worktrees

For each exact candidate:

  1. Re-read active CWDs.
  2. Recheck clean status and unchanged HEAD.
  3. Reconfirm live main containment or merged PR proof.
  4. Run non-force git worktree remove.
  5. Record success, safety skip, or permission failure.
  6. Prune only after removals.

If Git unregisters a Worktree but leaves root-owned generated files, label it as an unregistered filesystem residue rather than a preserved Worktree.

2. Conductor workspaces and unregistered project copies

Preserve every valid Git workspace with changes. For invalid/broken/no-Git workspaces:

  1. Establish the exact directory set and verify none are active or open.
  2. Create a recovery archive containing source and non-rebuildable files.
  3. Exclude rebuildable directories such as node_modules, .next, .open-next, build, dist, .turbo, .dart_tool, coverage, target, Pods, and caches.
  4. Verify the archive with gzip -t, list its members, and confirm every intended workspace root appears.
  5. Revalidate the exact set after archive creation.
  6. Delete only the archived exact roots.
  7. Preserve and measure root-owned residues if deletion is denied.

Do not claim an orphan directory was fully removed when only its user-owned portion disappeared.

3. Generated caches and temporary data

Before deleting each exact cache:

  • verify it is not a symlink;
  • check for open files and active project roots;
  • record allocated size;
  • delete only the exact generated directory;
  • verify it is absent or measure the residue.

For .next, skip the entire repository when a process CWD is within that repository. For npm/Gradle/pnpm caches, recheck running build processes. If a cache regenerates, inspect logs: retain it when it belongs to current activity.

For Xcode/CoreSimulator:

  • preserve installed runtimes and common simulator devices unless the user explicitly approves device deletion;
  • require devices to be Shutdown and no Simulator/xcodebuild/XCTest activity before clearing caches;
  • verify devices still exist afterward.

For installers, confirm the corresponding application/input method is installed and the image is not mounted before deleting the installer.

Phase 5: Verify and report

Do not call the cleanup complete until all checks pass:

  1. Re-run disk usage and report before/after free space and capacity.
  2. Re-run the Worktree auditor. There should be no remaining safe candidate inside the approved scope.
  3. Confirm representative dirty and active Worktrees still exist with their changes.
  4. Confirm recovery archives pass integrity checks and provide clickable paths.
  5. Confirm preserved iOS devices, runtimes, and Android AVDs still exist.
  6. Confirm no cleanup processes remain.
  7. Measure permission residues and current regenerated caches.
  8. Report SMART and snapshot state without deleting OS update snapshots.

Lead with the measured outcome. Then summarize removed categories, protected items, recoverable archives, and any exact blocker requiring administrator authorization.

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.