
Code Refactoring (Fowler method)
Guides safe, step-by-step refactoring of code using Martin Fowler's methodology and test checks
- Repository
- luongnv89/claude-howto
- Stars
- 46,401
- Licence
- MIT
- Files
- 1 file
What it does
When you ask the agent to clean up or restructure code, it follows a fixed six-stage process instead of editing freely. It first asks clarifying questions about scope, goals and constraints, checks whether tests exist and pass, identifies common code smells (like long methods or duplicated code), proposes a plan mapping each smell to a standard refactoring, and then makes small changes one at a time. It asks for your approval at several checkpoints along the way.
Great for
- Developers who want to reduce technical debt in an existing codebase without changing its behaviour
- Teams working on legacy code that lacks good test coverage and need a cautious, test-first approach
- People who want the agent to explain its reasoning and pause for sign-off rather than rewrite large sections silently
Skip it if
- Quick one-line fixes or new feature work, since the multi-stage process adds overhead (the workflow is designed for structural improvement)
- Projects where tests are absent and you cannot write them, because the skill's own guidance recommends refusing to proceed without a safety net unless you accept the risk
- Non-programmers, as the skill assumes familiarity with code, tests and tools like npm, pytest and Maven
Try asking
- “Refactor the payment module in this repo to remove duplicated code, checking tests first”
- “Find the code smells in src/orders.py and propose a prioritised refactoring plan for my approval”
- “Help me reduce technical debt in this legacy Java service without changing its behaviour”
- “Extract long methods in utils.js into smaller functions, one step at a time”
Install in 3 steps
- 1
Download the skill
The ZIP contains the 1 original files, the MIT licence and an attribution note.
refactor.zip - 2
Add it to your agent
Claude Code (all projects)
mkdir -p ~/.claude/skills && unzip refactor.zip -d ~/.claude/skills/Claude Code / Agent SDK (this project only)
mkdir -p .claude/skills && unzip refactor.zip -d .claude/skills/Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.
- 3
Ask for the task
No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.
Get better results
- Give the agent a clear scope (specific files or functions) so the stage-one questions are quick to answer.
- Make sure your tests pass before starting, or explicitly accept the risk of refactoring without them.
- Review the plan and smell report at each approval checkpoint rather than letting the agent run through all stages unattended.
What's inside
- SKILL.md
Redistributed unmodified from luongnv89/claude-howto under the MIT licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.