Refactoring
Improving code design through systematic refactoring
Improve existing code design using Martin Fowler's systematic refactoring catalog. This skill helps your AI agent identify code smells, apply named refactoring patterns, and transform messy code into clean, well-structured designs — safely and incrementally.
Refactoring
npx skills add wondelai/skills/refactoring-patterns --global This skill is compatible with Claude, Claude Code, Claude Cowork, Codex, Cursor, OpenClaw, Hermes Agent, and other agentskills.io-compatible agents.
What is the Refactoring skill?
Install this free skill and your agent stops improvising structural changes. It works from Martin Fowler's catalogue instead — naming the smell it sees, picking the matching transformation, and applying it in steps small enough to keep the tests green, so behaviour never changes while the design does.
Key concepts from Refactoring your agent applies
Code Smells
Recognize symptoms like Long Method, Feature Envy, Data Clumps, and Shotgun Surgery that indicate deeper design problems.
Extract Method/Class
Pull out coherent pieces of logic into their own methods or classes to improve readability and reuse.
Replace Conditional with Polymorphism
Eliminate complex switch/if chains by using object-oriented polymorphism and strategy patterns.
Move Method/Field
Relocate behavior to the class that holds the data it operates on — keep behavior and data together.
Small, Safe Steps
Refactor in tiny increments with tests running between each step — never break working code.
When to use Refactoring — and when not to
Reach for it when
- You know the code should be restructured but want the change made in reviewable steps rather than one rewrite.
- A code review turned up smells — long method, feature envy, shotgun surgery — and you want them named and fixed.
- A conditional has grown a new branch every quarter and now drives the behaviour of half the module.
- You are preparing a messy area of the codebase for a feature that would otherwise be painful to add.
Reach for something else when
- There are no tests to protect the change — get a safety net first with Legacy Code.
- You are deciding what good code looks like rather than how to transform it — that is Clean Code.
- The problem is which module should own what — Clean Architecture or Domain-Driven Design fit better.
- The code is fine and you simply want a rewrite in a new framework; refactoring is explicitly not that.
Example prompts for the Refactoring skill
Identify code smells in this module and suggest specific refactorings using refactoring-patterns skill
Code reviewRefactor this switch statement using Replace Conditional with Polymorphism using refactoring-patterns skill
RefactoringBreak this god class into smaller, focused classes using refactoring-patterns skill
Design improvementPlan a safe, incremental refactoring sequence for this legacy code using refactoring-patterns skill
Legacy codeRefactoring vs the other Code Quality skills
All 5 Code Quality skills are free and install the same way — the only question is which framework fits the job in front of you.
| Skill | Based on | Best for |
|---|---|---|
| Clean Code | Clean Code — Robert C. Martin | Writing readable, maintainable code |
| Pragmatic Programmer | The Pragmatic Programmer — Andrew Hunt & David Thomas | Practical software craftsmanship |
| Refactoring | Refactoring — Martin Fowler | Improving code design through systematic refactoring |
| Software Design | A Philosophy of Software Design — John Ousterhout | Reducing complexity through thoughtful software design |
| Legacy Code | Working Effectively with Legacy Code — Michael C. Feathers | Safely change untested code: seams and characterization tests |
Frequently asked questions
How do I install the Refactoring skill?
Run npx skills add wondelai/skills/refactoring-patterns --global. It takes about 30 seconds and needs no account. The Refactoring skill then works in Claude, Claude Code, Claude Cowork, Codex, Cursor, OpenClaw and Hermes Agent — anything that reads the open agentskills.io format — and your agent loads it on its own when a task calls for it. It is free and MIT-licensed, and the source is at https://github.com/wondelai/skills.
Which book is the Refactoring skill based on?
It packages Refactoring by Martin Fowler — chief Scientist at Thoughtworks, author of multiple canonical SE books. The skill distils the book's method into instructions your agent follows while it works, covering code smells, extract method/class and replace conditional with polymorphism. It sits in the Code Quality part of the library.
Why insist on small steps if the end state is the same?
Because the end state is only the same if nothing goes wrong. Each named refactoring is small enough to keep the tests passing between steps, so when behaviour does change you know it happened in the last two minutes of work rather than somewhere in a thousand-line diff. It also keeps the change reviewable and revertable at any point.
Can it refactor code that has no tests?
It can, but it shouldn't, and the skill will say so. Refactoring is defined as changing structure without changing behaviour, and without tests you have no way to know you succeeded. Install the Legacy Code skill for that case: it covers finding seams and writing characterization tests that pin current behaviour first.
Does it only know the refactorings in the book?
It works from Fowler's catalogue, which is the point — named refactorings are a shared vocabulary, so "extract this into a method object" means the same thing to you, your agent, and the next person reading the commit. It will still restructure code that doesn't map to a catalogued move; you just lose the shared name for it.
Install Refactoring
Free, open-source, and ready in 30 seconds.
npx skills add wondelai/skills/refactoring-patterns --global MIT Licensed · Works with Claude, Claude Code, Claude Cowork, Codex, Cursor, OpenClaw, Hermes Agent & other agentskills.io agents · No account needed
Don’t guess your AI engineering level.
Measure it.
AI Developer Scorecard
How production-grade is your AI engineering?
Twenty-five questions across the practices that separate vibe-coding from production-grade engineering. Instant score, per-section breakdown, and a 30/60/90-day playbook.
Score 0–75 · 30/60/90-day playbook Score yourself For CTOs & foundersCTO Scorecard
Is your engineering team ready for AI at scale?
Twenty-five questions on how your org adopts AI — adoption, governance, automation, and ROI. See where you sit on the path from Reactive to Strategic Leader.
Score 0–75 · Reactive → Strategic Leader Score your orgWe build the skills you already use. Now we’ll build yours.
Sprints from $3K · shipped to production, or you don’t pay the final milestone.