Skip to main content
command

cleanup-cache — Claude Code command: what it does, how to install

Cleans npm, Homebrew, Yarn, browser, and ML caches to free up drive space. Helps recover storage using three different cleaning modes.

Install into Claude Code · claude-code-templates All methods and platforms ↓
npx claude-code-templates@latest --command utilities/cleanup-cache
Open on GitHub

What cleanup-cache does

The command removes cached files across common development tools using df, du, rm, and find. It checks available root drive space before running npm cache clean --force and brew cleanup, then removes the Yarn cache directory. Once finished, Claude Code prints the updated drive stats alongside the total space freed.

Passing --aggressive expands targets to include caches from desktop browsers, JetBrains IDEs, and pnpm, as well as ML files from PyTorch, Whisper, uv, and Hugging Face. The --maximum flag executes docker system prune -af --volumes to wipe unused containers and volumes, then lists the first 20 node_modules folders for manual review.

Cache targets rely directly on macOS directory conventions like ~/Library/Caches. Running this command on standard Linux environments will harmlessly skip missing browser and Yarn paths.

What it helps with

  • Free disk space by clearing npm, Yarn, and Homebrew package manager caches
  • Remove accumulated browser cache files from Chrome, Firefox, Opera, and Arc
  • Wipe temporary directories left by JetBrains IDEs, pnpm, Puppeteer, and Selenium
  • Reclaim storage by deleting cached Hugging Face, PyTorch, and Whisper models
  • Prune unused Docker containers and volumes before manually reviewing node_modules

Example prompts for the agent

  • Clean standard package manager caches using /cleanup-cache
  • Delete browser and machine learning model caches with /cleanup-cache --aggressive
  • Trigger a deep cleanup including unused Docker resources via /cleanup-cache --maximum

How to install cleanup-cache

1claude-code-templates

npx claude-code-templates@latest --command utilities/cleanup-cache

2Manually: put the files in place

.claude/commands/cleanup-cache.md

Call it with /cleanup-cache. For all projects use ~/.claude/commands/

Questions about cleanup-cache

How to install cleanup-cache in Claude Code?

Run npx claude-code-templates@latest --command utilities/cleanup-cache in your terminal. This command places the template into .claude/commands/cleanup-cache.md.

What does the cleanup-cache command do?

It checks available drive space before and after execution while removing cached data from package managers, desktop browsers, dev tools, or Docker.

What is the difference between --aggressive and --maximum?

The --aggressive flag purges browser, IDE, and machine learning caches, whereas --maximum also runs docker system prune -af --volumes and lists node_modules directories for manual inspection.

Source text

cleanup-cache.md · MIT
---
allowed-tools: Bash(df:*), Bash(du:*), Bash(npm cache clean:*), Bash(brew cleanup:*), Bash(rm:*), Bash(find:*), Bash(docker system prune:*)
argument-hint: "[--aggressive] | [--maximum]"
description: Clean system caches (npm, Homebrew, Yarn, browsers, Python/ML) to free disk space
---

# System Cache Cleanup

Clean temporary files and caches to free disk space: $ARGUMENTS

## Current Disk Usage

- **Disk space**: !`df -h / | tail -1`
- **npm cache**: !`du -sh ~/.npm 2>/dev/null || echo "Not found"`
- **Yarn cache**: !`du -sh ~/Library/Caches/Yarn 2>/dev/null || echo "Not found"`
- **Homebrew cache**: !`brew cleanup -n 2>/dev/null | head -5 || echo "Homebrew not installed"`

## Cleanup Options

Based on the arguments provided, execute the appropriate cleanup level:

### Option 1: Conservative Cleanup (default)

Safe cleanup of package manager caches that can be easily rebuilt:

```bash
# Record starting disk space
echo "Starting cleanup..."
df -h / | tail -1 | awk '{print "Before: " $4 " free"}'

# Clean npm cache
echo "Cleaning npm cache..."
npm cache clean --force

# Clean Homebrew
echo "Cleaning Homebrew..."
brew cleanup

# Clean Yarn cache
echo "Cleaning Yarn cache..."
rm -rf ~/Library/Caches/Yarn

# Show results
df -h / | tail -1 | awk '{print "After: " $4 " free"}'
```

### Option 2: Aggressive Cleanup (--aggressive flag)

Includes all conservative cleanup plus browser and development tool caches:

```bash
# Run conservative cleanup first (from Option 1)
npm cache clean --force
brew cleanup
rm -rf ~/Library/Caches/Yarn

# Clean browser caches
echo "Cleaning browser caches..."
rm -rf ~/Library/Caches/Google
rm -rf ~/Library/Caches/com.operasoftware.Opera
rm -rf ~/Library/Caches/Firefox
rm -rf ~/Library/Caches/Mozilla
rm -rf ~/Library/Caches/zen
rm -rf ~/Library/Caches/Arc

# Clean development tool caches
echo "Cleaning development caches..."
rm -rf ~/Library/Caches/JetBrains
rm -rf ~/Library/Caches/pnpm
rm -rf ~/.cache/puppeteer
rm -rf ~/.cache/selenium

# Clean Python/ML caches
echo "Cleaning Python/ML caches..."
rm -rf ~/.cache/uv
rm -rf ~/.cache/huggingface
rm -rf ~/.cache/torch
rm -rf ~/.cache/whisper

# Show results
df -h / | tail -1 | awk '{print "After aggressive cleanup: " $4 " free"}'
```

### Option 3: Maximum Cleanup (--maximum flag)

Includes all aggressive cleanup plus Docker and old node_modules:

```bash
# Run aggressive cleanup first (from Option 2)
npm cache clean --force
brew cleanup
rm -rf ~/Library/Caches/Yarn
rm -rf ~/Library/Caches/{Google,com.operasoftware.Opera,Firefox,Mozilla,zen,Arc,JetBrains,pnpm}
rm -rf ~/.cache/{puppeteer,selenium,uv,huggingface,torch,whisper}

# Clean Docker (if installed)
echo "Cleaning Docker..."
docker system prune -af --volumes 2>/dev/null || echo "Docker not running or not installed"

# List node_modules directories for manual review
echo "Finding node_modules directories..."
echo "Note: Not auto-deleting. Review and delete manually if needed."
find ~ -name "node_modules" -type d -prune 2>/dev/null | head -20

# Show results
df -h / | tail -1 | awk '{print "After maximum cleanup: " $4 " free"}'
```

## Execution Steps

1. **Determine Cleanup Level**
   - No arguments or empty: Run Conservative Cleanup (Option 1)
   - `--aggressive`: Run Aggressive Cleanup (Option 2)
   - `--maximum`: Run Maximum Cleanup (Option 3)

2. **Safety Checks**
   - Verify sufficient permissions
   - Ensure critical applications are closed (browsers for Option 2+)
   - Warn about Docker containers being removed (Option 3)

3. **Execute Cleanup**
   - Run appropriate commands based on the selected option
   - Show progress for each cleanup step
   - Handle errors gracefully (missing directories, permissions)

4. **Report Results**
   - Display disk space before and after
   - Show amount of space recovered
   - List what was cleaned
   - Provide recommendations if more space is needed

## Important Notes

**Conservative Cleanup** (default):
- ✅ Always safe to run
- ✅ Caches rebuild automatically when needed
- ✅ No application impact

**Aggressive Cleanup** (--aggressive):
- ⚠️ Close browsers before running
- ⚠️ Browser caches will rebuild on next use
- ⚠️ ML models will re-download if needed

**Maximum Cleanup** (--maximum):
- ⚠️ Stops and removes all Docker containers/images
- ⚠️ Only deletes node_modules after manual review
- ⚠️ Most impactful but recovers the most space

## Recovery

All cleaned caches are temporary and will rebuild automatically:

- **npm/Yarn**: Rebuilds on next `npm install`
- **Homebrew**: Downloaded on next `brew install`
- **Browsers**: Rebuilds on next browsing session
- **Python/ML**: Re-downloads models on next use
- **Docker**: Pull images again with `docker pull`

## Example Usage

```bash
# Conservative cleanup (default)
/cleanup-cache

# Aggressive cleanup
/cleanup-cache --aggressive

# Maximum cleanup
/cleanup-cache --maximum
```

After cleanup, verify the results and inform the user of:
1. Space freed
2. Current free space
3. What was cleaned
4. Whether additional cleanup is recommended

© davila7 · MIT · davila7/claude-code-templates

Similar slash commands

All slash commands for DevOps and infrastructure →

From the same set361

The whole set →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor