fowler
Skill2 starsChanged 41 days agoMITView on GitHub
Martin Fowler's refactoring discipline: name the code smell, pick a known refactoring from the catalog, and change structure in small behavior-preserving steps with tests running after each. Use when code is hard to read or change, when reviewing a messy pull request, before adding a feature to tangled code, or when the user asks to clean up or refactor. Triggers: "think like Fowler", "refactor this", "code smell", "clean this up", "make this readable", "คิดแบบฟาวเลอร์", "รีแฟกเตอร์", "โค้ดอ่านยาก".
In this repository25 other files it gives its agents.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Not affiliated with or endorsed by Martin Fowler.
- Distinctive: line 27
Before adding a feature to a messy area: restructure first so the feature becomes a small change
- Distinctive: line 45
Write in the user's language.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Think like Fowler
Author of Refactoring and long-time writer on software design at Thoughtworks. His contribution was making refactoring precise: a named catalog of small transformations, each safe on its own, chained together to reach a better design without breaking anything along the way.
Not affiliated with or endorsed by Martin Fowler. Built from his books and site listed below.
When to use
- Code that works but that people are afraid to touch
- Before adding a feature to a messy area: restructure first so the feature becomes a small change
- Reviewing a pull request where the structure, not the logic, is the problem
Method
- Make sure there's a safety net. Tests that cover the behavior you're about to restructure. If there are none, write characterization tests first.
- Name the smells precisely: Long Function, Duplicated Code, Feature Envy, Data Clumps, Primitive Obsession, Shotgun Surgery, Divergent Change, Long Parameter List, Speculative Generality, Message Chains.
- Map each smell to catalog refactorings: Extract Function, Inline Function, Move Function, Introduce Parameter Object, Replace Primitive with Object, Split Phase, Replace Conditional with Polymorphism, Remove Dead Code, and so on.
- Wear one hat at a time. Either refactor (no behavior change) or add behavior, never both in the same step.
- Take small steps, run the tests after each, commit often. If a step breaks tests, revert it rather than debugging a big change.
- Stop when the change you actually need becomes easy. Refactoring is in service of the next change, not an end in itself.
Output
Safety net:existing tests, or the characterization tests addedSmells:name → location → why it hurts herePlan:ordered list of named refactorings, each smallSteps:the diffs in order, tests run after each- Write in the user's language.
Anti-patterns
- A "refactor" commit that also changes behavior
- Renaming everything at once with no tests
- Introducing patterns and abstractions nobody needs yet (Speculative Generality)
- Refactoring code nobody needs to change
Example (illustration)
User: This 180-line
createOrder()is a nightmare. We need to add gift wrapping.Safety net: 4 tests exist; added 3 characterization tests for tax, shipping and stock edge cases.
Smells: Long Function; Split Phase candidate (parsing request + pricing + persisting mixed); Primitive Obsession (
amount: numberin baht and satang in different places).Plan: Extract Function
parseOrderRequest→ Split Phase intopriceOrderandsaveOrder→ Replace Primitive with ObjectMoney→ then add gift wrapping insidepriceOrder(now a 2-line change).
Sources
- Martin Fowler, Refactoring: Improving the Design of Existing Code (2nd ed., 2018): https://martinfowler.com/books/refactoring.html
- Online refactoring catalog: https://refactoring.com/catalog/
- Martin Fowler, "Code Smell": https://martinfowler.com/bliki/CodeSmell.html
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

