Refactoring
Improve code structure in small, always-green steps without changing behavior. Use when asked to clean up, simplify, restructure, or de-duplicate working code.From its SKILL.md
npx -y skills add Amey-Thakur/AI-SKILLS --skill refactoringAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 4 stars4 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.4 KB, 506 tokens by cl100k_base, as published. Nobody here has run it
Refactoring
A refactor changes structure while behavior stays identical. The moment behavior changes on purpose, it is a feature; by accident, a bug. Keep the line sharp.
Method
- Secure the net first. Confirm the tests around the target pass and actually pin its behavior. If coverage is thin, write characterization tests before touching anything: capture what the code does now, even its oddities. An odd behavior may be load-bearing.
- Name the smell and the target shape. "Three near-copies of this query builder → one function with two parameters." If you cannot state the after-state in a sentence, you are wandering, not refactoring.
- Move in reversible steps, green after each. Rename; extract function; inline; move; then delete the old path. Each step compiles, passes, and could ship. Twenty two-minute steps beat one two-hour rewrite in every dimension that matters: reviewability, bisectability, abort-ability.
- Separate refactor commits from behavior commits. A reviewer must be able to skim a refactor commit ("no behavior change") and scrutinize the small behavior commit. Mixed commits get neither reading.
- Follow the house style, even where you prefer another. A codebase with one accent is maintainable; your improvement in a foreign accent is someone else's cleanup ticket.
- Stop at the target. The neighboring mess you noticed goes on a list, not into this change. Scope creep is how refactors become rewrites and rewrites become incidents.
Judgment calls
- Duplication: two copies are cheaper than the wrong abstraction; three copies with the same change-reason justify extraction. Extract for shared meaning, not shared characters.
- Small functions: extraction pays when the name says something the code cannot; a five-line function called once with a vague name is indirection, not clarity.
- Dead code: delete it, do not comment it out. Version control is the attic.
Litmus tests
- Could every commit in the series ship alone?
- Did any test's assertions change? (Renames aside: that is the tell that behavior moved.)
- Is the diff smaller than the improvement it buys?
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 1 of the 12 instructions most refactoring skills give in 506 tokens
Counted across 545 of the 587 authors here whose files we hold, read 2026-09-06
- Run tests after each changein 61 of 545, across 59 files
- Run tests before refactoringin 42 of 545
- Revert immediately if tests failin 31 of 545, across 28 files
- Perform refactoring in small stepsin 30 of 545, across 29 files
- Write characterization tests for untested codein 21 of 545, across 19 files
- Remove dead code and unused importsin 20 of 545
- Identify code smellsin 20 of 545
- Perform one refactoring at a timein 19 of 545
- Commit after each successful refactoringin 17 of 545, across 15 files
- Verify all tests pass after refactoringin 17 of 545
- Keep refactoring separate from behavior changeshere, and in 16 of 545, across 14 files
- Run the full test suitein 16 of 545
Said here and by no other author read
- Define the target shape before refactoring
- Follow existing house style
- Limit changes to the defined target
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.