agentleFS
WST2002WST2002/claude-code-skills/skills/refactor-planner/SKILL.md

refactor-planner

Skill4 starsChanged 27 days agoMITView on GitHub

Use when asked to refactor, clean up, restructure or modernize code, split a large file or god class, remove duplication, migrate to a new pattern or library, or reduce technical debt without changing behavior.

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Build the safety net: Run existing tests. If the behavior being moved is not covered, add characterization tests that capture what it does …

    line 16
  2. Distinctive:

    Finish: remove dead code, update docs, report.

    line 21
  3. Distinctive:

    Before changing code, deliver the plan:

    line 25
  4. Distinctive:

    After executing: the list of commits and the test result after the last one.

    line 36

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Refactor Planner

Overview

Refactoring changes structure, never behavior. Lock behavior with tests first, move in small steps that each leave the code working, and keep every step reviewable and revertible.

Method

  1. State the goal in one sentence and why it pays off: "Split orders.ts (1,400 lines) so checkout and refunds can change independently."
  2. Map the code: who calls the target (find usages), what it depends on, public contracts that must not change.
  3. Build the safety net. Run existing tests. If the behavior being moved is not covered, add characterization tests that capture what it does today, including odd behavior.
  4. Plan small steps. Each step is one known refactoring, keeps tests green, and is one commit:
    • Rename, extract function, extract module, move function, inline, introduce parameter object, replace conditional with polymorphism, extract interface at a boundary.
    • For migrations: add the new path beside the old one, move callers in batches, delete the old path last.
  5. Execute step by step: change, run tests, commit. Never mix a refactor and a behavior change in one commit.
  6. Finish: remove dead code, update docs, report.

Output

Before changing code, deliver the plan:

Goal: <one sentence>
Safety net: <existing tests, tests to add>
Steps:
1. <refactoring> — <files> — risk: low/medium/high
2. ...
Out of scope: <tempting changes deliberately left out>

After executing: the list of commits and the test result after the last one.

Smells and the refactoring that fixes them

SmellRefactoring
Long function doing several thingsExtract function per responsibility
File or class with many unrelated reasons to changeSplit by responsibility, move functions
Same logic in several placesExtract shared function; keep it where all callers can reach it
Long parameter listsIntroduce parameter object
switch on type repeated in many placesPolymorphism or a lookup table
Deep nestingGuard clauses, early returns
Feature envy (code that mostly uses another module's data)Move function to that module

Common mistakes

  • Big-bang rewrite in one commit that nobody can review or revert.
  • Refactoring without tests, then discovering behavior changed in production.
  • "While I am here" behavior changes mixed into the refactor.
  • Abstracting for imagined future needs; extract only what has two real callers.
  • Renaming public APIs without a deprecation path for external users.

Made by Wageesha Tripathi · LinkedIn · Email · More skills

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.