# Refactoring

> Improving code design through systematic refactoring — an AI agent skill based on *Refactoring* by Martin Fowler.

Published 2026-02-23 · Updated 2026-08-17 · Code Quality · Free and MIT-licensed
Canonical: https://skills.wondel.ai/skills/refactoring-patterns/
Source: https://github.com/wondelai/skills/tree/main/refactoring-patterns

**Install:** `npx skills add wondelai/skills/refactoring-patterns --global`

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

## About 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: https://en.wikipedia.org/wiki/Martin_Fowler_(software_engineer) · https://www.wikidata.org/wiki/Q74894
The book: https://openlibrary.org/books/OL26629721M/Refactoring

## Example prompts

- 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)_

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

## Related

- All Code Quality skills: https://skills.wondel.ai/skills/code/
- Clean Code: https://skills.wondel.ai/skills/clean-code/
- Pragmatic Programmer: https://skills.wondel.ai/skills/pragmatic-programmer/
- Software Design: https://skills.wondel.ai/skills/software-design-philosophy/
- Legacy Code: https://skills.wondel.ai/skills/working-with-legacy-code/

