agentleFS
divik-09divik-09/claude-skills-collection/skills/refactoring-guide/SKILL.md

refactoring-guide

Skill1 starsChanged 9 days agoMITView on GitHub

Plan and perform safe refactors that improve structure without changing behavior. Use whenever the user asks to clean up, simplify, restructure, de-duplicate, modernize, or 'make this more readable or maintainable' code, or complains that a function or class is too long or messy.

4 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

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

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 3

    Distinctive

    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:

    Do not rename, reformat, and restructure in one commit.

    line 32
  2. Distinctive:

    Do not add abstractions for hypothetical futures.

    line 34
  3. Distinctive:

    Keep the language idioms of the codebase.

    line 35

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “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

Refactoring Guide

Refactoring changes structure, not behavior. If behavior must change, separate that into its own step.

Before touching anything

  1. Confirm a safety net. Are there tests? If not, write characterization tests that pin current behavior first, or state the risk plainly.
  2. Name the smell and the goal. Examples: long function, deep nesting, duplicated logic, primitive obsession, god class, feature envy, boolean flag arguments, shotgun surgery.
  3. Choose the smallest step that helps.

Common moves

SmellMove
Long functionExtract function with a name that says what, not how
Deep nestingGuard clauses / early return
Duplicated codeExtract and parameterize, only after seeing 3 real copies
Flag argumentsSplit into two functions or use an enum/strategy
Magic numbersNamed constants
Large conditional on typePolymorphism or lookup table
Data clumpsIntroduce a small value object
Dead codeDelete it (version control remembers)

Rules

  • Make one refactor per step and keep each step independently reviewable.
  • Do not rename, reformat, and restructure in one commit.
  • Preserve public interfaces unless the user approves a breaking change.
  • Do not add abstractions for hypothetical futures. Three similar lines beat a premature framework.
  • Keep the language idioms of the codebase.

Output

Show the refactored code, then a short list of steps taken, what behavior is intentionally unchanged, and how to verify (tests to run, manual checks). Flag anything that looked like a latent bug instead of silently fixing it.

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.