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.
npx skills add wondelai/skills/refactoring-patterns --global
Refactoring Martin Fowler View on Amazon
02 What it is
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.
03 Key concepts
Five principles your agent applies.
Drawn from Refactoring — not advice it repeats back to you, but decisions it makes while it works.
04 Fit
When to use it, and
when not to.
four symptoms it fixes, and four it doesn't.
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.
05 Prompts
Say it like this.
Name the skill at the end of a prompt and the agent applies the framework rather than a vibe. Or say nothing — it loads on its own when a task matches.
Identify code smells in this module and suggest specific refactorings using refactoring-patterns skill
Refactor this switch statement using Replace Conditional with Polymorphism using refactoring-patterns skill
Break this god class into smaller, focused classes using refactoring-patterns skill
Plan a safe, incremental refactoring sequence for this legacy code using refactoring-patterns skill
06 About the author
07 Same stack
The stack it sits in.
Six Code Quality skills. Most people run two: this one, and whichever fits the next problem.
All Code Quality skills08 Questions
Before you install.
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.
09 Guides that use it
Put it to work.
Long-form playbooks where this skill does part of the job.
One skill, one command.
Install Refactoring, or the whole stack.
npx skills add wondelai/skills/refactoring-patterns --global MIT licensed · Claude, Claude Code, Codex, Cursor, OpenClaw, Hermes · No account