agentleFS
kapadiaskapadias/nonna/.claude/skills/refactoring/SKILL.md

refactoring

Skill0 starsChanged 46 days agoMITView on GitHub

Restructuring existing code without changing behavior — extract, rename, replace conditionals, untangle a module. The REFACTOR phase.

61 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use ci-cd, dependency-management and 8 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • JohnJBorenSkill

    ci-cd

    CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies

    Also in 5 projects that use this

  • dkprogSkill

    dependency-management

    Apply when wiring dependencies, integrating external services, or designing interfaces between modules. Ensures loose coupling through dependency injection, interface segregation, and proper abstraction boundaries.

    Also in 3 projects that use this

  • javalenciacaiSkill

    multi-agent-orchestration

    Design and coordinate multi-agent systems where specialized agents work together to solve complex problems. Covers agent communication, task delegation, workflow orchestration, and result aggregation. Use when building coordinated agent teams, complex workflows, or systems requiring specialized expertise across domains.

    Also in 3 projects that use this

  • harrissohail6Skill

    database-design

    Database schema design and SQL best practices. Use when designing tables, writing queries, or optimizing database performance.

    Also in 5 projects that use this

  • MicrosoftSkill

    error-handling

    统一错误处理系统。在添加 API 端点、修改错误处理、添加前端 API 调用、编写错误相关测试时使用。

    Also in 7 projects that use this

  • klauswgSkill

    performance

    Optimize web performance for faster loading and better user experience. Use when asked to "speed up my site", "optimize performance", "reduce load time", "fix slow loading", "improve page speed", or "performance audit".

    Also in 7 projects that use this

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 55 edited versions we read keep these.

  • 1

    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:

    Speculative generality: Don't add layers, hooks, or abstraction for a future that may never arrive.

    line 54

“Common” is measured: kept by at least 6 in 10 of the 55 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

Refactoring is changing the shape of code while its behavior stays identical. If behavior changes, it is not a refactor — it is a feature or a fix, and it belongs in its own commit.

The prime directive

Tests stay green and unchanged throughout. The test suite is the proof that behavior held. From the first step to the last, every test that passed before passes after — and you did not edit the tests to make that true. If a refactor forces a test change, one of two things is happening: the test was coupled to internals (fix the test first, in a separate commit), or you are actually changing behavior (stop — that's a different task).

Never mix a refactor with a behavior change in the same commit. A reviewer must be able to trust that a "refactor" commit cannot have altered what the program does. Mixing the two destroys that guarantee and makes the change un-reviewable and un-revertible.

Tests-green as the safety net

You can only refactor safely under coverage. The suite is what lets you move fast — make a change, run tests, and know in seconds whether you broke something. No suite, no net, no speed.

Work in small, reversible steps. Extract one function, run tests, commit. Rename one symbol, run tests, commit. If a step goes red, you revert one small step, not an afternoon. Big-bang rewrites skip the net and accumulate undiagnosable breakage.

"For each desired change, make the change easy (warning: this may be hard), then make the easy change." — Kent Beck

Often the feature you want is awkward because the current structure resists it. Refactor first to make room — as its own green-tested commit — then add the behavior in the next commit. Two clean steps beat one tangled one.

Catalog of common refactors

The everyday moves are mechanical and local: extract function, rename for intent, replace a magic value with a named constant, introduce a parameter object, replace a conditional with a lookup or polymorphism, and guard-clause early returns. Each does one thing, keeps behavior identical, and produces a diff small enough to hold in your head — so do one at a time. The full table (when to reach for each, what it buys) with worked before/after examples lives in references/catalog.md.

When NOT to refactor

  • No test coverage yet. Refactoring blind is editing and hoping. Add characterization tests first — tests that pin current behavior as-is (even if it's quirky) — then refactor under them.
  • On a hot deadline / incident path. Ship the fix; refactor in a follow-up. Structure work and urgent work compete for the same attention and one will be done badly.
  • Speculative generality. Don't add layers, hooks, or abstraction for a future that may never arrive. Refactor toward the code you have, not the code you imagine. The simplest structure that fits today's behavior is the goal.

A refactor that leaves the suite green, the diff small, and the next change easier has done its job. See .claude/rules/engineering.md; the loop's REFACTOR phase is where this lives.

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.