refactoring
Skill4 starsChanged 4 months agoMITView on GitHub
Changes the structure of code without changing what it does — extracting, renaming, splitting, collapsing, and untangling. Use this whenever the user asks to clean up, tidy, simplify, restructure, extract, rename, or reduce duplication, and whenever code must be made workable before a feature can land. Also use when a change is turning into a rewrite. For adding behaviour, use feature-implementation; for judging someone else's change, use code-review.
39 other projects use a version of this.
Adopted by
Most recently taken up by
- kapadias/nonnatheir own version, first seen Oct 1, 2026
- jablonkai/skillstheir own version, first seen Oct 1, 2026
- fabiandistler/agentstheir own version, first seen Sep 30, 2026
- wormeyman/wormeyman-skillstheir own version, first seen Sep 25, 2026
- dan-the-dev/xp-developer-skillstheir own version, first seen Sep 23, 2026
- syanga/astacktheir own version, first seen Sep 20, 2026
Used with
Projects with it also use performance, ci-cd and 7 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.
pluginagentmarketplaceSkillperformance
Optimize application performance through caching strategies, load balancing, database scaling, and monitoring. Build systems handling thousands of concurrent users.
Also in 7 projects that use this
JohnJBorenSkillci-cd
CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies
Also in 4 projects that use this
CloudAI-XSkilldatabase-design
Designs database schemas, indexing strategies, query optimization, and migration patterns for SQL and NoSQL databases. Use when designing tables, optimizing queries, fixing N+1 problems, planning migrations, or when asked about database performance, normalization, ORMs, or data modeling.
Also in 5 projects that use this
AnthropicSkilldocumentation
Write and maintain technical documentation. Trigger with "write docs for", "document this", "create a README", "write a runbook", "onboarding guide", or when the user needs help with any form of technical writing — API docs, architecture docs, or operational runbooks.
Also in 8 projects that use this
OpenAISkillobservability
Vercel Observability expert guidance — Drains (logs, traces, speed insights, web analytics), Web Analytics, Speed Insights, runtime logs, custom events, OpenTelemetry integration, and monitoring dashboards. Use when instrumenting, debugging, or optimizing application performance and user experience on Vercel.
Also in 5 projects that use this
ElasticSkillaccessibility
Accessibility guidance for Kibana. Use this skill when working with or reviewing EUI components, resolving a11y-related (@elastic/eui) ESLint issues, and ensuring proper use of ARIA attributes, focus management, keyboard interactions, and accessible naming conventions.
Also in 5 projects that use this
Other versions39 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 39
- ciembor/agent-rules-books★ 2.9ksame name
- databrickslabs/ontobricks★ 393same name
- extra-org/extra★ 113same name
- 312362115/claude★ 107same name
- DevelopersGlobal/ai-agent-skills★ 69same name
- andreaswasita/copilot-agents-dojo★ 54same name
- dan-the-dev/xp-developer-skills★ 30same name
- nimadorostkar/Claude-Skills-collection★ 28same name
- krzysztofsurdy/code-virtuoso★ 22same name
- s-hiraoku/synapse-a2a★ 16same name
29 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository61 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agent-deploymentSkill
- agent-designSkill
- agent-evaluationSkill
- agent-hardeningSkill
- agent-implementationSkill
- agent-observabilitySkill
- agent-scopingSkill
- api-designSkill
- code-templatingSkill
- dependency-upgradeSkill
- error-handlingSkill
- feature-implementationSkill
- project-scaffoldingSkill
- data-analysisSkill
- data-migrationSkill
- data-modelingSkill
- sql-queriesSkill
- ci-pipelinesSkill
- containerizationSkill
- deployment-strategiesSkill
- infrastructure-as-codeSkill
- debuggingSkill
- issue-investigationSkill
- issue-triageSkill
- log-analysisSkill
- network-troubleshootingSkill
- performance-profilingSkill
- api-documentationSkill
- commit-messagesSkill
- diagrammingSkill
- markdown-docsSkill
- plain-languageSkill
- pr-descriptionsSkill
- release-notesSkill
- browser-testingSkill
- integration-testingSkill
- load-testingSkill
- test-dataSkill
- test-driven-developmentSkill
- unit-testingSkill
- deep-researchSkill
- feed-digestSkill
- summarizationSkill
- accessibility-reviewSkill
- code-analysisSkill
- code-lintingSkill
- code-reviewSkill
- auth-designSkill
- dependency-auditSkill
- secrets-managementSkill
- security-analysisSkill
- threat-modelingSkill
- capacity-planningSkill
- disaster-recoverySkill
- incident-responseSkill
- monitoring-setupSkill
- root-cause-analysisSkill
- runbooksSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 34 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 63
If a step cannot be made small, that is information: the code is more tangled than you thought.
- Distinctive: line 66
Done when: every commit in the series passes tests on its own.
- Distinctive: line 73
Use the tool's automated refactoring where available rather than editing by hand.
- Very specific: line 77
When you mix them, the reviewer must find three risky lines inside four hundred trivial ones, and they will not.
- Distinctive: line 80
Done when: no commit contains both kinds.
“Common” is measured: kept by at least 6 in 10 of the 34 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.
Files
Refactoring
Refactoring means the observable behaviour is identical afterwards. The moment behaviour changes you are doing something else, and mixing the two is what makes refactors dangerous — a diff that moves 400 lines and alters a condition is unreviewable, and nobody can tell which half broke production.
The one rule: never refactor and change behaviour in the same commit. Everything below exists to make that rule practical.
1. Get a safety net first
You need a way to know you did not break anything. In order of preference:
- Existing tests covering the area — run them now and confirm they pass, so you know the baseline is green before you touch anything.
- Characterization tests you write first, pinning current behaviour including behaviour that
looks wrong. See
unit-testing. - A type checker, for mechanical changes like renames.
- Nothing: then the refactor must be small enough to verify by reading, or you stop and write tests. "I'll be careful" is not a safety net.
Done when: you can run one command that tells you whether behaviour changed.
2. Name the smell, then pick the move
Refactor toward something specific. "Cleaning up" without a target produces churn and a diff nobody can evaluate.
| What's wrong | The move |
| One function does several things | Extract function |
| The same logic in three places | Extract and call, but see below |
| A name lies about what it does | Rename |
| A parameter list keeps growing | Introduce a parameter object |
| Conditionals nested four deep | Guard clauses, early return |
| A module knows too much about another | Move the behaviour to the data |
| A comment explains a block | Extract that block, name it after the comment |
On duplication: three occurrences before you extract. Two similar blocks are often coincidence, and a premature abstraction over two cases produces a function with a boolean parameter that both callers have to reason about. That is worse than the duplication.
Done when: you can state what is wrong and which move fixes it.
3. Work in reversible steps
Each step should leave the code working. Run the tests after each one, not at the end.
- Rename before you move. A rename plus a move in one commit shows up as delete-and-add, and the diff becomes unreadable.
- Add the new path, migrate callers, then delete the old. For anything with several callers, this keeps every intermediate state green.
- Commit each step separately. A refactor in twelve small commits is reviewable; the same work squashed is not.
If a step cannot be made small, that is information: the code is more tangled than you thought. Back up and find a smaller first move.
Done when: every commit in the series passes tests on its own.
4. Keep the mechanical separate from the judgement
Two categories, and they must not share a commit:
- Mechanical: renames, moves, formatting, import reordering. Large diffs, near-zero risk. Use the tool's automated refactoring where available rather than editing by hand.
- Structural: extracting, inverting dependencies, changing an interface. Small diffs, real risk. These need reading.
When you mix them, the reviewer must find three risky lines inside four hundred trivial ones,
and they will not. Record mechanical commits in .git-blame-ignore-revs so history stays useful.
Done when: no commit contains both kinds.
5. Know when to stop
Refactoring has no natural end, which is its main hazard. Stop when:
- The thing you came to do is now possible. That was the point.
- You are changing code you have no reason to touch. Note it and leave it.
- You cannot articulate what is better. "More abstract" is not better.
- The tests are getting harder to write. That usually means you are refactoring toward the wrong shape — abstraction that makes testing harder is abstraction in the wrong place.
Done when: the original task is unblocked and the diff is defensible line by line.
What not to do
- Do not refactor code you are not about to change. It is risk without payoff, and it invalidates everyone's in-flight branches.
- Do not "improve" while implementing a feature. Separate commits, ideally separate PRs.
- Do not rename public API as a tidy-up. That is a breaking change wearing a refactor's clothes.
- Do not chase a pattern. Introducing a factory because the code "should" have one adds indirection without removing a problem.
Report
Say what you changed structurally, what proves behaviour is unchanged (which tests, run when), and what you deliberately left alone. If you found a real bug while refactoring — it happens often — report it separately and do not fix it in the same commit.
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
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.

