Skip to content

Commit 5cd0bc1

Browse files
davila7claude
andcommitted
feat: Add /cleanup-cache command for system cache cleanup
Add comprehensive cache cleanup command with three levels: - Conservative: npm, Homebrew, Yarn (~10GB) - Aggressive: adds browsers, Python/ML caches (~25GB) - Maximum: adds Docker, lists node_modules (~29GB+) Features: - Shows disk space before/after cleanup - Safe defaults with optional --aggressive and --maximum flags - Handles missing directories gracefully - Compatible with macOS system caches 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 219e5ba commit 5cd0bc1

File tree

2 files changed

+943
-733
lines changed

2 files changed

+943
-733
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
allowed-tools: Bash(df:*), Bash(du:*), Bash(npm cache clean:*), Bash(brew cleanup:*), Bash(rm:*), Bash(find:*), Bash(docker system prune:*)
3+
argument-hint: [--aggressive] | [--maximum]
4+
description: Clean system caches (npm, Homebrew, Yarn, browsers, Python/ML) to free disk space
5+
---
6+
7+
# System Cache Cleanup
8+
9+
Clean temporary files and caches to free disk space: $ARGUMENTS
10+
11+
## Current Disk Usage
12+
13+
- **Disk space**: !`df -h / | tail -1`
14+
- **npm cache**: !`du -sh ~/.npm 2>/dev/null || echo "Not found"`
15+
- **Yarn cache**: !`du -sh ~/Library/Caches/Yarn 2>/dev/null || echo "Not found"`
16+
- **Homebrew cache**: !`brew cleanup -n 2>/dev/null | head -5 || echo "Homebrew not installed"`
17+
18+
## Cleanup Options
19+
20+
Based on the arguments provided, execute the appropriate cleanup level:
21+
22+
### Option 1: Conservative Cleanup (default, ~10GB)
23+
24+
Safe cleanup of package manager caches that can be easily rebuilt:
25+
26+
```bash
27+
# Record starting disk space
28+
echo "Starting cleanup..."
29+
df -h / | tail -1 | awk '{print "Before: " $4 " free"}'
30+
31+
# Clean npm cache
32+
echo "Cleaning npm cache..."
33+
npm cache clean --force
34+
35+
# Clean Homebrew
36+
echo "Cleaning Homebrew..."
37+
brew cleanup
38+
39+
# Clean Yarn cache
40+
echo "Cleaning Yarn cache..."
41+
rm -rf ~/Library/Caches/Yarn
42+
43+
# Show results
44+
df -h / | tail -1 | awk '{print "After: " $4 " free"}'
45+
```
46+
47+
### Option 2: Aggressive Cleanup (--aggressive flag, ~25GB)
48+
49+
Includes all conservative cleanup plus browser and development tool caches:
50+
51+
```bash
52+
# Run conservative cleanup first (from Option 1)
53+
npm cache clean --force
54+
brew cleanup
55+
rm -rf ~/Library/Caches/Yarn
56+
57+
# Clean browser caches
58+
echo "Cleaning browser caches..."
59+
rm -rf ~/Library/Caches/Google
60+
rm -rf ~/Library/Caches/com.operasoftware.Opera
61+
rm -rf ~/Library/Caches/Firefox
62+
rm -rf ~/Library/Caches/Mozilla
63+
rm -rf ~/Library/Caches/zen
64+
rm -rf ~/Library/Caches/Arc
65+
66+
# Clean development tool caches
67+
echo "Cleaning development caches..."
68+
rm -rf ~/Library/Caches/JetBrains
69+
rm -rf ~/Library/Caches/pnpm
70+
rm -rf ~/.cache/puppeteer
71+
rm -rf ~/.cache/selenium
72+
73+
# Clean Python/ML caches
74+
echo "Cleaning Python/ML caches..."
75+
rm -rf ~/.cache/uv
76+
rm -rf ~/.cache/huggingface
77+
rm -rf ~/.cache/torch
78+
rm -rf ~/.cache/whisper
79+
80+
# Show results
81+
df -h / | tail -1 | awk '{print "After aggressive cleanup: " $4 " free"}'
82+
```
83+
84+
### Option 3: Maximum Cleanup (--maximum flag, ~29GB+)
85+
86+
Includes all aggressive cleanup plus Docker and old node_modules:
87+
88+
```bash
89+
# Run aggressive cleanup first (from Option 2)
90+
npm cache clean --force
91+
brew cleanup
92+
rm -rf ~/Library/Caches/Yarn
93+
rm -rf ~/Library/Caches/{Google,com.operasoftware.Opera,Firefox,Mozilla,zen,Arc,JetBrains,pnpm}
94+
rm -rf ~/.cache/{puppeteer,selenium,uv,huggingface,torch,whisper}
95+
96+
# Clean Docker (if installed)
97+
echo "Cleaning Docker..."
98+
docker system prune -af --volumes 2>/dev/null || echo "Docker not running or not installed"
99+
100+
# List node_modules directories for manual review
101+
echo "Finding node_modules directories..."
102+
echo "Note: Not auto-deleting. Review and delete manually if needed."
103+
find ~ -name "node_modules" -type d -prune 2>/dev/null | head -20
104+
105+
# Show results
106+
df -h / | tail -1 | awk '{print "After maximum cleanup: " $4 " free"}'
107+
```
108+
109+
## Execution Steps
110+
111+
1. **Determine Cleanup Level**
112+
- No arguments or empty: Run Conservative Cleanup (Option 1)
113+
- `--aggressive`: Run Aggressive Cleanup (Option 2)
114+
- `--maximum`: Run Maximum Cleanup (Option 3)
115+
116+
2. **Safety Checks**
117+
- Verify sufficient permissions
118+
- Ensure critical applications are closed (browsers for Option 2+)
119+
- Warn about Docker containers being removed (Option 3)
120+
121+
3. **Execute Cleanup**
122+
- Run appropriate commands based on the selected option
123+
- Show progress for each cleanup step
124+
- Handle errors gracefully (missing directories, permissions)
125+
126+
4. **Report Results**
127+
- Display disk space before and after
128+
- Show amount of space recovered
129+
- List what was cleaned
130+
- Provide recommendations if more space is needed
131+
132+
## Important Notes
133+
134+
**Conservative Cleanup** (default):
135+
- ✅ Always safe to run
136+
- ✅ Caches rebuild automatically when needed
137+
- ✅ No application impact
138+
139+
**Aggressive Cleanup** (--aggressive):
140+
- ⚠️ Close browsers before running
141+
- ⚠️ Browser caches will rebuild on next use
142+
- ⚠️ ML models will re-download if needed
143+
144+
**Maximum Cleanup** (--maximum):
145+
- ⚠️ Stops and removes all Docker containers/images
146+
- ⚠️ Only deletes node_modules after manual review
147+
- ⚠️ Most impactful but recovers the most space
148+
149+
## Recovery
150+
151+
All cleaned caches are temporary and will rebuild automatically:
152+
153+
- **npm/Yarn**: Rebuilds on next `npm install`
154+
- **Homebrew**: Downloaded on next `brew install`
155+
- **Browsers**: Rebuilds on next browsing session
156+
- **Python/ML**: Re-downloads models on next use
157+
- **Docker**: Pull images again with `docker pull`
158+
159+
## Example Usage
160+
161+
```bash
162+
# Conservative cleanup (default)
163+
/cleanup-cache
164+
165+
# Aggressive cleanup
166+
/cleanup-cache --aggressive
167+
168+
# Maximum cleanup
169+
/cleanup-cache --maximum
170+
```
171+
172+
After cleanup, verify the results and inform the user of:
173+
1. Space freed
174+
2. Current free space
175+
3. What was cleaned
176+
4. Whether additional cleanup is recommended

0 commit comments

Comments
 (0)