Agent skill

Refactor Advisor

by laolaoshiren in laolaoshiren/claude-code-skills-zh

“重构顾问 - 识别代码坏味道并提供重构方案”

— description from SKILL.md by laolaoshiren
MITAuto-check passedDevelopment

Install Refactor Advisor

skills CLI
$ npx skills add laolaoshiren/claude-code-skills-zh --skill refactor-advisor -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install laolaoshiren/claude-code-skills-zh refactor-advisor --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/laolaoshiren/claude-code-skills-zh.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/refactor-advisor .claude/skills/refactor-advisor && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
refactor-advisor
GitHub stars
879
Token cost
~456 tokens
SKILL.md length
119 words
Files
1
Skills in repo
19
Repo updated
First seen
Licence
MIT

At a glance

  • Works in 3 steps: 影响范围 — 被引用/调用次数越多,优先级越高 → 变更频率 — git log 频繁改动的文件优先 → 修复成本 — 成本低且收益高的优先处理
  • SKILL.md covers 触发条件, 工作流程, 常见坏味道检测 and 输出格式, plus 1 more section
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

About this skill

Refactor Advisor is a skill in laolaoshiren/claude-code-skills-zh (879 stars). Its SKILL.md is about 456 tokens. Licence: MIT.

Workflow steps

3 steps, taken from the first numbered list in SKILL.md.

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

What it can do on your machine

Read from SKILL.md and the folder at commit 633f21c. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are markdown and typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Refactor Advisor loads about 456 tokens when it runs. Until then it costs about 10 tokens; SKILL.md has 119 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~10
When it runs · the whole SKILL.md, loaded when a task matches
~456

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from laolaoshiren/claude-code-skills-zh at commit 633f21c, republished under its MIT licence (© laolaoshiren). 119 words, ~456 tokens.

Download SKILL.mdSave it as .claude/skills/refactor-advisor/SKILL.md (or your agent's skills folder).
name
refactor-advisor
description
重构顾问 - 识别代码坏味道并提供重构方案

代码重构顾问

触发条件

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

工作流程

第 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提取中间变量🟢
全局可变状态全局变量被多处修改封装为模块/引入依赖注入🔴
过度耦合模块间相互依赖依赖反转、引入接口🟡

输出格式

完整报告模板
markdown
# 代码重构报告

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

## 问题列表

### 问题 1:[问题标题]
- **📍 位置**:`src/services/user.ts:45-120`
- **🔍 问题**:该函数长达 75 行,包含 3 层嵌套,职责不单一
- **🛠️ 重构方案**:
  - 提取 `validateUserData()` 方法
  - 提取 `saveToDatabase()` 方法
  - 使用卫语句替代嵌套 if
- **⚠️ 风险评估**:
  - 该函数被 12 处调用,需全面回归测试
  - 建议先添加单元测试再重构
- **Before**:
  ```typescript
  function processUser(data) { /* 75行... */ }
  • After:
    typescript
    function processUser(data) {
      const validated = validateUserData(data);
      return saveToDatabase(validated);
    }

重构路线图

阶段内容优先级预估
P1修复 🔴 严重问题高2天
P2处理 🟡 中等问题中3天
P3优化 🟢 轻微问题低1天

## 注意事项
- 重构前确保有足够的测试覆盖
- 每次重构尽量小步提交,便于回滚
- 重构不应改变外部行为(行为保持)
- 大规模重构建议分阶段进行,每阶段独立可验证
- 关注重构过程中的性能回退风险

© laolaoshiren, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/refactor-advisor of laolaoshiren/claude-code-skills-zh.

Open the folder on GitHubat commit 633f21c

Compare with similar skills

Refactor Advisor next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Refactor Advisor compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Refactor Advisor this skilllaolaoshiren/claude-code-skills-zh879—~456Automated safety check: PassMIT
Guidelinesakash-network/node1.1k20 repos~577Automated safety check: PassMIT
Component Refactoringlangflow-ai/langflow155k—~3.5kAutomated safety check: PassMIT
Migrate Core Code to Submodulestinyhumansai/openhuman42k—~2.6kAutomated safety check: PassGPL-3.0
ast-grep Structural Searchcode-yeongyu/oh-my-openagent70k—~3.3kAutomated safety check: PassMIT
Systematic Code Refactoringluongnv89/claude-howto42k—~3kAutomated safety check: PassMIT

Similar skills

  • Guidelines

    akash-network/node

    Behavioral guidelines to reduce common LLM coding mistakes. An agent skill from akash-network/node.

    1.1k GitHub starsUsed in 20 repos~577 tokens
    DevelopmentAuto-check passed
  • Component Refactoring

    langflow-ai/langflow

    Refactor high-complexity React components in Langflow frontend.

    155k GitHub stars~3.5k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Migrate Core Code to Submodules

    tinyhumansai/openhuman

    Plans and carries out moving non-host-specific code and its tests from the OpenHuman core into vendored tiny submodule libraries, then releases the submodule and re-pins the host.

    42k GitHub stars~2.6k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • ast-grep Structural Search

    code-yeongyu/oh-my-openagent

    Searches and rewrites code by syntax-tree shape across 25 languages with ast-grep, for codemods, structural queries and YAML lint rules, using a Python wrapper script.

    70k GitHub stars~3.3k tokensUpdated today
    DevelopmentAuto-check passed
  • Systematic Code Refactoring

    luongnv89/claude-howto

    Guides refactoring in phases based on Martin Fowler's method: research, test coverage check, planning and small tested steps, with your approval at each phase.

    42k GitHub stars~3k tokensUpdated 9 days ago
    DevelopmentAuto-check passed
  • Codex

    skills-directory/skill-codex

    A skill your agent uses when the user asks to run Codex CLI (codex exec, codex resume) or references OpenAI Codex for code analysis, refactoring, or automated editing

    1.5k GitHub starsUsed in 3 repos~1.8k tokens
    DevelopmentAuto-check passed

More from laolaoshiren/claude-code-skills-zh

All 19 skills in this repo
  • API Tester

    laolaoshiren/claude-code-skills-zh

    依据真实 OpenAPI、路由实现和现有测试生成并验证 API 测试。用于用户要求测试接口、补集成测试、验证 API 契约、生成回归用例或排查接口兼容性时;区分“生成测试”和“执行请求”的授权,不猜测状态码、响应结构或 SLA,不在未确认环境中发送写请求。

    879 GitHub stars~614 tokensUpdated 4 days ago
    Auto-check passed
  • Dep Auditor

    laolaoshiren/claude-code-skills-zh

    审计 Node.js、Python、Go、Rust、JVM、Ruby 项目的依赖漏洞、版本健康度与许可证事实;当用户要求检查 package.json、lockfile、requirements、go.mod、Cargo.toml、pom.xml、Gemfile.lock,或生成不改依赖的中文审计报告时使用

    879 GitHub stars~895 tokensUpdated 4 days ago
    Auto-check passed
  • Eslint Fix

    laolaoshiren/claude-code-skills-zh

    安全诊断并修复 ESLint error、warning 和配置兼容问题。用于用户要求运行 lint、解释 ESLint 报错、限定范围自动修复或迁移 ESLint 配置时;优先使用项目锁定的包管理器与版本,先预检再修改,不自动下载最新版或批量改写无关源码。

    879 GitHub stars~436 tokensUpdated 4 days ago
    Auto-check passed
  • Git Workflow

    laolaoshiren/claude-code-skills-zh

    安全处理 Git 状态检查、提交信息、commit、分支、push、PR 和 rebase。用于用户要求检查改动、生成或创建提交、管理分支、推送、发起 PR 或整理历史时;严格区分每个动作的授权,并保护工作树中已有和无关的修改。

    879 GitHub stars~513 tokensUpdated 4 days ago
    Auto-check passed
  • GitHub Actions Gen

    laolaoshiren/claude-code-skills-zh

    分析真实项目并生成或修订安全、可验证的 GitHub Actions workflow;当用户要求创建 CI、测试矩阵、构建、Release、部署、缓存、Secrets、OIDC、PR 自动化或排查 workflow 配置时使用

    879 GitHub stars~1.1k tokensUpdated 4 days ago
    Auto-check: notes
  • Skill Curator

    laolaoshiren/claude-code-skills-zh

    中文 Skill 收录评估器。用于核验 GitHub 上的 Claude Code、Codex、Agent Skills、Plugin、MCP、CLI 或 Agent 工作流是否值得加入精选列表;检查真实资产、安装方式、活跃度、重复项和安全边界,并生成分类、中文描述与可追溯证据。

    879 GitHub stars~756 tokensUpdated 4 days ago
    Auto-check passed

Categories

Questions about Refactor Advisor

How do I install Refactor Advisor in Claude Code?

Run `npx skills add laolaoshiren/claude-code-skills-zh --skill refactor-advisor -a claude-code`. Or copy the skill folder (skills/refactor-advisor in laolaoshiren/claude-code-skills-zh) into .claude/skills/refactor-advisor in your project. Claude Code loads it when a task matches its description.

How do I install Refactor Advisor in Codex?

Run `npx skills add laolaoshiren/claude-code-skills-zh --skill refactor-advisor -a codex`. Or copy the skill folder (skills/refactor-advisor in laolaoshiren/claude-code-skills-zh) into .agents/skills/refactor-advisor in your project. Codex loads it when a task matches its description.

Can I use Refactor Advisor in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add laolaoshiren/claude-code-skills-zh --skill refactor-advisor -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/refactor-advisor, .gemini/skills/refactor-advisor, .github/skills/refactor-advisor and .opencode/skills/refactor-advisor in your project.

What does Refactor Advisor need to run?

SKILL.md names no scripts, command-line tools or credentials: Refactor Advisor is instructions for the agent only.

Does Refactor Advisor access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Refactor Advisor safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Refactor Advisor use?

Refactor Advisor is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Refactor Advisor use?

About 456 tokens (SKILL.md is roughly 1.8k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Refactor Advisor?

Skills that share tags, products or a category with Refactor Advisor: Guidelines (akash-network/node, 1.1k stars), Component Refactoring (langflow-ai/langflow, 155k stars), Migrate Core Code to Submodules (tinyhumansai/openhuman, 42k stars) and ast-grep Structural Search (code-yeongyu/oh-my-openagent, 70k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Refactor Advisor?

laolaoshiren (a GitHub user) maintains it in laolaoshiren/claude-code-skills-zh, which has 879 GitHub stars. The repository holds 19 skills in this directory. The repository was last updated on October 5, 2026.

Source: laolaoshiren/claude-code-skills-zh on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.