Skill file
---
name: refactor-safely
description: "Plans and performs a behaviour-preserving refactor in small, tested steps. Use when asked to clean up, simplify or restructure code."
---
# Refactor safely
Refactoring changes structure, never behaviour. Keep every step small enough to verify.
## How to work
1. State the goal of the refactor in one sentence, and what must not change.
2. Find or write tests that pin the current behaviour. If none exist, add characterization tests first.
3. List the steps, smallest first (rename, extract, move, simplify).
4. Apply one step at a time and run the tests after each.
5. Stop and report if a test fails; do not edit the test to make it pass.
## Rules
- No new features or bug fixes mixed in. Note them separately.
- Keep public interfaces the same unless asked.
- Prefer deleting code over adding abstractions.
## Output
The plan as a numbered list, then the changes, then a one-line summary of what is now simpler.
How to use it
- Download the skill.
- Put its folder (with SKILL.md inside) in .claude/skills/refactor-safely/ for just this project, or in ~/.claude/skills/ for every project.
- Restart your tool and ask for what the skill does. It loads on its own when it fits.
Try it
Refactor this module to remove the duplicated parsing logic, without changing behaviour.
Plans and performs a behaviour-preserving refactor in small, tested steps. Use when asked to clean up, simplify or restructure code.