Skip to content

清理命令 (/cleanup)

项目清理和技术债务管理命令,帮助维护代码库的整洁性和性能。

核心功能

  • 代码清理: 移除无用代码、注释和导入
  • 依赖管理: 清理未使用的依赖包
  • 文件整理: 删除临时文件和重复文件
  • 性能优化: 清理缓存和优化资源
  • 技术债务: 识别并修复技术债务

使用语法

bash
/cleanup [类型] [目标] [选项]

清理类型

  • code - 代码清理
  • dependencies - 依赖清理
  • files - 文件清理
  • cache - 缓存清理
  • all - 全面清理

主要选项

  • --dry-run - 预览清理操作
  • --safe - 安全模式(保留备份)
  • --aggressive - 深度清理
  • --interactive - 交互确认模式

清理功能详解

代码清理

bash
# 移除未使用的导入
/cleanup code --unused-imports

# 清理无用的变量和函数
/cleanup code --dead-code --safe

# 格式化和规范化代码
/cleanup code --format --lint-fix

依赖清理

bash
# 检测未使用的依赖
/cleanup dependencies --unused --dry-run

# 更新过时的依赖
/cleanup dependencies --outdated --security-fixes

# 清理node_modules并重新安装
/cleanup dependencies --reinstall --clean

文件清理

bash
# 清理临时文件
/cleanup files --temp --log-files

# 移除重复文件
/cleanup files --duplicates --confirm

# 清理构建产物
/cleanup files --build-artifacts --cache

清理报告

清理前分析

bash
# 生成清理建议报告
/cleanup --analyze --report

# 输出示例:
# 清理分析报告
# - 未使用的依赖: 12个 (节省 45MB)
# - 无用代码: 23个文件 (减少 8%)
# - 临时文件: 156个 (释放 128MB)
# - 缓存文件: 89个 (释放 256MB)

清理后统计

bash
# 显示清理效果
/cleanup --statistics

# 输出示例:
# 清理完成统计
# - 文件减少: 245个
# - 空间释放: 512MB
# - 构建时间提升: 15%
# - 依赖安全漏洞: 修复3个

安全特性

备份机制

bash
# 清理前自动备份
/cleanup --backup --timestamp

# 恢复备份
/cleanup --restore --backup-id=20231201_143025

确认机制

bash
# 交互式确认每个操作
/cleanup --interactive

# 危险操作二次确认
/cleanup code --dead-code --confirm-dangerous

性能优化

构建优化

bash
# 清理构建缓存并重新构建
/cleanup cache --build --rebuild

# 优化打包体积
/cleanup --bundle-analysis --tree-shaking

资源优化

bash
# 压缩图片资源
/cleanup files --images --compress

# 清理无用的CSS和JS
/cleanup code --unused-styles --unused-scripts

最佳实践

定期清理计划

bash
# 设置自动清理计划
/cleanup --schedule --weekly --safe-mode

# CI/CD集成清理
/cleanup --ci --fail-on-issues

团队协作

bash
# 生成清理清单
/cleanup --checklist --team-review

# 清理前后对比
/cleanup --before-after --visual-diff

清理命令 - 保持代码库整洁高效

Claude Code 使用指南