maintaining-macos-health
Hands-on playbook for macOS disk cleanup, dev-machine optimization, and proactive health alerting. Use when the Mac is full or slow, when a kernel panic / watchdog timeout / vm-compressor-space-shortage / Jetsam event happened, when the user asks to free disk space, audit storage
What it does
Maintaining macOS Health
Recovery and prevention playbook for macOS disk and memory crises. Validated against a real watchdog-timeout kernel panic on Apple Silicon caused by vm_compressor segments saturated to 100 % with the disk over 90 % full. The same playbook works for routine cleanup or first-time setup on a new machine.
Table of contents
- When to use
- Skill layout
- Core mental model
- Standard workflows
- Safety rules (non-negotiable)
- Domain quirks captured
- Outcomes scale
When to use
Trigger on any of:
- Disk free < 20 % or user complains about being out of space
- Watchdog-timeout / kernel panic / "no checkins from watchdogd"
- New
JetsamEvent-*.ipswithvm-compressor-space-shortage - "Mac is slow", swap > 6 GB, sustained Critical memory pressure
- User wants to set up monitoring/alerting from scratch
- Migration to a new Mac → restore the same alerter
- General "clean my Mac" / "audit storage" / "free space" requests
Skill layout
| File | Use for |
|---|---|
references/triage.md | First 5 minutes — which signal fired, which tier of cleanup to start with |
references/cleanup-tiers.md | Tiered cleanup playbook (10 tiers, zero-risk → discuss-first), copy-paste-safe shell blocks |
references/never-touch.md | Categories that must not be deleted even under sudo (Mole-derived blacklist + incident-derived additions) |
references/mole-techniques.md | What Mole does that we borrow: marker→target map for mo purge, safe-path validators, age thresholds |
references/alerting.md | Full alerter design: 3 CRITICAL-only triggers, hysteresis, calibration, alerter vs terminal-notifier vs osascript, install/restore commands |
assets/mac-health-check | Production-ready bash script (~250 lines, bash 3.2 compatible) |
assets/com.local.mac-health-check.plist | LaunchAgent plist with StartCalendarInterval (StartInterval is broken on laptops) |
assets/config.sh | Default config with safe thresholds |
Read the relevant reference before acting. Do NOT operate from memory of these files — the details are calibrated to a real incident and small changes break safety.
Core mental model
- Monitor passively — Stats menubar (
brew install --cask stats) — you see issues forming, not just when they explode. - Alert actively — only on truly CRITICAL conditions: disk < 10 %, memory pressure Critical AND swap > 8 GB, or new JetsamEvent with
vm-compressor-space-shortage. Anything else is noise. - Cleanup tiers — start zero-risk (caches, orphan data), only escalate to project artifacts and sudo categories if needed. Mole's
mo purgeandmo cleanare the right primary tools. - Mole is the safety floor — even when running shell commands by hand, follow Mole's path-validation rules: never delete inside
/System,/bin,/usr,/etc,/var/dboutside specific allowlisted subpaths; bin/ only under .NET; vendor/ only under PHP; protect AI/password/VPN/keychain bundle IDs.
Standard workflows
A. "Free space NOW" (incident response)
- Triage — read
references/triage.md, identify which signal fired and how urgent. - Snapshot baseline —
df -h /System/Volumes/Dataand write down free GB. - Tier 1 → 4 sweep — copy from
references/cleanup-tiers.md. Each tier ends with adfcheckpoint. - Run
mo purgeif dev projects exist. Mole's marker-based detection + bin/.NET guard + vendor/PHP guard makes it safer than hand-rolledfind. mo clean --dry-runfor cache categories Mole knows about. Show user before confirming.- Stop at goal — most users target 100 GB free. Don't go below that just for sport.
B. "Set up alerting" (new machine or first time)
- Copy
assets/mac-health-checkto~/bin/mac-health-check(mkdir first; chmod +x). - Copy
assets/com.local.mac-health-check.plistto~/Library/LaunchAgents/. - Copy
assets/config.shto~/.config/mac-health/config.sh(mkdir first). brew install vjeantet/tap/alerter(NOT terminal-notifier — it's broken in 2026 on Sequoia/Tahoe).brew install --cask statsfor passive layer.launchctl load -w ~/Library/LaunchAgents/com.local.mac-health-check.plist.- First run permission prompt: open
alerteronce interactively (alerter --message test) so macOS asks for Notification Center permission. - Tell the user: 7-day calibration is silent (logs only). Edit
config.shafter a week if pattern noisy.
Verify with launchctl list | grep mac-health (should show PID and exit 0) and tail -f ~/Library/Logs/mac-health/health.log.
C. "Already have alerter, but it stopped working / making noise"
Read references/alerting.md § Troubleshooting. Common causes:
- Stuck/old
terminal-notifier(the cask) instead ofalerter— replace. - LaunchAgent not loading after macOS update —
launchctl bootstrap gui/$(id -u) <plist>. - Notifications going to Script Editor — TCC permission was revoked, re-grant.
- Constant alerts during heavy dev work —
touch ~/.config/mac-health/silentto suppress.
D. "Uninstall an app cleanly"
mo uninstall <app> — Mole scans 12+ locations for app traces (Application Support, Containers, Group Containers, Caches, Preferences, Saved State, LaunchAgents, LaunchDaemons, login items, etc.). Always show dry-run first, never bypass.
Safety rules (non-negotiable)
- Never delete without dry-run + user confirmation for any tier ≥ 5 or any sudo operation.
- Never bypass
references/never-touch.md— even if user explicitly asks. Push back, explain the consequence. mo purgeandmo cleanalways with--dry-runfirst. Show estimated reclaim, get confirm.- For Time Machine backups:
tmutil delete <path>, neverrm. TM-tagged paths require thetmutilAPI. - For sudo cleanup of
/Library,/private/var/db/*: only the allowlisted subpaths fromreferences/never-touch.md§ Sudo allowlist. - No auto-cleanup hooks tied to alerts. Alerts notify; user decides. Documented anti-pattern (Google SRE, also confirmed by community 2025-2026 — see
references/alerting.md). - Don't delete swap files.
rm /private/var/vm/swapfile*while running = guaranteed kernel panic.
Domain quirks captured
- macOS Tahoe (26.x) ships
/bin/bash3.2.57.set -u+local var(no init) = unbound on first reference. The shipped script handles this. - LaunchAgent does not inherit user PATH. Plist must declare
EnvironmentVariables.PATHand use absolute paths for interpreters. StartIntervalclock pauses during sleep on Apple Silicon laptops (radar 6630231). UseStartCalendarIntervalwith explicit minute entries (the shipped plist has all 12).terminal-notifieris effectively unmaintained (last release 2019-11) and silently fails on Sequoia/Tahoe Apple Silicon. Usealerterinstead.osascript display notificationfrom launchd attributes to "Script Editor" and is unreliable. Usealerterfrom launchd context.log show --last 6mis too slow (30+ s) for periodic checks. Poll/Library/Logs/DiagnosticReports/JetsamEvent-*.ipsinstead — async write delay is acceptable on a 5-min cadence.JetsamEvent-*.ipsfiles live in/Library/Logs/DiagnosticReports/(system-wide), NOT~/Library/Logs/DiagnosticReports/.- APFS purgeable space lags behind actual deletion by minutes. After cleanup,
dfmay not show the change immediately; wait or rundiskutil info /System/Volumes/Data | grep "Container Free".
Outcomes scale
A representative recovery from a Mac that hit ~8 % free after long memory-pressure sessions on a heavily-loaded dev profile (Docker, multiple AI tools, IDEs, browsers):
- ~25 % of total disk capacity recovered in a 4-hour session
- Largest single contribution: project build artifacts via
mo purge(~30–50 GB across many scan paths) - Stale IDE installations + caches + preferences: ~10 GB
- Docker reclaim (unused images, dead builders, orphan volumes): ~10 GB
~/Downloadsreview (old installers, recordings, archived repos): ~15 GB- Package-manager caches (npm, pnpm, gradle, maven, cargo, brew): ~5 GB
- Sudo-tier cleanup (system logs, vendor-app depots): ~5–10 GB
Active alerter installed with 7-day calibration window; verified via synthetic disk-trigger test before going live. Stats menubar app installed for passive monitoring.
Numbers scale with workload and disk size. Light users will see less; heavy AI/Docker/IDE users will see more.
Capabilities
Install
Quality
deterministic score 0.48 from registry signals: · indexed on github topic:agent-skills · 67 github stars · SKILL.md body (8,972 chars)