Code Quality

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.

Updated Free & MIT-licensed

npx skills add wondelai/skills/refactoring-patterns --global

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.

01 Code Smells Recognize symptoms like Long Method, Feature Envy, Data Clumps, and Shotgun Surgery that indicate deeper design problems.
02 Extract Method/Class Pull out coherent pieces of logic into their own methods or classes to improve readability and reuse.
03 Replace Conditional with Polymorphism Eliminate complex switch/if chains by using object-oriented polymorphism and strategy patterns.
04 Move Method/Field Relocate behavior to the class that holds the data it operates on — keep behavior and data together.
05 Small, Safe Steps Refactor in tiny increments with tests running between each step — never break working code.

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.

example prompts
# 01 · Code review

Identify code smells in this module and suggest specific refactorings using refactoring-patterns skill

# 02 · Refactoring

Refactor this switch statement using Replace Conditional with Polymorphism using refactoring-patterns skill

# 03 · Design improvement

Break this god class into smaller, focused classes using refactoring-patterns skill

# 04 · Legacy code

Plan a safe, incremental refactoring sequence for this legacy code using refactoring-patterns skill

06 About the author

Martin Fowler

Chief Scientist at Thoughtworks, author of multiple canonical SE books

Martin Fowler is the Chief Scientist at Thoughtworks and one of the most influential voices in software design. He has authored or co-authored multiple canonical software engineering books and is known for popularizing refactoring, continuous integration, and domain-specific languages.

08 Questions

Before you install.

01

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.

02

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.

03

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.

04

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.

05

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.

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

  We build the skills you already use. Now we’ll build yours. See what we build  ·  Book a 15-min call