agentleFS
servitolaservitola/dotfiles/macos_cleanup/AGENTS.md

dotfiles / macos_cleanup

AGENTS.md16 starsChanged 48 days agoMITView on GitHub

  • Reads credentials
  • Deletes or force-pushes

The file

We found no rules to list in this file: it reads as prose or reference rather than instructions.

Files
AGENTS.md

macos_cleanup — "where_is_my_space" macOS cache/junk cleanup scripts

  • cleanup_all.sh is the entry point: flushes DNS, rebuilds zsh completion cache, sources cleanup_targets.sh, then prunes Homebrew Caskroom installers, the uv cache, Docker, Trash, Atuin DB (VACUUM), and various app caches (GeForce NOW, Battle.net, Steam, DriveFS, GlobalProtect).
  • deep_clean.sh (alias deepclean, -n for a dry run, optional repo roots as arguments) is the rare, deliberate half and is never run by up. Every step costs a re-download, a rebuild or lost local state, so each prints what it frees and the price, then waits for y + Enter: NuGet locals, the whole uv cache, npm cache, Go build + module cache, build output in repositories, iOS simulator erase, docker system prune -a, reflog expiry + git gc --aggressive. It replaced the AGGRESSIVE=true section of cleanup_all.sh.
    • Repositories are not cleaned with git clean -dfx. Measured over ~/projects (165 repos, 27 GB), that command would also delete every ignored .env, local SQLite databases, trained models, karabiner.json and the Claude Code transcripts under claude-code/ — ignored is not the same as regenerable. A directory goes only if git ignores it and its name is in ARTIFACT_NAMES (bin obj node_modules build dist target .venv …); that keeps ~8 GB of the 27 and loses nothing that cannot be rebuilt. A directory some live process was started from is kept and listed as in use. The dotfiles repo itself is skipped entirely: ~/.claude is a symlink into it, so its ignored directories are live tool state.
  • uv keeps the environment of a uv run script.py service inside its cache (environments-v2), so both uv cache prune --force here and uv cache clean in deep_clean.sh delete it under the live launchd shims; the process survives until its next lazy import and then answers 500 with ModuleNotFoundError. restart_services_with_deleted_uv_env in helpers.sh runs after either and kickstarts exactly the launchd jobs whose interpreter path no longer exists.
  • cleanup_targets.sh is the declarative target list — mostly try_clean/try_clean_aged/try_clean_pattern calls grouped (Caches / Gaming / Development / Applications / System / Patterns). The Patterns section deletes .DS_Store (single find ~ pass, prunes Library/.Trash/node_modules/.git, 30s timeout) and .AppleDouble files.
  • try_clean.sh defines try_clean <dir> <label> [exclude], the two age-gated variants below, and try_clean_pattern <base> <d|f> <pattern> <label>; all size-measure, skip missing/empty dirs, and report. helpers.sh provides the spinner (spinner_start/spinner_stop) and format_size.
  • Age gating protects work in flight: nothing modified within CLEANUP_KEEP_DAYS (default 2, overridable from the environment) is removed. Which of the two shapes a target gets depends on what a top-level entry means, and picking wrong either corrupts a cache or frees nothing:
    • try_clean_aged <dir> <label> [exclude] [days] — entry is one self-contained unit of work, so it lives or dies whole. Used for the three Caches roots, JetBrains caches, DerivedData, Android SDK/NPX/pre-commit caches, Steam temp+downloads, work bins. The freshness probe is a recursive find -type f, not a stat of the entry: a directory's own mtime doesn't move when a nested file changes (an in-flight build would read as stale) and does move on every add/remove (a bag of ancient junk would read as fresh) — it lies in both directions. A find that exits non-zero (unreadable subtree) is read as "in use" and kept.
    • try_clean_aged_files <dir> <label> [days] — entry is a bag of independently replaceable artifacts, so the unit is the file; empty dirs are pruned afterwards. Used for ~/.gradle/caches, the NuGet v3-cache, the /private/var/folders/…/T xdb logs. Whole-unit gating is actively useless here: one warm jar in modules-2 would pin the other several GB forever. Note ! -mtime -$DAYS, not -mtime +$DAYS — the latter truncates to whole days and spares an extra day's worth (verified: a 49h-old file is missed by +2).
  • Two rules that look like candidates and are not. App caches (~/Library/Caches/<bundle>, browser/Electron CEF dirs) must never move to the per-file shape — a fresh index referencing stale data files is a state apps handle worse than an absent cache, which is what plain try_clean gives them. And the hot Electron caches (Discord/Obsidian/Claude/Vivaldi) stay on plain try_clean entirely: rewritten constantly, so any gate keeps everything and frees nothing, and they regenerate cheaply. Measured cost of the safety rule on ~/Library/Caches: ~270 MB (14%) of stale bytes stay pinned inside live apps' bundles.
  • broken_links.sh defines report_broken_links (called from the always-run "Dangling Symlinks" section): scans $HOME (pruning Library/node_modules/.git/.Trash/.cache/.npm/dosdevices, plus foreign filesystems mirrored into $HOME that only look broken from the host: OrbStack container roots and */etc/ssl/certs server-rootfs mirrors) plus /opt/homebrew/{bin,sbin,etc} and /usr/local/bin for dangling symlinks (target deleted/renamed — e.g. a removed app's leftover link, or a renamed dotfiles target), using find … -type l ! -exec test -e {} \;. Report-only by default, flagging links into ~/projects/dotfiles with [dotfiles]; set PRUNE_BROKEN_LINKS=true to rm them (a dangling symlink is pure junk). NB: "broken hardlinks" don't exist — a hardlink keeps the inode alive — so only symlinks are scanned.
  • Invariant: cleanup is destructive but conservative — missing/empty/running-app targets are skipped silently, never failed. Safety options: setopt no_unset pipe_fail at the top (a typo'd variable can never expand to "" inside an rm path); err_exit is deliberately NOT set, matching the skip-silently design.
  • Invoked three ways: locally via up (alias → macos/update_all_and_cleanup_all.sh, which runs macos_update/update_all.sh then cleanup_all.sh as child zsh processes — not sourced, so the safety setopts can't leak into the interactive shell); directly; or remotely via clean.sh (curl bootstrap that downloads the five sourced scripts to a tmpdir and sources cleanup_all.sh with CLEANUP_DIR set — safe there because the curl pipe runs in its own zsh process). It does its own sudo -v.
  • Relation to macos_update/: update_all.sh does package/tool updates (brew, npm, uv, docker, etc.); this dir does only deletion. They are independent — up chains update → cleanup. Files are tracked by the repo Makefile (not symlinked).

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.