macos-cleaner

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

macOS Cleaner

macOS 清理工具

Overview

概述

Intelligently analyze macOS disk usage and provide actionable cleanup recommendations to reclaim storage space. This skill follows a safety-first philosophy: analyze thoroughly, present clear findings, and require explicit user confirmation before executing any deletions.
Target users: Users with basic technical knowledge who understand file systems but need guidance on what's safe to delete on macOS.
智能分析macOS磁盘使用情况,并提供可执行的清理建议以回收存储空间。本技能遵循安全优先原则:全面分析、清晰呈现结果,执行任何删除操作前必须获得用户明确确认。
目标用户:具备基础技术知识、了解文件系统,但需要指导判断macOS上哪些内容可安全删除的用户。

Core Principles

核心原则

  1. Safety First, Never Bypass: NEVER execute dangerous commands (
    rm -rf
    ,
    mo clean
    , etc.) without explicit user confirmation. No shortcuts, no workarounds.
  2. Value Over Vanity: Your goal is NOT to maximize cleaned space. Your goal is to identify what is truly useless vs valuable cache. Clearing 50GB of useful cache just to show a big number is harmful.
  3. Network Environment Awareness: Many users (especially in China) have slow/unreliable internet. Re-downloading caches can take hours. A cache that saves 30 minutes of download time is worth keeping.
  4. Impact Analysis Required: Every cleanup recommendation MUST include "what happens if deleted" column. Never just list items without explaining consequences.
  5. Patience Over Speed: Disk scans can take 5-10 minutes. NEVER interrupt or skip slow operations. Report progress to user regularly.
  6. User Executes Cleanup: After analysis, provide the cleanup command for the user to run themselves. Do NOT auto-execute cleanup.
  7. Conservative Defaults: When in doubt, don't delete. Err on the side of caution.
ABSOLUTE PROHIBITIONS:
  • ❌ NEVER run
    rm -rf
    on user directories automatically
  • ❌ NEVER run
    mo clean
    without dry-run preview first
  • ❌ NEVER use
    docker volume prune -f
    or
    docker system prune -a --volumes
  • ❌ NEVER skip analysis steps to save time
  • ❌ NEVER append
    --help
    to Mole commands (except
    mo --help
    )
  • ❌ NEVER recommend deleting useful caches just to inflate cleanup numbers
  1. 安全第一,绝不越界:未经用户明确确认,绝不能执行危险命令(如
    rm -rf
    mo clean
    等)。没有捷径,没有变通方法。
  2. 价值优先,拒绝虚荣:你的目标不是最大化清理空间,而是识别真正无用的内容与有价值的缓存。为了显示清理大数字而删除50GB有用缓存是有害的。
  3. 考虑网络环境:许多用户(尤其是国内用户)网络速度慢或不稳定。重新下载缓存可能需要数小时。一个能节省30分钟下载时间的缓存是值得保留的。
  4. 必须进行影响分析:每条清理建议必须包含“删除后会发生什么”的说明。绝不能只列出项目却不解释后果。
  5. 耐心优先于速度:磁盘扫描可能需要5-10分钟。绝不能中断或跳过耗时的操作,要定期向用户报告进度。
  6. 由用户执行清理:分析完成后,提供清理命令让用户自行执行。绝不能自动执行清理操作。
  7. 保守默认策略:存疑时,不删除。宁可信其有,不可信其无。
绝对禁止事项:
  • ❌ 绝不能自动在用户目录下运行
    rm -rf
  • ❌ 绝不能在未先进行试运行预览的情况下运行
    mo clean
  • ❌ 绝不能使用
    docker volume prune -f
    docker system prune -a --volumes
  • ❌ 绝不能为了节省时间而跳过分析步骤
  • ❌ 绝不能在Mole命令后追加
    --help
    (除了
    mo --help
  • ❌ 绝不能为了虚增清理数字而建议删除有用缓存

Workflow Decision Tree

工作流决策树

User reports disk space issues
    Quick Diagnosis
    ┌──────┴──────┐
    │             │
Immediate    Deep Analysis
 Cleanup      (continue below)
    │             │
    └──────┬──────┘
  Present Findings
   User Confirms
   Execute Cleanup
  Verify Results
用户反馈磁盘空间问题
    快速诊断
    ┌──────┴──────┐
    │             │
立即清理    深度分析
           (继续下方步骤)
    │             │
    └──────┬──────┘
  呈现分析结果
   用户确认
   执行清理
  验证结果

Step 1: Quick Diagnosis with Mole

步骤1:使用Mole进行快速诊断

Primary tool: Use Mole for disk analysis. It provides comprehensive, categorized results.
主要工具:使用Mole进行磁盘分析,它能提供全面的分类结果。

1.1 Pre-flight Checks

1.1 前置检查

bash
undefined
bash
undefined

Check Mole installation and version

检查Mole是否安装及版本

which mo && mo --version
which mo && mo --version

If not installed

若未安装

brew install tw93/tap/mole
brew install tw93/tap/mole

Check for updates (Mole updates frequently)

检查更新(Mole更新频繁)

brew info tw93/tap/mole | head -5
brew info tw93/tap/mole | head -5

Upgrade if outdated

若版本过时则升级

brew upgrade tw93/tap/mole
undefined
brew upgrade tw93/tap/mole
undefined

1.2 Choose Analysis Method

1.2 选择分析方法

IMPORTANT: Use
mo analyze
as the primary analysis tool, NOT
mo clean --dry-run
.
CommandPurposeUse When
mo analyze
Interactive disk usage explorer (TUI tree view)PRIMARY: Understanding what's consuming space
mo clean --dry-run
Preview cleanup categoriesSECONDARY: Only after
mo analyze
to see cleanup preview
Why prefer
mo analyze
:
  • Dedicated disk analysis tool with interactive tree navigation
  • Allows drilling down into specific directories
  • Shows actual disk usage breakdown, not just cleanup categories
  • More informative for understanding storage consumption
重要提示:使用
mo analyze
作为主要分析工具,而非
mo clean --dry-run
命令用途使用场景
mo analyze
交互式磁盘使用情况浏览器(TUI树形视图)主要工具:了解存储空间占用情况
mo clean --dry-run
预览清理分类次要工具:仅在
mo analyze
之后使用,查看清理预览
优先使用
mo analyze
的原因:
  • 专用磁盘分析工具,支持交互式树形导航
  • 可深入查看特定目录
  • 显示实际磁盘使用情况细分,而非仅清理分类
  • 更有助于理解存储消耗情况

1.3 Run Analysis via tmux

1.3 通过tmux运行分析

IMPORTANT: Mole requires TTY. Always use tmux from Claude Code.
CRITICAL TIMING NOTE: Home directory scans are SLOW (5-10 minutes or longer for large directories). Inform user upfront and wait patiently.
bash
undefined
重要提示:Mole需要TTY环境。在Claude Code中始终使用tmux。
关键时间提示:主目录扫描速度较慢(大型目录可能需要5-10分钟或更久)。提前告知用户并耐心等待。
bash
undefined

Create tmux session

创建tmux会话

tmux new-session -d -s mole -x 120 -y 40
tmux new-session -d -s mole -x 120 -y 40

Run disk analysis (PRIMARY tool - interactive TUI)

运行磁盘分析(主要工具 - 交互式TUI)

tmux send-keys -t mole 'mo analyze' Enter
tmux send-keys -t mole 'mo analyze' Enter

Wait for scan - BE PATIENT!

等待扫描完成 - 请耐心等待!

Home directory scanning typically takes 5-10 minutes

主目录扫描通常需要5-10分钟

Report progress to user regularly

定期向用户报告进度

sleep 60 && tmux capture-pane -t mole -p
sleep 60 && tmux capture-pane -t mole -p

Navigate the TUI with arrow keys

使用箭头键导航TUI

tmux send-keys -t mole Down # Move to next item tmux send-keys -t mole Enter # Expand/select item tmux send-keys -t mole 'q' # Quit when done

**Alternative: Cleanup preview (use AFTER mo analyze)**
```bash
tmux send-keys -t mole Down # 移动到下一项 tmux send-keys -t mole Enter # 展开/选择项目 tmux send-keys -t mole 'q' # 完成后退出

**替代方案:清理预览(仅在mo analyze之后使用)**
```bash

Run dry-run preview (SAFE - no deletion)

运行试运行预览(安全 - 无删除操作)

tmux send-keys -t mole 'mo clean --dry-run' Enter
tmux send-keys -t mole 'mo clean --dry-run' Enter

Wait for scan (report progress to user every 30 seconds)

等待扫描完成(每30秒向用户报告一次进度)

Be patient! Large directories take 5-10 minutes

请耐心等待!大型目录需要5-10分钟

sleep 30 && tmux capture-pane -t mole -p
undefined
sleep 30 && tmux capture-pane -t mole -p
undefined

1.4 Progress Reporting

1.4 进度报告

Report scan progress to user regularly:
📊 Disk Analysis in Progress...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⏱️ Elapsed: 2 minutes

Current status:
✅ Applications: 49.5 GB (complete)
✅ System Library: 10.3 GB (complete)
⏳ Home: scanning... (this may take 5-10 minutes)
⏳ App Library: pending

I'm waiting patiently for the scan to complete.
Will report again in 30 seconds...
定期向用户报告扫描进度:
📊 磁盘分析进行中...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⏱️ 已耗时:2分钟

当前状态:
✅ 应用程序:49.5 GB(已完成)
✅ 系统库:10.3 GB(已完成)
⏳ 主目录:扫描中...(可能需要5-10分钟)
⏳ 应用库:待处理

我正在耐心等待扫描完成,将在30秒后再次报告进度...

1.5 Present Final Findings

1.5 呈现最终结果

After scan completes, present structured results:
📊 Disk Space Analysis (via Mole)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Free space: 27 GB

🧹 Recoverable Space (dry-run preview):

➤ User Essentials
  • User app cache:     16.67 GB
  • User app logs:      102.3 MB
  • Trash:              642.9 MB

➤ Browser Caches
  • Chrome cache:       1.90 GB
  • Safari cache:       4 KB

➤ Developer Tools
  • uv cache:           9.96 GB
  • npm cache:          (detected)
  • Docker cache:       (detected)
  • Homebrew cache:     (detected)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total recoverable: ~30 GB

⚠️ This was a dry-run preview. No files were deleted.
扫描完成后,以结构化方式呈现结果:
📊 磁盘空间分析结果(通过Mole)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
可用空间:27 GB

🧹 可回收空间(试运行预览):

➤ 用户核心数据
  • 用户应用缓存:     16.67 GB
  • 用户应用日志:      102.3 MB
  • 废纸篓:              642.9 MB

➤ 浏览器缓存
  • Chrome缓存:       1.90 GB
  • Safari缓存:       4 KB

➤ 开发工具
  • uv缓存:           9.96 GB
  • npm缓存:          (已检测到)
  • Docker缓存:       (已检测到)
  • Homebrew缓存:     (已检测到)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
总可回收空间:约30 GB

⚠️ 这是试运行预览,未删除任何文件。

Step 2: Deep Analysis Categories

步骤2:深度分析分类

Scan the following categories systematically. Reference
references/cleanup_targets.md
for detailed explanations.
系统地扫描以下分类。详细说明可参考
references/cleanup_targets.md

Category 1: System & Application Caches

分类1:系统与应用缓存

Locations to analyze:
  • ~/Library/Caches/*
    - User application caches
  • /Library/Caches/*
    - System-wide caches (requires sudo)
  • ~/Library/Logs/*
    - Application logs
  • /var/log/*
    - System logs (requires sudo)
Analysis script:
bash
scripts/analyze_caches.py --user-only
Safety level: 🟢 Generally safe to delete (apps regenerate caches)
Exceptions to preserve:
  • Browser caches while browser is running
  • IDE caches (may slow down next startup)
  • Package manager caches (Homebrew, pip, npm)
分析位置:
  • ~/Library/Caches/*
    - 用户应用缓存
  • /Library/Caches/*
    - 系统级缓存(需要sudo权限)
  • ~/Library/Logs/*
    - 应用日志
  • /var/log/*
    - 系统日志(需要sudo权限)
分析脚本:
bash
scripts/analyze_caches.py --user-only
安全级别:🟢 通常可安全删除(应用会重新生成缓存)
需保留的例外情况:
  • 浏览器运行时的浏览器缓存
  • IDE缓存(删除后可能会减慢下次启动速度)
  • 包管理器缓存(Homebrew、pip、npm)

Category 2: Application Remnants

分类2:应用残留

Locations to analyze:
  • ~/Library/Application Support/*
    - App data
  • ~/Library/Preferences/*
    - Preference files
  • ~/Library/Containers/*
    - Sandboxed app data
Analysis approach:
  1. List installed applications in
    /Applications
  2. Cross-reference with
    ~/Library/Application Support
  3. Identify orphaned folders (app uninstalled but data remains)
Analysis script:
bash
scripts/find_app_remnants.py
Safety level: 🟡 Caution required
  • ✅ Safe: Folders for clearly uninstalled apps
  • ⚠️ Check first: Folders for apps you rarely use
  • ❌ Keep: Active application data
分析位置:
  • ~/Library/Application Support/*
    - 应用数据
  • ~/Library/Preferences/*
    - 偏好设置文件
  • ~/Library/Containers/*
    - 沙箱应用数据
分析方法:
  1. 列出
    /Applications
    中已安装的应用
  2. ~/Library/Application Support
    中的内容进行交叉比对
  3. 识别孤立文件夹(应用已卸载但数据仍保留)
分析脚本:
bash
scripts/find_app_remnants.py
安全级别:🟡 需要谨慎操作
  • ✅ 安全:已明确卸载的应用对应的文件夹
  • ⚠️ 需先检查:很少使用的应用对应的文件夹
  • ❌ 保留:正在使用的应用数据

Category 3: Large Files & Duplicates

分类3:大文件与重复文件

Analysis script:
bash
scripts/analyze_large_files.py --threshold 100MB --path ~
Find duplicates (optional, resource-intensive):
bash
undefined
分析脚本:
bash
scripts/analyze_large_files.py --threshold 100MB --path ~
查找重复文件(可选,资源消耗较大):
bash
undefined

Use fdupes if installed

若已安装fdupes则使用

if command -v fdupes &> /dev/null; then fdupes -r ~/Documents ~/Downloads fi

**Present findings:**
📦 Large Files (>100MB): ━━━━━━━━━━━━━━━━━━━━━━━━
  1. movie.mp4 4.2 GB ~/Downloads
  2. dataset.csv 1.8 GB ~/Documents/data
  3. old_backup.zip 1.5 GB ~/Desktop ...
🔁 Duplicate Files:
  • screenshot.png (3 copies) 15 MB each
  • document_v1.docx (2 copies) 8 MB each

**Safety level**: 🟡 User judgment required
if command -v fdupes &> /dev/null; then fdupes -r ~/Documents ~/Downloads fi

**呈现结果:**
📦 大文件(>100MB): ━━━━━━━━━━━━━━━━━━━━━━━━
  1. movie.mp4 4.2 GB ~/Downloads
  2. dataset.csv 1.8 GB ~/Documents/data
  3. old_backup.zip 1.5 GB ~/Desktop ...
🔁 重复文件:
  • screenshot.png(3个副本) 每个15 MB
  • document_v1.docx(2个副本) 每个8 MB

**安全级别**:🟡 需要用户自行判断

Category 4: Development Environment Cleanup

分类4:开发环境清理

Targets:
  • Docker: images, containers, volumes, build cache
  • Homebrew: cache, old versions
  • Node.js:
    node_modules
    , npm cache
  • Python: pip cache,
    __pycache__
    , venv
  • Git:
    .git
    folders in archived projects
Analysis script:
bash
scripts/analyze_dev_env.py
Example findings:
🐳 Docker Resources:
- Unused images:      12 GB
- Stopped containers:  2 GB
- Build cache:         8 GB
- Orphaned volumes:    3 GB
Total potential:      25 GB

📦 Package Managers:
- Homebrew cache:      5 GB
- npm cache:           3 GB
- pip cache:           1 GB
Total potential:       9 GB

🗂️  Old Projects:
- archived-project-2022/.git  500 MB
- old-prototype/.git          300 MB
Cleanup commands (require confirmation):
bash
undefined
清理目标:
  • Docker:镜像、容器、卷、构建缓存
  • Homebrew:缓存、旧版本
  • Node.js:
    node_modules
    、npm缓存
  • Python:pip缓存、
    __pycache__
    、虚拟环境
  • Git:归档项目中的
    .git
    文件夹
分析脚本:
bash
scripts/analyze_dev_env.py
示例结果:
🐳 Docker资源:
- 未使用镜像:      12 GB
- 已停止容器:  2 GB
- 构建缓存:         8 GB
- 孤立卷:    3 GB
总可回收空间:      25 GB

📦 包管理器:
- Homebrew缓存:      5 GB
- npm缓存:           3 GB
- pip缓存:           1 GB
总可回收空间:       9 GB

🗂️  旧项目:
- archived-project-2022/.git  500 MB
- old-prototype/.git          300 MB
清理命令(需用户确认):
bash
undefined

Homebrew cleanup (safe)

Homebrew清理(安全)

brew cleanup -s
brew cleanup -s

npm _npx only (safe - temporary packages)

仅清理npm _npx(安全 - 临时包)

rm -rf ~/.npm/_npx
rm -rf ~/.npm/_npx

pip cache (use with caution)

pip缓存(谨慎使用)

pip cache purge

**Docker cleanup - SPECIAL HANDLING REQUIRED:**

⚠️ **NEVER use these commands:**
```bash
pip cache purge

**Docker清理 - 特殊处理要求:**

⚠️ **绝不能使用以下命令:**
```bash

❌ DANGEROUS - deletes ALL volumes without confirmation

❌ 危险 - 无确认即删除所有卷

docker volume prune -f docker system prune -a --volumes

✅ **Correct approach - per-volume confirmation:**
```bash
docker volume prune -f docker system prune -a --volumes

✅ **正确方法 - 按卷确认:**
```bash

1. List all volumes

1. 列出所有卷

docker volume ls
docker volume ls

2. Identify which projects each volume belongs to

2. 识别每个卷所属的项目

docker volume inspect <volume_name>
docker volume inspect <volume_name>

3. Ask user to confirm EACH project they want to delete

3. 请求用户确认每个要删除的项目

Example: "Do you want to delete all volumes for 'ragflow' project?"

示例:"是否要删除'ragflow'项目的所有卷?"

4. Delete specific volumes only after confirmation

4. 仅在确认后删除特定卷

docker volume rm ragflow_mysql_data ragflow_redis_data

**Safety level**: 🟢 Homebrew/npm cleanup, 🔴 Docker volumes require per-project confirmation
docker volume rm ragflow_mysql_data ragflow_redis_data

**安全级别**:🟢 Homebrew/npm清理安全,🔴 Docker卷需要按项目确认

Step 3: Integration with Mole

步骤3:与Mole集成

Mole (https://github.com/tw93/Mole) is a command-line interface (CLI) tool for comprehensive macOS cleanup. It provides interactive terminal-based analysis and cleanup for caches, logs, developer tools, and more.
CRITICAL REQUIREMENTS:
  1. TTY Environment: Mole requires a TTY for interactive commands. Use
    tmux
    when running from Claude Code or scripts.
  2. Version Check: Always verify Mole is up-to-date before use.
  3. Safe Help Command: Only
    mo --help
    is safe. Do NOT append
    --help
    to other commands.
Installation check and upgrade:
bash
undefined
关键要求:
  1. TTY环境:Mole的交互式命令需要TTY环境。从Claude Code或脚本运行时使用
    tmux
  2. 版本检查:使用前始终确认Mole为最新版本。
  3. 安全帮助命令:仅
    mo --help
    是安全的。绝不能在其他命令后追加
    --help
安装检查与升级:
bash
undefined

Check if installed and get version

检查是否安装及版本

which mo && mo --version
which mo && mo --version

If not installed

若未安装

brew install tw93/tap/mole
brew install tw93/tap/mole

Check for updates

检查更新

brew info tw93/tap/mole | head -5
brew info tw93/tap/mole | head -5

Upgrade if needed

若需要则升级

brew upgrade tw93/tap/mole

**Using Mole with tmux (REQUIRED for Claude Code):**

```bash
brew upgrade tw93/tap/mole

**结合tmux使用Mole(Claude Code中必须使用):**

```bash

Create tmux session for TTY environment

创建tmux会话以提供TTY环境

tmux new-session -d -s mole -x 120 -y 40
tmux new-session -d -s mole -x 120 -y 40

Run analysis (safe, read-only)

运行分析(安全,只读)

tmux send-keys -t mole 'mo analyze' Enter
tmux send-keys -t mole 'mo analyze' Enter

Wait for scan (be patient - can take 5-10 minutes for large directories)

等待扫描完成(耐心等待 - 大型目录可能需要5-10分钟)

sleep 60
sleep 60

Capture results

获取结果

tmux capture-pane -t mole -p
tmux capture-pane -t mole -p

Cleanup when done

完成后清理会话

tmux kill-session -t mole

**Available commands (from `mo --help`):**

| Command | Safety | Description |
|---------|--------|-------------|
| `mo --help` | ✅ Safe | View all commands (ONLY safe help) |
| `mo analyze` | ✅ Safe | Disk usage explorer (read-only) |
| `mo status` | ✅ Safe | System health monitor |
| `mo clean --dry-run` | ✅ Safe | Preview cleanup (no deletion) |
| `mo clean` | ⚠️ DANGEROUS | Actually deletes files |
| `mo purge` | ⚠️ DANGEROUS | Remove project artifacts |
| `mo uninstall` | ⚠️ DANGEROUS | Remove applications |

**Reference guide:**
See `references/mole_integration.md` for detailed tmux workflow and troubleshooting.
tmux kill-session -t mole

**可用命令(来自`mo --help`):**

| 命令 | 安全性 | 描述 |
|---------|--------|-------------|
| `mo --help` | ✅ 安全 | 查看所有命令(唯一安全的帮助命令) |
| `mo analyze` | ✅ 安全 | 磁盘使用情况浏览器(只读) |
| `mo status` | ✅ 安全 | 系统健康监控 |
| `mo clean --dry-run` | ✅ 安全 | 预览清理操作(无删除) |
| `mo clean` | ⚠️ 危险 | 实际删除文件 |
| `mo purge` | ⚠️ 危险 | 删除项目构建产物 |
| `mo uninstall` | ⚠️ 危险 | 卸载应用程序 |

**参考指南:**
详细的tmux工作流与故障排除可参考`references/mole_integration.md`。

Multi-Layer Deep Exploration with Mole

使用Mole进行多层深度探索

CRITICAL: For comprehensive analysis, you MUST perform multi-layer exploration, not just top-level scans. This section documents the proven workflow for navigating Mole's TUI.
关键提示:为了全面分析,必须进行多层探索,而不仅仅是顶层扫描。本节记录了在Mole的TUI中导航的成熟工作流。

Navigation Commands

导航命令

bash
undefined
bash
undefined

Create session

创建会话

tmux new-session -d -s mole -x 120 -y 40
tmux new-session -d -s mole -x 120 -y 40

Start analysis

启动分析

tmux send-keys -t mole 'mo analyze' Enter
tmux send-keys -t mole 'mo analyze' Enter

Wait for initial scan

等待初始扫描完成

sleep 8 && tmux capture-pane -t mole -p
sleep 8 && tmux capture-pane -t mole -p

Navigation keys (send via tmux)

导航键(通过tmux发送)

tmux send-keys -t mole Enter # Enter/expand selected directory tmux send-keys -t mole Left # Go back to parent directory tmux send-keys -t mole Down # Move to next item tmux send-keys -t mole Up # Move to previous item tmux send-keys -t mole 'q' # Quit TUI
tmux send-keys -t mole Enter # 进入/展开选中的目录 tmux send-keys -t mole Left # 返回父目录 tmux send-keys -t mole Down # 移动到下一项 tmux send-keys -t mole Up # 移动到上一项 tmux send-keys -t mole 'q' # 退出TUI

Capture current view

获取当前视图内容

tmux capture-pane -t mole -p
undefined
tmux capture-pane -t mole -p
undefined

Multi-Layer Exploration Workflow

多层探索工作流

Step 1: Top-level overview
bash
undefined
步骤1:顶层概览
bash
undefined

Start mo analyze, wait for initial menu

启动mo analyze,等待初始菜单加载

tmux send-keys -t mole 'mo analyze' Enter sleep 8 && tmux capture-pane -t mole -p
tmux send-keys -t mole 'mo analyze' Enter sleep 8 && tmux capture-pane -t mole -p

Example output:

示例输出:

1. Home 289.4 GB (58.5%)

1. Home 289.4 GB (58.5%)

2. App Library 145.2 GB (29.4%)

2. App Library 145.2 GB (29.4%)

3. Applications 49.5 GB (10.0%)

3. Applications 49.5 GB (10.0%)

4. System Library 10.3 GB (2.1%)

4. System Library 10.3 GB (2.1%)


**Step 2: Enter largest directory (Home)**
```bash
tmux send-keys -t mole Enter
sleep 10 && tmux capture-pane -t mole -p

**步骤2:进入最大目录(Home)**
```bash
tmux send-keys -t mole Enter
sleep 10 && tmux capture-pane -t mole -p

Example output:

示例输出:

1. Library 144.4 GB (49.9%)

1. Library 144.4 GB (49.9%)

2. Workspace 52.0 GB (18.0%)

2. Workspace 52.0 GB (18.0%)

3. .cache 19.3 GB (6.7%)

3. .cache 19.3 GB (6.7%)

4. Applications 17.0 GB (5.9%)

4. Applications 17.0 GB (5.9%)

...

...


**Step 3: Drill into specific directories**
```bash

**步骤3:深入特定目录**
```bash

Go to .cache (3rd item: Down Down Enter)

进入.cache(第3项:按两次Down再按Enter)

tmux send-keys -t mole Down Down Enter sleep 5 && tmux capture-pane -t mole -p
tmux send-keys -t mole Down Down Enter sleep 5 && tmux capture-pane -t mole -p

Example output:

示例输出:

1. uv 10.3 GB (55.6%)

1. uv 10.3 GB (55.6%)

2. modelscope 5.5 GB (29.5%)

2. modelscope 5.5 GB (29.5%)

3. huggingface 887.8 MB (4.7%)

3. huggingface 887.8 MB (4.7%)


**Step 4: Navigate back and explore another branch**
```bash

**步骤4:返回并探索另一个分支**
```bash

Go back to parent

返回父目录

tmux send-keys -t mole Left sleep 2
tmux send-keys -t mole Left sleep 2

Navigate to different directory

导航到其他目录

tmux send-keys -t mole Down Down Down Down Enter # Go to .npm sleep 5 && tmux capture-pane -t mole -p

**Step 5: Deep dive into Library**
```bash
tmux send-keys -t mole Down Down Down Down Enter # 进入.npm sleep 5 && tmux capture-pane -t mole -p

**步骤5:深入Library目录**
```bash

Back to Home, then into Library

返回Home,然后进入Library

tmux send-keys -t mole Left tmux send-keys -t mole Up Up Up Up Up Up Enter # Go to Library sleep 10 && tmux capture-pane -t mole -p
tmux send-keys -t mole Left tmux send-keys -t mole Up Up Up Up Up Up Enter # 进入Library sleep 10 && tmux capture-pane -t mole -p

Example output:

示例输出:

1. Application Support 37.1 GB

1. Application Support 37.1 GB

2. Containers 35.4 GB

2. Containers 35.4 GB

3. Developer 17.8 GB ← Xcode is here

3. Developer 17.8 GB ← Xcode相关内容在此

4. Caches 8.2 GB

4. Caches 8.2 GB

undefined
undefined

Recommended Exploration Path

推荐探索路径

For comprehensive analysis, follow this exploration tree:
mo analyze
├── Home (Enter)
│   ├── Library (Enter)
│   │   ├── Developer (Enter) → Xcode/DerivedData, iOS DeviceSupport
│   │   ├── Caches (Enter) → Playwright, JetBrains, etc.
│   │   └── Application Support (Enter) → App data
│   ├── .cache (Enter) → uv, modelscope, huggingface
│   ├── .npm (Enter) → _cacache, _npx
│   ├── Downloads (Enter) → Large files to review
│   ├── .Trash (Enter) → Confirm trash contents
│   └── miniconda3/other dev tools (Enter) → Check last used time
├── App Library → Usually overlaps with ~/Library
└── Applications → Installed apps
为了全面分析,请遵循以下探索树:
mo analyze
├── Home(Enter)
│   ├── Library(Enter)
│   │   ├── Developer(Enter)→ Xcode/DerivedData、iOS DeviceSupport
│   │   ├── Caches(Enter)→ Playwright、JetBrains等
│   │   └── Application Support(Enter)→ 应用数据
│   ├── .cache(Enter)→ uv、modelscope、huggingface
│   ├── .npm(Enter)→ _cacache、_npx
│   ├── Downloads(Enter)→ 需检查的大文件
│   ├── .Trash(Enter)→ 确认废纸篓内容
│   └── miniconda3/其他开发工具(Enter)→ 检查最后使用时间
├── App Library → 通常与~/Library内容重叠
└── Applications → 已安装的应用

Time Expectations

时间预期

DirectoryScan TimeNotes
Top-level menu5-8 secondsFast
Home directory5-10 minutesLarge, be patient
~/Library3-5 minutesMany small files
Subdirectories2-30 secondsVaries by size
目录扫描时间说明
顶层菜单5-8秒快速
主目录5-10分钟内容庞大,请耐心等待
~/Library3-5分钟包含大量小文件
子目录2-30秒时间因大小而异

Example Complete Session

完整会话示例

bash
undefined
bash
undefined

1. Create session

1. 创建会话

tmux new-session -d -s mole -x 120 -y 40
tmux new-session -d -s mole -x 120 -y 40

2. Start analysis and get overview

2. 启动分析并获取概览

tmux send-keys -t mole 'mo analyze' Enter sleep 8 && tmux capture-pane -t mole -p
tmux send-keys -t mole 'mo analyze' Enter sleep 8 && tmux capture-pane -t mole -p

3. Enter Home

3. 进入Home目录

tmux send-keys -t mole Enter sleep 10 && tmux capture-pane -t mole -p
tmux send-keys -t mole Enter sleep 10 && tmux capture-pane -t mole -p

4. Enter .cache to see dev caches

4. 进入.cache查看开发缓存

tmux send-keys -t mole Down Down Enter sleep 5 && tmux capture-pane -t mole -p
tmux send-keys -t mole Down Down Enter sleep 5 && tmux capture-pane -t mole -p

5. Back to Home, then to .npm

5. 返回Home,然后进入.npm

tmux send-keys -t mole Left sleep 2 tmux send-keys -t mole Down Down Down Down Enter sleep 5 && tmux capture-pane -t mole -p
tmux send-keys -t mole Left sleep 2 tmux send-keys -t mole Down Down Down Down Enter sleep 5 && tmux capture-pane -t mole -p

6. Back to Home, enter Library

6. 返回Home,进入Library

tmux send-keys -t mole Left sleep 2 tmux send-keys -t mole Up Up Up Up Up Up Enter sleep 10 && tmux capture-pane -t mole -p
tmux send-keys -t mole Left sleep 2 tmux send-keys -t mole Up Up Up Up Up Up Enter sleep 10 && tmux capture-pane -t mole -p

7. Enter Developer to see Xcode

7. 进入Developer查看Xcode内容

tmux send-keys -t mole Down Down Down Enter sleep 5 && tmux capture-pane -t mole -p
tmux send-keys -t mole Down Down Down Enter sleep 5 && tmux capture-pane -t mole -p

8. Enter Xcode

8. 进入Xcode

tmux send-keys -t mole Enter sleep 5 && tmux capture-pane -t mole -p
tmux send-keys -t mole Enter sleep 5 && tmux capture-pane -t mole -p

9. Enter DerivedData to see projects

9. 进入DerivedData查看项目内容

tmux send-keys -t mole Enter sleep 5 && tmux capture-pane -t mole -p
tmux send-keys -t mole Enter sleep 5 && tmux capture-pane -t mole -p

10. Cleanup

10. 清理会话

tmux kill-session -t mole
undefined
tmux kill-session -t mole
undefined

Key Insights from Exploration

探索关键发现

After multi-layer exploration, you will discover:
  1. What projects are using DerivedData - specific project names
  2. Which caches are actually large - uv vs npm vs others
  3. Age of files - Mole shows ">3mo", ">7mo", ">1yr" markers
  4. Specific volumes and their purposes - Docker project data
  5. Downloads that can be cleaned - old dmgs, duplicate files
经过多层探索后,你将发现:
  1. 哪些项目在使用DerivedData - 具体项目名称
  2. 哪些缓存实际占用大量空间 - uv、npm或其他缓存
  3. 文件的使用时长 - Mole会显示">3mo"、">7mo"、">1yr"等标记
  4. 特定卷及其用途 - Docker项目数据
  5. 可清理的下载内容 - 旧镜像文件、重复文件

Anti-Patterns: What NOT to Delete

反模式:绝不能删除的内容

CRITICAL: The following items are often suggested for cleanup but should NOT be deleted in most cases. They provide significant value that outweighs the space they consume.
关键提示:以下内容常被建议清理,但在大多数情况下不应删除。它们的价值远大于占用的空间。

Items to KEEP (Anti-Patterns)

需保留的内容(反模式)

ItemSizeWhy NOT to DeleteReal Impact of Deletion
Xcode DerivedData10+ GBBuild cache saves 10-30 min per full rebuildNext build takes 10-30 minutes longer
npm _cacache5+ GBDownloaded packages cached locally
npm install
redownloads everything (30min-2hr in China)
~/.cache/uv10+ GBPython package cacheEvery Python project reinstalls deps from PyPI
Playwright browsers3-4 GBBrowser binaries for automation testingRedownload 2GB+ each time (30min-1hr)
iOS DeviceSupport2-3 GBRequired for device debuggingRedownload from Apple when connecting device
Docker stopped containers<500 MBMay restart anytime with
docker start
Lose container state, need to recreate
~/.cache/huggingfacevariesAI model cacheRedownload large models (hours)
~/.cache/modelscopevariesAI model cache (China)Same as above
JetBrains caches1+ GBIDE indexing and cachesIDE takes 5-10 min to re-index
项目大小绝不能删除的原因删除后的实际影响
Xcode DerivedData10+ GB构建缓存可节省每次完整构建10-30分钟的时间下次构建时间将增加10-30分钟
npm _cacache5+ GB已下载的包缓存本地存储
npm install
将重新下载所有内容(国内网络下需要30分钟-2小时)
~/.cache/uv10+ GBPython包缓存每个Python项目都需要从PyPI重新安装依赖
Playwright浏览器3-4 GB自动化测试所需的浏览器二进制文件每次使用都需要重新下载2GB+内容(30分钟-1小时)
iOS DeviceSupport2-3 GB设备调试必需连接设备时需要从Apple重新下载
Docker已停止容器<500 MB可随时通过
docker start
重启
丢失容器状态,需要重新创建
~/.cache/huggingface大小不定AI模型缓存重新下载大型模型(需要数小时)
~/.cache/modelscope大小不定AI模型缓存(国内)与上述情况相同
JetBrains缓存1+ GBIDE索引与缓存IDE重新索引需要5-10分钟

Why This Matters

为什么这很重要

The vanity trap: Showing "Cleaned 50GB!" feels good but:
  • User spends next 2 hours redownloading npm packages
  • Next Xcode build takes 30 minutes instead of 30 seconds
  • AI project fails because models need redownload
The right mindset: "I found 50GB of caches. Here's why most of them are actually valuable and should be kept..."
虚荣陷阱:显示“已清理50GB!”看起来很棒,但实际上:
  • 用户接下来需要花2小时重新下载npm包
  • 下次Xcode构建需要30分钟而不是30秒
  • AI项目因需要重新下载模型而失败
正确心态:“我发现了50GB缓存,但其中大部分实际上很有价值,应该保留……”

What IS Actually Safe to Delete

真正可安全删除的内容

ItemWhy SafeImpact
TrashUser already deleted these filesNone - user's decision
Homebrew old versionsReplaced by newer versionsRare: can't rollback to old version
npm _npxTemporary npx executionsMinor: npx re-downloads on next use
Orphaned app remnantsApp already uninstalledNone - app doesn't exist
Specific unused Docker volumesProjects confirmed abandonedNone - if truly abandoned
项目为什么安全影响
废纸篓用户已决定删除这些文件无 - 用户自主选择
Homebrew旧版本已被新版本替代罕见情况:无法回滚到旧版本
npm _npxnpx临时执行文件轻微影响:下次使用npx时需要重新下载
孤立应用残留应用已卸载无 - 应用已不存在
特定未使用的Docker卷项目已确认废弃无 - 若确实已废弃

Report Format Requirements

报告格式要求

Every cleanup report MUST follow this format with impact analysis:
markdown
undefined
每份清理报告必须遵循以下格式,并包含影响分析:
markdown
undefined

Disk Analysis Report

磁盘分析报告

Classification Legend

分类图例

SymbolMeaning
🟢Absolutely Safe - No negative impact, truly unused
🟡Trade-off Required - Useful cache, deletion has cost
🔴Do Not Delete - Contains valuable data or actively used
符号含义
🟢绝对安全 - 无负面影响,真正未使用的内容
🟡需要权衡 - 有用的缓存,删除会有代价
🔴绝不能删除 - 包含有价值的数据或正在使用的内容

Findings

分析结果

ItemSizeClassificationWhat It IsImpact If Deleted
Trash643 MB🟢Files you deletedNone
npm _npx2.1 GB🟢Temp npx packagesMinor redownload
npm _cacache5 GB🟡Package cache30min-2hr redownload
DerivedData10 GB🟡Xcode build cache10-30min rebuild
Docker volumes11 GB🔴Project databasesDATA LOSS
项目大小分类内容说明删除影响
废纸篓643 MB🟢用户已删除的文件
npm _npx2.1 GB🟢npx临时包轻微影响:下次使用npx时重新下载
npm _cacache5 GB🟡包缓存30分钟-2小时的重新下载时间
DerivedData10 GB🟡Xcode构建缓存10-30分钟的额外构建时间
Docker卷11 GB🔴项目数据库数据丢失

Recommendation

建议

Only items marked 🟢 are recommended for cleanup. Items marked 🟡 require your judgment based on usage patterns. Items marked 🔴 require explicit confirmation per-item.
undefined
仅标记为🟢的项目建议清理。 标记为🟡的项目需要你根据使用模式自行判断。 标记为🔴的项目需要逐项明确确认。
undefined

High-Quality Report Template

高质量报告模板

After multi-layer exploration, present findings using this proven template:
markdown
undefined
多层探索完成后,使用以下成熟模板呈现结果:
markdown
undefined

📊 磁盘空间深度分析报告

📊 磁盘空间深度分析报告

分析日期: YYYY-MM-DD 使用工具: Mole CLI + 多层目录探索 分析原则: 安全第一,价值优于虚荣

分析日期: YYYY-MM-DD 使用工具: Mole CLI + 多层目录探索 分析原则: 安全第一,价值优于虚荣

总览

总览

区域总占用关键发现
HomeXXX GBLibrary占一半(XXX GB)
App LibraryXXX GB与Home/Library重叠统计
ApplicationsXXX GB应用本体

区域总占用关键发现
HomeXXX GBLibrary占一半(XXX GB)
App LibraryXXX GB与Home/Library统计重叠
ApplicationsXXX GB应用本体

🟢 绝对安全可删除 (约 X.X GB)

🟢 绝对安全可删除 (约 X.X GB)

项目大小位置删除后影响清理命令
废纸篓XXX MB~/.Trash无 - 你已决定删除的文件清空废纸篓
npm _npxX.X GB~/.npm/_npx下次 npx 命令重新下载
rm -rf ~/.npm/_npx
Homebrew 旧版本XX MB/opt/homebrew无 - 已被新版本替代
brew cleanup --prune=0
废纸篓内容预览:
  • [列出主要文件]

项目大小位置删除后影响清理命令
废纸篓XXX MB~/.Trash无 - 你已决定删除的文件清空废纸篓
npm _npxX.X GB~/.npm/_npx下次npx命令会重新下载
rm -rf ~/.npm/_npx
Homebrew旧版本XX MB/opt/homebrew无 - 已被新版本替代
brew cleanup --prune=0
废纸篓内容预览:
  • [列出主要文件]

🟡 需要你确认的项目

🟡 需要你确认的项目

1. [项目名] (X.X GB) - [状态描述]

1. [项目名] (X.X GB) - [状态描述]

子目录大小最后使用
[子目录1]X.X GB>X个月
[子目录2]X.X GB>X个月
问题: [需要用户回答的问题]

子目录大小最后使用
[子目录1]X.X GB>X个月
[子目录2]X.X GB>X个月
问题: [需要用户回答的问题]

2. Downloads 中的旧文件 (X.X GB)

2. Downloads中的旧文件 (X.X GB)

文件/目录大小年龄建议
[文件1]X.X GB-[建议]
[文件2]XXX MB>X个月[建议]
建议: 手动检查 Downloads,删除已不需要的文件。

文件/目录大小使用时长建议
[文件1]X.X GB-[建议]
[文件2]XXX MB>X个月[建议]
建议: 手动检查Downloads文件夹,删除不再需要的文件。

3. 停用的 Docker 项目 Volumes

3. 停用的Docker项目Volumes

项目前缀可能包含的数据需要你确认
project1_*
MySQL, Redis还在用吗?
project2_*
Postgres还在用吗?
注意: 我不会使用
docker volume prune -f
,只会在你确认后删除特定项目的 volumes。

项目前缀可能包含的数据需要你确认
project1_*
MySQL、Redis还在使用吗?
project2_*
Postgres还在使用吗?
注意: 我不会使用
docker volume prune -f
命令,只会在你确认后删除特定项目的volumes。

🔴 不建议删除的项目 (有价值的缓存)

🔴 不建议删除的项目 (有价值的缓存)

项目大小为什么要保留
Xcode DerivedDataXX GB[项目名]的编译缓存,删除后下次构建需要X分钟
npm _cacacheX.X GB所有下载过的 npm 包,删除后需要重新下载
~/.cache/uvXX GBPython 包缓存,重新下载在中国网络下很慢
[其他有价值的缓存]X.X GB[保留原因]

项目大小保留原因
Xcode DerivedDataXX GB[项目名]的编译缓存,删除后下次构建需要X分钟
npm _cacacheX.X GB所有已下载的npm包,删除后需要重新下载
~/.cache/uvXX GBPython包缓存,国内网络下重新下载速度很慢
[其他有价值的缓存]X.X GB[保留原因]

📋 其他发现

📋 其他发现

项目大小说明
OrbStack/DockerXX GB正常的 VM/容器占用
[其他发现]X.X GB[说明]

项目大小说明
OrbStack/DockerXX GB正常的虚拟机/容器占用
[其他发现]X.X GB[说明]

推荐操作

推荐操作

立即可执行 (无需确认):
bash
undefined
立即可执行 (无需确认):
bash
undefined

1. 清空废纸篓 (XXX MB)

1. 清空废纸篓 (XXX MB)

手动: Finder → 清空废纸篓

手动操作: Finder → 清空废纸篓

2. npm _npx (X.X GB)

2. npm _npx (X.X GB)

rm -rf ~/.npm/_npx
rm -rf ~/.npm/_npx

3. Homebrew 旧版本 (XX MB)

3. Homebrew旧版本 (XX MB)

brew cleanup --prune=0

**预计释放**: ~X.X GB

---

**需要你确认后执行**:

1. **[项目1]** - [确认问题]
2. **[项目2]** - [确认问题]
3. **Docker 项目** - 告诉我哪些项目确定不用了
brew cleanup --prune=0

**预计释放空间**: ~X.X GB

---

**需要你确认后执行**:

1. **[项目1]** - [确认问题]
2. **[项目2]** - [确认问题]
3. **Docker项目** - 告诉我哪些项目确定不再使用

Report Quality Checklist

报告质量检查清单

Before presenting the report, verify:
  • Every item has "Impact If Deleted" explanation
  • 🟢 items are truly safe (Trash, _npx, old versions)
  • 🟡 items require user decision (age info, usage patterns)
  • 🔴 items explain WHY they should be kept
  • Docker volumes listed by project, not blanket prune
  • Network environment considered (China = slow redownload)
  • No recommendations to delete useful caches just to inflate numbers
  • Clear action items with exact commands
呈现报告前,请验证:
  • 每个项目都包含“删除后影响”的说明
  • 🟢类项目确实安全(废纸篓、_npx、旧版本)
  • 🟡类项目需要用户决策(包含使用时长信息、使用模式)
  • 🔴类项目说明了必须保留的原因
  • Docker卷按项目列出,而非批量清理
  • 考虑了网络环境(国内网络=下载速度慢)
  • 没有为了虚增清理数字而建议删除有用缓存
  • 提供了清晰的操作项与准确命令

Step 4: Present Recommendations

步骤4:呈现建议

Format findings into actionable recommendations with risk levels:
markdown
undefined
将结果整理为带有风险级别的可执行建议:
markdown
undefined

macOS Cleanup Recommendations

macOS清理建议

Summary

摘要

Total space recoverable: ~XX GB Current usage: XX%
可回收总空间:约XX GB 当前使用率:XX%

Recommended Actions

推荐操作

🟢 Safe to Execute (Low Risk)

🟢 可安全执行(低风险)

These are safe to delete and will be regenerated as needed:
  1. Empty Trash (~12 GB)
    • Location: ~/.Trash
    • Command:
      rm -rf ~/.Trash/*
  2. Clear System Caches (~45 GB)
    • Location: ~/Library/Caches
    • Command:
      rm -rf ~/Library/Caches/*
    • Note: Apps may be slightly slower on next launch
  3. Remove Homebrew Cache (~5 GB)
    • Command:
      brew cleanup -s
这些内容可安全删除,必要时会重新生成:
  1. 清空废纸篓 (~12 GB)
    • 位置:~/.Trash
    • 命令:
      rm -rf ~/.Trash/*
  2. 清理系统缓存 (~45 GB)
    • 位置:~/Library/Caches
    • 命令:
      rm -rf ~/Library/Caches/*
    • 注意:应用首次启动可能会稍慢
  3. 删除Homebrew缓存 (~5 GB)
    • 命令:
      brew cleanup -s

🟡 Review Recommended (Medium Risk)

🟡 建议检查后操作(中风险)

Review these items before deletion:
  1. Large Downloads (~38 GB)
    • Location: ~/Downloads
    • Action: Manually review and delete unneeded files
    • Files: [list top 10 largest files]
  2. Application Remnants (~8 GB)
    • Apps: [list detected uninstalled apps]
    • Locations: [list paths]
    • Action: Confirm apps are truly uninstalled before deleting data
删除前请检查这些内容:
  1. 大体积下载文件 (~38 GB)
    • 位置:~/Downloads
    • 操作:手动检查并删除不需要的文件
    • 文件列表:[列出前10个大文件]
  2. 应用残留 (~8 GB)
    • 涉及应用:[列出检测到的已卸载应用]
    • 位置:[列出路径]
    • 操作:确认应用确实已卸载后再删除数据

🔴 Keep Unless Certain (High Risk)

🔴 非确定情况下请保留(高风险)

Only delete if you know what you're doing:
  1. Docker Volumes (~3 GB)
    • May contain important data
    • Review with:
      docker volume ls
  2. Time Machine Local Snapshots (~XX GB)
    • Automatic backups, will be deleted when space needed
    • Command to check:
      tmutil listlocalsnapshots /
undefined
仅当你明确了解内容时再删除:
  1. Docker卷 (~3 GB)
    • 可能包含重要数据
    • 查看命令:
      docker volume ls
  2. Time Machine本地快照 (~XX GB)
    • 自动备份,空间不足时会自动删除
    • 检查命令:
      tmutil listlocalsnapshots /
undefined

Step 5: Execute with Confirmation

步骤5:获得确认后执行

CRITICAL: Never execute deletions without explicit user confirmation.
Interactive confirmation flow:
python
undefined
关键提示:未经用户明确确认,绝不能执行删除操作。
交互式确认流程:
python
undefined

Example from scripts/safe_delete.py

示例来自scripts/safe_delete.py

def confirm_delete(path: str, size: str, description: str) -> bool: """ Ask user to confirm deletion.
Args:
    path: File/directory path
    size: Human-readable size
    description: What this file/directory is

Returns:
    True if user confirms, False otherwise
"""
print(f"\n🗑️  Confirm Deletion")
print(f"━━━━━━━━━━━━━━━━━━")
print(f"Path:        {path}")
print(f"Size:        {size}")
print(f"Description: {description}")

response = input("\nDelete this item? [y/N]: ").strip().lower()
return response == 'y'

**For batch operations:**

```python
def batch_confirm(items: list) -> list:
    """
    Show all items, ask for batch confirmation.

    Returns list of items user approved.
    """
    print("\n📋 Items to Delete:")
    print("━━━━━━━━━━━━━━━━━━")
    for i, item in enumerate(items, 1):
        print(f"{i}. {item['path']} ({item['size']})")

    print("\nOptions:")
    print("  'all'    - Delete all items")
    print("  '1,3,5'  - Delete specific items by number")
    print("  'none'   - Cancel")

    response = input("\nYour choice: ").strip().lower()

    if response == 'none':
        return []
    elif response == 'all':
        return items
    else:
        # Parse numbers
        indices = [int(x.strip()) - 1 for x in response.split(',')]
        return [items[i] for i in indices if 0 <= i < len(items)]
def confirm_delete(path: str, size: str, description: str) -> bool: """ 请求用户确认删除操作。
参数:
    path: 文件/目录路径
    size: 易读的大小格式
    description: 该文件/目录的说明

返回:
    用户确认则返回True,否则返回False
"""
print(f"\
🗑️ 确认删除") print(f"━━━━━━━━━━━━━━━━━━") print(f"路径: {path}") print(f"大小: {size}") print(f"说明: {description}")
response = input("\
是否删除此项目? [y/N]: ").strip().lower() return response == 'y'

**批量操作确认:**

```python
def batch_confirm(items: list) -> list:
    """
    显示所有项目,请求批量确认。

    返回用户批准的项目列表。
    """
    print("\
📋 待删除项目:")
    print("━━━━━━━━━━━━━━━━━━")
    for i, item in enumerate(items, 1):
        print(f"{i}. {item['path']} ({item['size']})")

    print("\
选项:")
    print("  'all'    - 删除所有项目")
    print("  '1,3,5'  - 按编号删除特定项目")
    print("  'none'   - 取消操作")

    response = input("\
你的选择: ").strip().lower()

    if response == 'none':
        return []
    elif response == 'all':
        return items
    else:
        # 解析编号
        indices = [int(x.strip()) - 1 for x in response.split(',')]
        return [items[i] for i in indices if 0 <= i < len(items)]

Step 6: Verify Results

步骤6:验证结果

After cleanup, verify the results and report back:
bash
undefined
清理完成后,验证结果并向用户报告:
bash
undefined

Compare before/after

对比清理前后的空间使用情况

df -h /
df -h /

Calculate space recovered

计算回收的空间

(handled by scripts/cleanup_report.py)

(由scripts/cleanup_report.py处理)


**Report format:**
✅ Cleanup Complete!
Before: 450 GB used (90%) After: 385 GB used (77%) ━━━━━━━━━━━━━━━━━━━━━━━━ Recovered: 65 GB
Breakdown:
  • System caches: 45 GB
  • Downloads: 12 GB
  • Homebrew cache: 5 GB
  • Application remnants: 3 GB
⚠️ Notes:
  • Some applications may take longer to launch on first run
  • Deleted items cannot be recovered unless you have Time Machine backup
  • Consider running this cleanup monthly
💡 Maintenance Tips:
  • Set up automatic Homebrew cleanup:
    brew cleanup
    weekly
  • Review Downloads folder monthly
  • Enable "Empty Trash Automatically" in Finder preferences
undefined

**报告格式:**
✅ 清理完成!
清理前: 已使用450 GB (90%) 清理后: 已使用385 GB (77%) ━━━━━━━━━━━━━━━━━━━━━━━━ 回收空间: 65 GB
空间回收明细:
  • 系统缓存: 45 GB
  • 下载文件: 12 GB
  • Homebrew缓存: 5 GB
  • 应用残留: 3 GB
⚠️ 注意事项:
  • 部分应用首次启动可能会耗时更久
  • 删除的项目除非有Time Machine备份,否则无法恢复
  • 建议每月进行一次此类清理
💡 维护建议:
  • 设置Homebrew自动每周清理:
    brew cleanup
  • 每月检查Downloads文件夹
  • 在Finder偏好设置中启用“自动清空废纸篓”
undefined

Safety Guidelines

安全指南

Always Preserve

始终保留的内容

Never delete these without explicit user instruction:
  • ~/Documents
    ,
    ~/Desktop
    ,
    ~/Pictures
    content
  • Active project directories
  • Database files (*.db, *.sqlite)
  • Configuration files for active apps
  • SSH keys, credentials, certificates
  • Time Machine backups
未经用户明确指示,绝不能删除以下内容:
  • ~/Documents
    ~/Desktop
    ~/Pictures
    中的内容
  • 活跃的项目目录
  • 数据库文件(.db、.sqlite)
  • 正在使用的应用的配置文件
  • SSH密钥、凭据、证书
  • Time Machine备份

Require Sudo Confirmation

需要Sudo权限的操作需确认

These operations require elevated privileges. Ask user to run commands manually:
  • Clearing
    /Library/Caches
    (system-wide)
  • Clearing
    /var/log
    (system logs)
  • Clearing
    /private/var/folders
    (system temp)
Example prompt:
⚠️ This operation requires administrator privileges.

Please run this command manually:
  sudo rm -rf /Library/Caches/*

⚠️ You'll be asked for your password.
以下操作需要提升权限。请让用户手动运行命令:
  • 清理
    /Library/Caches
    (系统级)
  • 清理
    /var/log
    (系统日志)
  • 清理
    /private/var/folders
    (系统临时文件)
提示示例:
⚠️ 此操作需要管理员权限。

请手动运行以下命令:
  sudo rm -rf /Library/Caches/*

⚠️ 运行时会要求你输入密码。

Backup Recommendation

备份建议

Before executing any cleanup >10GB, recommend:
💡 Safety Tip:
Before cleaning XX GB, consider creating a Time Machine backup.

Quick backup check:
  tmutil latestbackup

If no recent backup, run:
  tmutil startbackup
清理空间超过10GB前,建议用户:
💡 安全提示:
在清理XX GB空间前,建议创建Time Machine备份。

快速检查备份情况:
  tmutil latestbackup

若没有近期备份,请运行:
  tmutil startbackup

Troubleshooting

故障排除

"Operation not permitted" errors

“Operation not permitted”错误

macOS may block deletion of certain system files due to SIP (System Integrity Protection).
Solution: Don't force it. These protections exist for security.
macOS可能会因系统完整性保护(SIP)而阻止删除某些系统文件。
解决方案:不要强制删除。这些保护措施是为了安全考虑。

App crashes after cache deletion

删除缓存后应用崩溃

Rare but possible. Solution: Restart the app, it will regenerate necessary caches.
这种情况很少见,但有可能发生。解决方案:重启应用,它会重新生成必要的缓存。

Docker cleanup removes important data

Docker清理删除了重要数据

Prevention: Always list Docker volumes before cleanup:
bash
docker volume ls
docker volume inspect <volume_name>
预防措施:清理前始终列出Docker卷:
bash
docker volume ls
docker volume inspect <volume_name>

Resources

资源

scripts/

scripts/

  • analyze_caches.py
    - Scan and categorize cache directories
  • find_app_remnants.py
    - Detect orphaned application data
  • analyze_large_files.py
    - Find large files with smart filtering
  • analyze_dev_env.py
    - Scan development environment resources
  • safe_delete.py
    - Interactive deletion with confirmation
  • cleanup_report.py
    - Generate before/after reports
  • analyze_caches.py
    - 扫描并分类缓存目录
  • find_app_remnants.py
    - 检测孤立的应用数据
  • analyze_large_files.py
    - 通过智能过滤查找大文件
  • analyze_dev_env.py
    - 扫描开发环境资源
  • safe_delete.py
    - 带确认机制的交互式删除
  • cleanup_report.py
    - 生成清理前后的报告

references/

references/

  • cleanup_targets.md
    - Detailed explanations of each cleanup target
  • mole_integration.md
    - How to use Mole alongside this skill
  • safety_rules.md
    - Comprehensive list of what to never delete
  • cleanup_targets.md
    - 每个清理目标的详细说明
  • mole_integration.md
    - 如何将Mole与本技能结合使用
  • safety_rules.md
    - 绝不能删除的内容的完整列表

Usage Examples

使用示例

Example 1: Quick Cache Cleanup

示例1:快速缓存清理

User request: "My Mac is running out of space, can you help?"
Workflow:
  1. Run quick diagnosis
  2. Identify system caches as quick win
  3. Present findings: "45 GB in ~/Library/Caches"
  4. Explain: "These are safe to delete, apps will regenerate them"
  5. Ask confirmation
  6. Execute:
    rm -rf ~/Library/Caches/*
  7. Report: "Recovered 45 GB"
用户请求: "我的Mac空间不足,能帮忙清理吗?"
工作流:
  1. 运行快速诊断
  2. 识别系统缓存为快速清理目标
  3. 呈现结果: "~/Library/Caches中存在45 GB缓存"
  4. 说明: "这些可安全删除,应用会重新生成缓存"
  5. 请求确认
  6. 执行:
    rm -rf ~/Library/Caches/*
  7. 报告: "已回收45 GB空间"

Example 2: Development Environment Cleanup

示例2:开发环境清理

User request: "I'm a developer and my disk is full"
Workflow:
  1. Run
    scripts/analyze_dev_env.py
  2. Present Docker + npm + Homebrew findings
  3. Explain each category
  4. Provide cleanup commands with explanations
  5. Let user execute (don't auto-execute Docker cleanup)
  6. Verify results
用户请求: "我是开发者,我的磁盘满了"
工作流:
  1. 运行
    scripts/analyze_dev_env.py
  2. 呈现Docker + npm + Homebrew的分析结果
  3. 解释每个分类
  4. 提供带说明的清理命令
  5. 让用户自行执行(绝不自动执行Docker清理)
  6. 验证结果

Example 3: Finding Large Files

示例3:查找大文件

User request: "What's taking up so much space?"
Workflow:
  1. Run
    scripts/analyze_large_files.py --threshold 100MB
  2. Present top 20 large files with context
  3. Categorize: videos, datasets, archives, disk images
  4. Let user decide what to delete
  5. Execute confirmed deletions
  6. Suggest archiving to external drive
用户请求: "什么内容占用了这么多空间?"
工作流:
  1. 运行
    scripts/analyze_large_files.py --threshold 100MB
  2. 呈现前20个大文件及相关上下文
  3. 分类:视频、数据集、归档文件、磁盘镜像
  4. 让用户决定删除哪些内容
  5. 执行已确认的删除操作
  6. 建议将文件归档到外部驱动器

Best Practices

最佳实践

  1. Start Conservative: Begin with obviously safe targets (caches, trash)
  2. Explain Everything: Users should understand what they're deleting
  3. Show Examples: List 3-5 example files from each category
  4. Respect User Pace: Don't rush through confirmations
  5. Document Results: Always show before/after space usage
  6. Educate: Include maintenance tips in final report
  7. Integrate Tools: Suggest Mole for users who prefer GUI
  1. 从保守开始:从明显安全的目标开始(缓存、废纸篓)
  2. 解释所有内容:用户应该了解他们要删除的是什么
  3. 提供示例:每个分类列出3-5个示例文件
  4. 尊重用户节奏:不要催促用户确认
  5. 记录结果:始终显示清理前后的空间使用情况
  6. 教育用户:在最终报告中包含维护建议
  7. 整合工具:为偏好图形界面的用户推荐Mole

When NOT to Use This Skill

不适用此技能的场景

  • User wants automatic/silent cleanup (against safety-first principle)
  • User needs Windows/Linux cleanup (macOS-specific skill)
  • User has <10% disk usage (no cleanup needed)
  • User wants to clean system files requiring SIP disable (security risk)
In these cases, explain limitations and suggest alternatives.
  • 用户需要自动/静默清理(违反安全优先原则)
  • 用户需要Windows/Linux系统的清理(本技能仅适用于macOS)
  • 用户磁盘使用率<10%(无需清理)
  • 用户需要清理需要禁用SIP的系统文件(存在安全风险)
在这些情况下,请说明限制并建议替代方案。",