refactor
Expert code refactoring based on Martin Fowler's catalog — improve maintainability without changing behavior. Covers code smells, composing methods, moving features, organizing data, simplifying conditionals, method calls, and generalization. Triggers on: refactor, 重构, clean up, improve code, code smell, extract method, rename, simplify.
Profile →npx skills add smallnest/goal-workflow --skill refactor --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Guides a developer to perform surgical refactoring focused on preserving external behavior while improving structure, readability, and maintainability. Emphasizes gradual, small steps, with tests and version control as core practices. Covers identifying code smells and applying techniques such as Extract Method, Move Method, Rename Method, and organizing data, guided by a catalog of refactoring techniques.
How it works
- Activates when code is hard to understand or maintain, functions/classes are large, smells are detected, or the user requests refactoring or cleanup.
- Enforces five non-negotiable rules: preserve behavior, small steps, leverage version control, rely on tests, and perform one change at a time.
- Provides a catalog of refactoring techniques (e.g., Extract Method, Inline Method, Move Method, Extract Class, Hide Delegate, Encapsulate Field, Replace Type Code with Class, etc.) with concrete mechanical steps per technique.
- For each technique, outlines the step-by-step mechanics (e.g., create a new method, move code, adjust parameters/return values, replace original call, test).
- Includes guidance on when not to refactor and scenarios to avoid, plus a set of code smells and the corresponding recommended refactorings.
When to use it
- When code is hard to understand or maintain
- When functions/classes have grown too large
- When code smells are detected
- When adding features is difficult due to poor structure
- When the user explicitly requests refactoring, cleanup, or improvement
- Trigger phrases include: refactor, 重构, clean up, improve code, code smell, extract method, rename, simplify
What it can touch
- Refactoring techniques touch methods, classes, and data structures; movement of features between objects; consolidation or decomposition of data and behavior. The skill enumerates techniques and their concrete mechanics, such as extracting methods, moving methods/fields, extracting classes, encapsulating fields, and replacing type codes with classes, among others.
Caveats
- Behavior must be preserved; tests are essential to detect regressions.
- Changes should be small and incremental, with commits after each successful step.
- Not a substitute for writing characterization tests when none exist.
- Includes conditions under which refactoring should not be attempted (e.g., no tests, tight deadlines, or no clear benefit).
- License: MIT
# Refactor — Expert Code Restructuring Surgical code refactoring based on Martin Fowler's <Refactoring> (2nd Edition) catalog. Improve structure, readability, and maintainability without changing external behavior. Gradual evolution, not revolution. --- ## When to Use This skill activates when: - Code is hard to understand or maintain - Functions/classes have grown too large - Code smells are detected - Adding features is difficult due to poor structure - User explicitly requests refactoring, cleanup, or improvement - User says: refactor, 重构, clean up, improve code, code smell, extract method, rename, simplify --- ## The Golden Rules These five rules are non-negotiable. Violating any of them turns refactoring into reckless editing. ### 1. Behavior is Preserved Only *how* the code works changes, never *what* it does. If tests existed before, they must pass after. If the refactoring introduces a behavioral change, it's not refactoring — it's rewriting. ### 2. Small Steps Each change should be the smallest possible transformation that compiles and passes tests. If a step breaks, you know exactly which change caused it. Refactoring is a series of tiny, safe transformations, not one big
- When to Use
- The Golden Rules
- 1. Behavior is Preserved
- 2. Small Steps
- 3. Version Control is Your Friend
- 4. Tests are Essential
- 5. One Thing at a Time
- When NOT to Refactor
- Code Smells Catalog
- Bloaters
- Object-Orientation Abusers
- Change Preventers
- Dispensables
- Couplers
What does the refactor skill do?
Expert code refactoring based on Martin Fowler's catalog — improve maintainability without changing behavior. Covers code smells, composing methods, moving features, organizing data, simplifying conditionals, method calls, and generalization. Triggers on: refactor, 重构, clean up, improve code, code smell, extract method, rename, simplify.
How do I install it?
Run `npx skills add smallnest/goal-workflow --skill refactor --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From smallnest/goal-workflow, a repository with 199 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.