Aggressive but safe disk cleanup for macOS developer machines. Designed for developers who work with lots of git worktrees.
Cleans system caches, Docker resources, per-project build artifacts, and stale worktrees/branches for closed GitHub issues — with multiple safety nets to prevent data loss.
System-level:
- Homebrew, npm, pnpm, pip, bun, uv caches
- HuggingFace cache (info only — interactive cleanup recommended)
- Docker (containers >24h, dangling images, unused volumes, build cache)
- VS Code extension caches
- System logs >30 days old
- Stale
/tmpclones from dev tools (PR reviews, issue work)
Per-project (auto-detected):
node_modules,.next- Python caches (
__pycache__,.pytest_cache,.ruff_cache,.mypy_cache) >14 days - Python virtualenvs (
venv,.venv) >7 days - Rust
target/directories >7 days - Java/Kotlin
build/,.gradle/ - Git maintenance (
gc --auto,worktree prune)
Worktree cleanup (requires gh CLI):
- Removes worktrees for closed GitHub issues (
.loom/worktrees/issue-*) - Deletes local feature branches for closed issues (
feature/issue-*) - Kills stale Loom tmux sessions (
loom-*)
- Age thresholds — never deletes files modified within N days (configurable)
- Open-handle check (
lsof) — skips directories with active processes - Active worktree check — never touches files inside live git worktrees
- GitHub issue check — only cleans worktrees/branches for CLOSED issues
- Uncommitted changes — skips worktrees with uncommitted work
- Tool-native commands — uses
cargo clean,uv cache prune, etc. overrm -rf - Pattern matching — only known cache/temp patterns, never source code
git clone https://github.com/rjwalters/clean.git ~/GitHub/clean
# Symlink to PATH
ln -s ~/GitHub/clean/cleanup.sh /usr/local/bin/cleanupcleanup # Run cleanup
cleanup --check # Preview what would be cleaned (dry run)
cleanup --aggressive # Also run 'docker system prune -af --volumes'
cleanup --system-only # Skip per-project cleanup
cleanup --help # Show detailed helpThe script auto-detects your project directory by checking (in order):
CLEAN_PROJECT_DIRenvironment variable~/GitHub~/Projects~/repos~/src
Override with:
CLEAN_PROJECT_DIR=~/code cleanupEdit the variables at the top of cleanup.sh:
| Variable | Default | Description |
|---|---|---|
VENV_AGE_DAYS |
7 |
Min age before cleaning virtualenvs |
TMP_AGE_HOURS |
1 |
Min age before cleaning /tmp clones |
PYCACHE_AGE_DAYS |
14 |
Min age before cleaning Python caches |
TARGET_AGE_DAYS |
7 |
Min age before cleaning Rust target dirs |
This tool is built for workflows that use git worktrees for issue-based development (e.g., Loom). The worktree cleanup section:
- Scans each repo for
.loom/worktrees/issue-*directories - Checks the corresponding GitHub issue status via
gh issue view - Only removes worktrees where the issue is CLOSED
- Skips worktrees with uncommitted changes
- Cleans up orphaned
feature/issue-*branches for closed issues
- macOS (uses
stat -f,~/Librarypaths, macOSdateflags) - gh CLI (optional, for worktree/branch cleanup)
MIT