When you need to clean up messy code but don't want to dig through refactoring catalogs, this skill scans for the usual suspects: long methods over 50 lines, classes pushing 300 lines, nested conditionals three levels deep, magic numbers, and functions with too many parameters. It gives you specific locations, explains what's wrong, and shows before/after code for fixes like Extract Method or Guard Clauses. The structured output format (location, problem, solution, warnings) keeps things practical. It's basically a refactoring checklist that actually shows you the rewrites instead of just naming patterns. Good for getting a second pair of eyes on code that works but smells off.

skills.sh installs
117
GitHub stars
906
last updated
May 13, 2026

Install

$ npx -y skills add laolaoshiren/claude-code-skills-zh --skill refactor-advisor --agent claude-code

Installs into .claude/skills of the current project.

Files

代码重构顾问

触发条件

当用户要求重构代码、优化代码结构、改善代码质量、消除技术债务时激活此技能。

工作流程

第 1 步:扫描代码库

  • 使用 grep/rg 扫描目标目录,识别潜在坏味道
  • 统计文件行数、函数长度、参数数量等指标
  • 查找重复代码块(相似度 > 80%)

第 2 步:分类坏味道

按严重程度分类发现的问题:

等级含义说明
🔴 严重必须立即修复影响可维护性和稳定性
🟡 中等建议尽快修复降低代码可读性
🟢 轻微可择机优化不影响功能但有改进空间

第 3 步:优先级排序

按以下维度综合排序:

  1. 影响范围 — 被引用/调用次数越多,优先级越高
  2. 变更频率 — git log 频繁改动的文件优先
  3. 修复成本 — 成本低且收益高的优先处理

第 4 步:输出重构方案

常见坏味道检测

坏味道特征重构手法等级
长方法函数超过 50 行提取方法 (Extract Method)🔴
大类类超过 300 行提取类 (Extract Class)🔴
重复代码相似代码块出现 3+ 次提取公共方法🔴
过长参数函数参数超过 4 个引入参数对象🟡
嵌套过深if/for 嵌套 3+ 层卫语句 (Guard Clause)🟡
魔法数字硬编码的数字提取为常量🟢
过长链式调用a.b.c.d.e提取中间变量🟢
全局可变状态全局变量被多处修改封装为模块/引入依赖注入🔴
过度耦合模块间相互依赖依赖反转、引入接口🟡

输出格式

完整报告模板

# 代码重构报告

## 概要
- 扫描文件数:XXX
- 发现问题数:XX(🔴 X / 🟡 X / 🟢 X)
- 预估工作量:X 天

## 问题列表

Sponsors

Details

Repository
github.com/laolaoshiren/claude-code-skills-zh
Category
Code Review & Quality
License
MIT
First seen
Jun 11, 2026

More from laolaoshiren/claude-code-skills-zh

All 19
1erichowens avatarskill-architecterichowens/some_claude_skillsskill architect116skills.sh installs
2daffy0208 avatardesign-system-architectdaffy0208/ai-dev-standardsBuild scalable, maintainable design systems that unify product experiences. Use when creating component libraries, design tokens, or establishing design standar0skills.sh installs
3ganyuanran avatarfirst-principles-reviewganyuanran/aegisThis is a compositional skill that runs a lightweight decision checkpoint before other workflows commit to a direction.0skills.sh installs
4hoangnguyen0403 avatarcodebase-reviewhoangnguyen0403/agent-skills-standardReview an entire codebase against framework best practices and generate a prioritized improvement plan.0skills.sh installs
5mattpocock avatarimprove-codebase-architecturemattpocock/skillsScan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.1.2Mskills.sh installs
6juliusbrussee avatarcaveman-reviewjuliusbrussee/cavemanUltra-compressed code review comments. Cuts noise from PR feedback while preserving the actionable signal. Each comment is one line: location, problem, fix. Use427.5Kskills.sh installs