Refactoring
Use when restructuring, simplifying, extracting, renaming, deduplicating, or cleaning up code — any change meant to preserve behavior. Also covers when NOT to abstract.From its SKILL.md
npx -y skills add odjacobs/claude-skills --skill refactoringAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.6 KB, as published. Nobody here has run it
Refactoring
A behavior-preserving change, proven by green tests before AND after every step.
Preconditions
- Tests exist and pass NOW. Quote the run. No coverage on the target area → STOP: write characterization tests first, or report that the refactor is unsafe.
- Working tree clean (commit or stash first) — every step must be revertable.
The loop
- ONE transformation (extract function, rename, inline, move — a single named move).
- Run tests. Green → commit, message names the transformation.
- Red → revert immediately (
git checkout -- .). Safe here despite the ask-first rule: the tree was clean at loop start, so this discards only the failed uncommitted transformation. Never debug forward on top of a broken refactor. Re-attempt smaller. - Next transformation.
Never mix refactoring with behavior change in one commit. Feature first or refactor first — pick one, finish it, then do the other.
When to abstract — rule of three
- 2 similar blocks: leave them. The similarity may be coincidence.
- 3rd appearance: NOW extract. Name it after what it means, not how it works.
Do NOT abstract
- Interface with one implementation
- Config or parameter for a value that never varies
- Base class for future variants that don't exist
- Helper wrapping a single stdlib call
- Generic solution when every caller uses it the same one way
Deletion beats abstraction: dead code, unused params, commented-out blocks → delete, don't organize.
STOP conditions
- No test coverage on the target area → stop, report.
- Refactor would touch 5+ files → propose the plan first, get approval.
- Tests red after 2 attempts at the same transformation → revert, report the design obstacle.
Output template — report per refactor
REFACTOR: <goal in one sentence>
BASELINE: <test command> → <green output before starting, quoted>
STEPS:
1. <transformation> → tests green → <commit>
2. <transformation> → tests green → <commit>
BEHAVIOR CHANGES: none (or the refactor failed — revert and report)
Failure modes
| Anti-pattern | Reality |
|---|---|
| "While I'm here" scope creep | One named transformation per commit. |
| Refactoring without tests | That's editing and hoping. Characterize first. |
| Clever one-liner replaces clear 5 lines | Clever is what someone decodes at 3am. Boring wins. |
| DRYing coincidental similarity | The wrong abstraction costs more than duplication. |