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
Refactoring by Martin Fowler

Refactoring

by Martin Fowler

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.

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.

More on Martin Fowler: Wikipedia Wikidata

View Book →

Example prompts for the Refactoring skill

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

Code review

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

Refactoring

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

Design improvement

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

Legacy code

Refactoring 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.

SkillBased onBest for
Clean CodeClean Code — Robert C. MartinWriting readable, maintainable code
Pragmatic ProgrammerThe Pragmatic Programmer — Andrew Hunt & David ThomasPractical software craftsmanship
RefactoringRefactoring — Martin FowlerImproving code design through systematic refactoring
Software DesignA Philosophy of Software Design — John OusterhoutReducing complexity through thoughtful software design
Legacy CodeWorking Effectively with Legacy Code — Michael C. FeathersSafely 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

Work with us

We build the skills you already use. Now we’ll build yours.

Custom skills · Subagents · MCP integrations — shipped to production, not demoed.

Sprints from $3K · shipped to production, or you don’t pay the final milestone.