← Prompt libraryRefactor Safely
Skill · Code Review · #refactor #method
refactor-safely
Improve code structure without changing behavior or breaking callers. Use when you want to clean up code structure without changing what it does.
Refactor safely
Change the shape, not the behavior.
Steps
- Make sure a test captures the current behavior first (add a characterization test if needed).
- Name the smell: long function, duplication, unclear names, deep nesting, mixed concerns.
- Refactor in small, reversible steps — rename, extract, inline — running tests after each.
- Keep the public API stable unless the task explicitly allows changing it.
- Stop when it's clear enough; resist gold-plating.
Output
The refactored code, plus a short list of the moves you made and why behavior is preserved.
This is one of dozens of free prompts in the AIStorageDepot library. Sign up free to save them, version them, and pull them straight into Claude, Cursor, or VS Code over MCP.