skills/development-workflows/code-refactor/SKILL.md
Implement safe, behavior-preserving code refactors after inspecting the existing project. Use when the user asks to refactor code, split large files or modules, extract functions or methods, reduce duplicated logic, rename confusing classes/functions/variables, improve code comments, remove unused or dead code, or says 重构代码, 拆分模块, 提取方法, 减少重复代码, 优化命名, 优化注释, 删除未调用代码. For broad refactor requests, plan safe slices and wait for approval; for narrow scoped requests, directly implement the smallest verifiable slice.
npx skillsauth add bahayonghang/my-claude-code-settings code-refactorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Refactor existing code without changing behavior. The skill's job is to make code easier to understand, modify, and test while keeping the observable contract stable.
Refactoring is not a license for broad cleanup. Treat every edit as a behavior-preserving transformation with evidence, a bounded target, and verification.
Choose the mode from the user's scope.
code-quality-review instead.improve-codebase-architecture instead.Classify the requested work before editing. A task may include more than one type, but execute one coherent slice at a time.
| Type | Use when | Good outcome | | --- | --- | --- | | Module split | A file or subsystem mixes unrelated responsibilities | Files align with functional modules, ownership, and test boundaries | | Function/method extraction | One function has multiple small behaviors or hidden phases | Public API stays small; private helpers name meaningful substeps | | Duplicate consolidation | Similar logic appears repeatedly and may drift | A shared helper removes real duplication without adding thin indirection | | Naming cleanup | Names hide intent, encode stale details, or force readers to inspect implementation | Names are concise, intention-revealing, and consistent with local style | | Comment cleanup | Comments repeat code, miss invariants, or hide key assumptions | Comments explain why, contracts, edge cases, and non-obvious decisions | | Dead-code removal | Code appears uncalled, stale, or orphaned | Removal is backed by call-site, export, framework, and verification checks |
Establish scope
AGENTS.md, nested guidance, code_map.md, package docs, and nearby tests.Build evidence
Set a baseline
Plan the slice
Apply the refactor
ts-morph, jscodeshift, ast-grep, rope, OpenRewrite, IDE refactors, or project-native lint fixes.Verify and inspect
Report
Use the strongest tool already available in the project:
ts-morph, jscodeshift, ast-grep, ESLint autofix.rope, ruff, pyright, mypy, vulture, autoflake, project tests.ast-grep or Comby for bounded syntax-aware patterns.If a tool is not installed, do not install it automatically. Explain the manual fallback or ask before adding dependencies.
Stop and ask for approval or clarification when:
For direct implementation, report:
## Scope
## Baseline
## Refactor Plan
## Edits Made
## Verification
## Residual Risk
For broad or risky requests, stop before editing and report:
## Findings
## Recommended Refactor Slices
## Required Decision
## Verification Plan
development
Use only when the user explicitly asks for swarm, subagents, parallel agents, dynamic workflow, multi-agent orchestration, 多智能体编排, or when the task truly needs coordinated research plus implementation plus review plus verification packets. Do not use for ordinary code review, planning-only work, single-line bugfixes, routine audits, or migrations unless orchestration is requested or at least two independent workflow dimensions are present.
development
Run a code quality review focused on maintainability, structure, abstraction quality, file growth, branching complexity, boundary cleanliness, and refactoring opportunities. Use when the user asks for code quality review, code review, maintainability review, architecture quality review, PR code quality feedback, 代码质量审查, 代码质量 review, 可维护性审查, 架构质量审查, or review comments about code structure. Do not use for pure security review, formatting-only review, performance profiling, or implementation tasks unless the user also asks for a code quality review.
development
Plan-first brainstorming workflow that turns an idea into an approved Markdown implementation plan by default. Use when the user wants to brainstorm, design, scope, or plan a feature/spec before implementation. Spark explores project context, asks only blocking questions, writes the plan under the project root's .plannings/YYYY-MM-DD-feature-slug.md path, self-reviews it, and waits for user approval. Create an HTML or visual plan/spec only when the user explicitly asks for HTML, browser-viewable, or visual output; save the paired .html beside the Markdown plan.
development
Run a code quality review focused on maintainability, structure, abstraction quality, file growth, branching complexity, boundary cleanliness, and refactoring opportunities. Use when the user asks for code quality review, code review, maintainability review, architecture quality review, PR code quality feedback, 代码质量审查, 代码质量 review, 可维护性审查, 架构质量审查, or review comments about code structure. Do not use for pure security review, formatting-only review, performance profiling, or implementation tasks unless the user also asks for a code quality review.