refactoring
Skill1 starsChanged 6 months agoMITView on GitHub
Refactor code safely with characterization tests first, small reversible steps, and verification after each step. Use when the user asks to refactor, restructure, clean up, simplify, extract, or rename existing code.
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 5 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
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
NVIDIASkilltesting
Run Python and Rust tests for physicsnemo-curator using uv + pytest with coverage reporting via pytest-cov, and cargo-nextest for Rust tests. Includes benchmark workflows with pytest-benchmark and criterion.
Also in 10 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 repository50 other files it gives its agents.
- accessibility-reviewSkill
- adr-authorSkill
- api-designSkill
- architecture-reviewSkill
- caching-strategySkill
- changelogSkill
- ci-cd-pipelineSkill
- codebase-explorationSkill
- code-reviewSkill
- code-style-guideSkill
- context-engineeringSkill
- conventional-commitsSkill
- cost-optimizationSkill
- database-migrationSkill
- data-privacy-reviewSkill
- debuggingSkill
- dependency-updateSkill
- deprecation-migrationSkill
- error-handlingSkill
- feature-flag-rolloutSkill
- filament-resource-designSkill
- flux-ui-patternsSkill
- git-workflowSkill
- i18n-reviewSkill
- idea-refineSkill
- incident-responseSkill
- incremental-implementationSkill
- inertia-patternsSkill
- laravel-ai-featuresSkill
- laravel-eloquent-performanceSkill
- laravel-queue-designSkill
- laravel-testingSkill
- livewire-component-designSkill
- llm-feature-designSkill
- observabilitySkill
- onboarding-docSkill
- performance-budgetSkill
- pr-descriptionSkill
- primevue-patternsSkill
- release-checklistSkill
- resilience-patternsSkill
- runbook-authorSkill
- security-auditSkill
- spec-writingSkill
- task-breakdownSkill
- tech-debt-triageSkill
- test-writingSkill
- threat-modelingSkill
- using-elyra-skillsSkill
- vue-component-patternsSkill
The file
We split this skill into the rules it gives an agent
8 rules. 0 are common, 7 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 34 edited versions we read keep these.
7
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 51
If you can't get to step 1 or 2, stop and tell the user.
- Distinctive: line 61
Commit (or at least stash) after each green step.
- Distinctive: line 80
All tests pass (including ones you wrote in step 1)
- Distinctive: line 82
No dead code left over
- Distinctive: line 83
Run a diff stat: large diff is fine, surprises are not
- Very specific: line 114
If the test suite is slow, scope down: pytest path/to/affected, vitest run src/affected/, etc.
- Distinctive: line 115
Use the IDE/LSP refactor tools for renames and moves when available — they're more reliable than text search-replace.
- Distinctive: line 116
If a refactor "needs" you to change a test, pause: are you changing behavior?
“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: changing the structure of code without changing its observable behavior.
The discipline is in the without. If tests fail or behavior changes, it's no longer a refactor — it's a rewrite, and it needs to be reviewed as one.
When to use
- "Refactor X"
- "Clean up / simplify / restructure …"
- "Extract this into a function/module/class"
- "Rename / move / split …"
- "Reduce duplication"
When NOT to use
- The user wants new behavior → that's a feature, not a refactor
- There are no tests and no time/permission to add them → flag the risk first
- The code is going to be deleted soon → don't polish it
Procedure
0. Confirm scope and goal
Refactoring is open-ended. Pin it down:
- What's the smell? (duplication, long function, unclear naming, tight coupling, …)
- What does "done" look like?
- What must not change? (public API, file paths, performance, …)
1. Establish a safety net
Behavior preservation needs proof. In order of preference:
- Existing tests that cover the affected code. Run them; they must pass before you start.
- Characterization tests — write tests that pin down current behavior (including warts), so you'll notice if you change it.
- Manual repro of key paths if tests are impossible. Document what you checked.
If you can't get to step 1 or 2, stop and tell the user. Don't refactor on faith.
2. Refactor in small steps
Each step:
- Is one transformation (extract, rename, inline, move, …)
- Compiles / lints / type-checks
- Passes the test suite
Commit (or at least stash) after each green step. If a step turns red, revert it — don't pile fixes on top.
3. Common refactoring moves
| Move | Use when |
| Extract function | A block of code has a clear single purpose and a good name suggests itself |
| Inline | A function adds no clarity over its body |
| Rename | The current name lies, lags, or shrugs |
| Move | A function sits closer to data it doesn't use than data it does |
| Replace conditional with polymorphism | A switch/if chain on type repeats in multiple places |
| Introduce parameter object | A function takes 4+ related args, or the same cluster appears together repeatedly |
| Replace magic value with named constant | A literal appears more than once or its meaning isn't obvious |
| Split phase | One function does parsing and processing, or fetch and transform |
4. Verify
After all steps:
- All tests pass (including ones you wrote in step 1)
- Public API unchanged (or changes are deliberate and documented)
- No dead code left over
- Run a diff stat: large diff is fine, surprises are not
5. Stop
Refactoring is open-ended; that's why it's dangerous. Stop at the goal you set in step 0. If you spot more smells, note them, don't fix them now.
Output format
## Refactor: <short title>
**Goal:** what we set out to do.
**Approach:** sequence of small steps actually taken.
**Behavior preservation:** tests run / written / checked.
**Out of scope (noted, not fixed):** other smells you spotted.Anti-patterns
- ❌ "Refactor + add a feature in the same change" — split into two PRs
- ❌ Big-bang rewrite labeled as "refactor"
- ❌ Refactoring without running the tests after each step
- ❌ Renaming things at the same time as moving them at the same time as changing signatures
- ❌ Polishing code that's about to be deleted
- ❌ Reformatting unrelated code — keep diffs reviewable
Tips
- If the test suite is slow, scope down:
pytest path/to/affected,vitest run src/affected/, etc. But run the full suite at the end. - Use the IDE/LSP refactor tools for renames and moves when available — they're more reliable than text search-replace.
- If a refactor "needs" you to change a test, pause: are you changing behavior? If yes, label it as such.
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.

