/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,
$ npx -y skills add smallnest/goal-workflow --skill refactor --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/refactor
Context preview
The summary Claude sees to decide when to auto-load this skill.
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,
SKILL.md
refactor.SKILL.mdname: refactor
description: "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."
user-invocable: true
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 rewrite.
3. Version Control is Your Friend
Commit before starting. Commit after each successful step. This gives you infinite undo. Branch from a clean state so you can abandon the refactoring without consequences.
4. Tests are Essential
"Without tests, you're not refactoring — you're just editing." If tests don't exist for the target code, write characterization tests first. These tests capture the current behavior so you can detect regressions.
5. One Thing at a Time
Never mix refactoring with feature changes. Never refactor two unrelated things simultaneously. Each commit should contain exactly one refactoring operation.
---
When NOT to Refactor
| Scenario | Action | |----------|--------| | Code works and won't change again | Leave it alone | | Critical production path with no tests | Write characterization tests first | | Under tight deadline pressure | Document the smell, refactor later | | No clear purpose or benefit | Don't refactor for refactoring's sake | | Code is fundamentally wrong | This is a rewrite, not a refactoring |
---
Code Smells Catalog
Based on Fowler's taxonomy. Before refactoring, identify which smell is present.
Bloaters
| Smell | Description | Primary Refactoring | |-------|-------------|-------------------| | **Long Method** | Method > 10-15 lines, doing multiple things | Extract Method, Replace Temp with Query | | **Large Class** | Class with too many fields/methods (God Object) | Extract Class, Extract Subclass | | **Primitive Obsession** | Using primitives instead of small objects | Replace Data Value with Object, Replace Type Code with Class | | **Long Parameter List** | Method with > 3-4 parameters | Introduce Parameter Object, Preserve Whole Object | | **Data Clumps** | Same group of data appearing together | Extract Class, Introduce Parameter Object |
Object-Orientation Abusers
| Smell | Description | Primary Refactoring | |-------|-------------|-------------------| | **Switch Statements** | Repeated switch/if-else on type codes | Replace Conditional with Polymorphism, Replace Type Code with Subclasses | | **Temporary Field** | Field only set in certain circumstances | Extract Class, Introduce Null Object | | **Refused Bequest** | Subclass doesn't use inherited members | Replace Inheritance with Delegation, Push Down Method/Field | | **Alternative Classes with Different Interfaces** | Classes doing similar things with different names | Rename Method, Move Method, Extract Superclass |
Change Preventers
| Smell | Description | Primary Refactoring | |-------|-------------|-------------------| | **Divergent Change** | One class changed for different reasons | Extract Class | | **Shotgun Surgery** | One change requires many small changes across classes | Move Method, Move Field, Inline Class | | **Parallel Inheritance Hierarchies** | Adding a subclass to one hierarchy forces adding to another | Move Method, Move Field |
Dispensables
| Smell | Description | Primary Refactoring | |-------|-------------|-------------------| | **Comments** | Comments explaining what code does (not why) | Extract Method, Rename Variable, Introduce Assertion | | **Duplicate Code** | Same code structure in multiple places | Extract Method, Pull Up Method, Form Template Method | | **Lazy Class** | Class doing too little to justify existence | Inline Class, Collapse Hierarchy | | **Data Class** | Class with only fields and getters/setters | Move Method, Encapsulate Field, Encapsulate Collection | | **Dead Code** | Unused code, imports, commented-out blocks | Delete it (git history has it) | | **Speculative Generality** | Code built for "someday" that never came | Inline Class, Collapse Hierarchy, Remove Parameter |
Couplers
| Smell | Description | Primary Refactoring | |-------|-------------|-------------------| | **Feature Envy** | Method uses another class's data more than its own | Move Method, Extract Method + Move Method | | **Inappropriate Intimacy** | Classes know too much about each other's internals | Move Method, Move Field, Replace Delegation with Hidden Delegate | | **Message Chains** | `a.getB().getC().getD().doSomething()` | Hide Delegate, Extract Method | | **Middle Man** | Class delegates everything to another class | Remove Middle Man, Inline Method | | **Incomplete Library Class** | Library missing methods you need | Introduce
Read more
name: refactor description: "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." user-invocable: true
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 rewrite.
3. Version Control is Your Friend
Commit before starting. Commit after each successful step. This gives you infinite undo. Branch from a clean state so you can abandon the refactoring without consequences.
4. Tests are Essential
"Without tests, you're not refactoring — you're just editing." If tests don't exist for the target code, write characterization tests first. These tests capture the current behavior so you can detect regressions.
5. One Thing at a Time
Never mix refactoring with feature changes. Never refactor two unrelated things simultaneously. Each commit should contain exactly one refactoring operation.
---
When NOT to Refactor
| Scenario | Action | |----------|--------| | Code works and won't change again | Leave it alone | | Critical production path with no tests | Write characterization tests first | | Under tight deadline pressure | Document the smell, refactor later | | No clear purpose or benefit | Don't refactor for refactoring's sake | | Code is fundamentally wrong | This is a rewrite, not a refactoring |
---
Code Smells Catalog
Based on Fowler's taxonomy. Before refactoring, identify which smell is present.
Bloaters
| Smell | Description | Primary Refactoring | |-------|-------------|-------------------| | **Long Method** | Method > 10-15 lines, doing multiple things | Extract Method, Replace Temp with Query | | **Large Class** | Class with too many fields/methods (God Object) | Extract Class, Extract Subclass | | **Primitive Obsession** | Using primitives instead of small objects | Replace Data Value with Object, Replace Type Code with Class | | **Long Parameter List** | Method with > 3-4 parameters | Introduce Parameter Object, Preserve Whole Object | | **Data Clumps** | Same group of data appearing together | Extract Class, Introduce Parameter Object |
Object-Orientation Abusers
| Smell | Description | Primary Refactoring | |-------|-------------|-------------------| | **Switch Statements** | Repeated switch/if-else on type codes | Replace Conditional with Polymorphism, Replace Type Code with Subclasses | | **Temporary Field** | Field only set in certain circumstances | Extract Class, Introduce Null Object | | **Refused Bequest** | Subclass doesn't use inherited members | Replace Inheritance with Delegation, Push Down Method/Field | | **Alternative Classes with Different Interfaces** | Classes doing similar things with different names | Rename Method, Move Method, Extract Superclass |
Change Preventers
| Smell | Description | Primary Refactoring | |-------|-------------|-------------------| | **Divergent Change** | One class changed for different reasons | Extract Class | | **Shotgun Surgery** | One change requires many small changes across classes | Move Method, Move Field, Inline Class | | **Parallel Inheritance Hierarchies** | Adding a subclass to one hierarchy forces adding to another | Move Method, Move Field |
Dispensables
| Smell | Description | Primary Refactoring | |-------|-------------|-------------------| | **Comments** | Comments explaining what code does (not why) | Extract Method, Rename Variable, Introduce Assertion | | **Duplicate Code** | Same code structure in multiple places | Extract Method, Pull Up Method, Form Template Method | | **Lazy Class** | Class doing too little to justify existence | Inline Class, Collapse Hierarchy | | **Data Class** | Class with only fields and getters/setters | Move Method, Encapsulate Field, Encapsulate Collection | | **Dead Code** | Unused code, imports, commented-out blocks | Delete it (git history has it) | | **Speculative Generality** | Code built for "someday" that never came | Inline Class, Collapse Hierarchy, Remove Parameter |
Couplers
| Smell | Description | Primary Refactoring | |-------|-------------|-------------------| | **Feature Envy** | Method uses another class's data more than its own | Move Method, Extract Method + Move Method | | **Inappropriate Intimacy** | Classes know too much about each other's internals | Move Method, Move Field, Replace Delegation with Hidden Delegate | | **Message Chains** | `a.getB().getC().getD().doSomething()` | Hide Delegate, Extract Method | | **Middle Man** | Class delegates everything to another class | Remove Middle Man, Inline Method | | **Incomplete Library Class** | Library missing methods you need | Introduce
An AI-driven development workflow — from PRD to shipped code, all within Claude Code.
Other skills on goal-workflow-skills.
- /article-icons
Illustrate an article (Markdown, HTML, etc.) with animated-style icons from itshover.com/icons. Fetches icons as clean inline SVG and places them at section headings, key concepts, lists, and callouts. Triggers on: /article-icons, 配图, 给文章配图标, add icons to article, illustrate
Open skill - /code-to-spec
Reverse-engineer a SPEC document from an existing project. Analyzes code, config, tests, and structure to produce a comprehensive specification. Triggers on: code-to-spec, reverse spec, generate spec, 逆向规格, 生成规格文档, 生成设计文档, 生成设计方案, extract spec, document this project, what does
Open skill - /graph
Graph engineering for parallel task execution: convert a task, PRD, SPEC, or issue set into a dependency graph (DAG), layer it into supersteps, then implement each independent node concurrently with subagents — each node runs /goal → /review-it → /ship-it in an isolated git
Open skill - /humanize-it
对指定文档进行去 AI 味的改写。自动选择最合适的人性化策略(humanizer-zh / humanize-chinese / technical-writing), 迭代改写直到效果达标或迭代 42 次为止。适用于中文文本的去 AI 化处理,包括通用文章、技术文档、学术论文等。 Use when user says: "humanize this", "去AI味", "降AIGC", "人性化改写", "改成人话", "去除AI痕迹", "humanize document", "make text human-like", "去机器味",
Open skill - /insight-diagram
为任意项目生成 UML 图、架构图和流程图。分析代码库后让用户选择要生成的图表类型,使用 architecture-diagram skill 渲染为 HTML+SVG,保存到 docs/ 目录。适用于任何软件项目的文档可视化。
Open skill - /listenhub-tts
使用 ListenHub API 将文本转换为语音(TTS)。支持三种模式:快速合成(/v1/tts)、 多角色脚本(/v1/speech)、长文本流式合成(/v1/flow-speech/episodes)。 音色未指定时自动获取音色列表供用户选择,默认使用 chat-girl-105-cn(晓曼)。 Use when user says: "tts", "text to speech", "语音合成", "文字转语音", "朗读", "生成语音", "生成音频", "转音频", "text to audio"
Open skill

