refactoring
Skill216 starsChanged 6 months agoMITView on GitHub
Safe, behavior-preserving code transformation backed by tests. Refactor with evidence, not instinct.
We split this skill into the rules it gives an agent
13 rules. 0 are common, 13 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 47 edited versions we read keep these.
13
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
- Distinctive: line 15
When code is hard to understand or extend
- Distinctive: line 16
When duplication makes maintenance risky
- Distinctive: line 17
Before adding a feature to a messy area of code
- Distinctive: line 18
Never: "while also adding feature X" — refactor separately
- Distinctive: line 24
Before touching a single line: ensure there are tests covering the code to be refactored.
- Distinctive: line 25
If tests are missing: add characterization tests first.
- Distinctive: line 26
Run the tests. They should all pass.
- Distinctive: line 33
Run tests after EVERY change — not after 10 changes.
- Distinctive: line 34
If tests break: revert immediately and take a smaller step.
- Distinctive: line 35
Never batch multiple refactoring changes together.
- Distinctive: line 51
Run the full test suite.
- Distinctive: line 52
If integration/E2E tests exist: run them too.
- Distinctive: line 55
Verify: All tests pass. No observable behavior change.
“Common” is measured: kept by at least 6 in 10 of the 47 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
Overview
Refactoring changes the internal structure of code without changing its external behavior. The keyword is "without" — if behavior changes, it's not refactoring, it's modification. This skill enforces safe refactoring with tests as the safety net.
When to Use
- When code is hard to understand or extend
- When duplication makes maintenance risky
- Before adding a feature to a messy area of code
- Never: "while also adding feature X" — refactor separately
Process
Step 1: Establish a Safety Net
- Before touching a single line: ensure there are tests covering the code to be refactored.
- If tests are missing: add characterization tests first. These capture current behavior, not desired behavior.
- Run the tests. They should all pass. This is your baseline.
Verify: Tests pass. They cover the code being refactored.
Step 2: Refactor in Micro-Steps
- Make the smallest meaningful change.
- Run tests after EVERY change — not after 10 changes.
- If tests break: revert immediately and take a smaller step.
- Never batch multiple refactoring changes together.
Verify: Tests pass after every individual change.
Step 3: One Thing at a Time
- Refactoring types cannot be mixed in one step:
- Extract method → separate commit
- Rename → separate commit
- Move → separate commit
- "Refactor and also fix this" is not refactoring — it's two PRs.
Verify: This commit does exactly one type of refactoring.
Step 4: Verify No Behavior Change
- Run the full test suite.
- If integration/E2E tests exist: run them too.
- Compare external API responses before and after (if applicable).
Verify: All tests pass. No observable behavior change.
Common Rationalizations (and Rebuttals)
| Excuse | Rebuttal |
| "I'll add tests after refactoring" | You can't verify a behavior-preserving refactor without tests before the refactor. |
| "This change is obviously safe" | Obvious safety is how production incidents happen. Run the tests. |
| "I'll just do a quick cleanup" | "Quick cleanup" that changes behavior is a bug, not a refactor. |
Verification
- Tests existed before any code was changed
- Tests run after every individual change
- Only one type of refactoring per commit
- Full test suite passes at the end
- No behavior change observable externally
References
- test-driven-development skill
- simplicity-first skill
- Martin Fowler, "Refactoring"
Other versions52 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 52
- handsontable/handsontable★ 22ksame name
- ciembor/agent-rules-books★ 2.8ksame name
- hitobito/hitobito★ 484same name
- databrickslabs/ontobricks★ 457same name
- extra-org/extra★ 118same name
- tmcfarlane/team-avatar★ 111same name
- nimadorostkar/Claude-Skills-collection★ 33same name
- dan-the-dev/xp-developer-skills★ 31same name
- s-hiraoku/synapse-a2a★ 17same name
- tae0y/python-project-template★ 14same name
42 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.
Used alongsideProjects with it also use ci-cd, planning 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.
JohnJBorenSkillci-cd
CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies
Also in 5 projects that use this
AWSSkillplanning
Discovers user intent and generates a structured, step-by-step plan for model customization workflows. This skill must always be activated alongside any other skill when the user's request relates to model customization — including fine-tuning, training, building, customizing, reviewing data, or getting advice on approach, regardless of domain. Do not skip this skill even if the immediate ask is narrow (e.g., reviewing data format or a single workflow step), because planning discovers the full scope of work needed. Also activate when the user wants to resume, continue, or modify an existing plan.
Also in 6 projects that use this
harrissohail6Skilldatabase-design
Database schema design and SQL best practices. Use when designing tables, writing queries, or optimizing database performance.
Also in 4 projects that use this
AnthropicSkillincident-response
Run an incident response workflow — triage, communicate, and write postmortem. Trigger with "we have an incident", "production is down", an alert that needs severity assessment, a status update mid-incident, or when writing a blameless postmortem after resolution.
Also in 5 projects that use this
klauswgSkillperformance
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 5 projects that use this
francogalfreSkilldependency-audit
Audits package.json dependencies for outdated packages, security vulnerabilities, unnecessary deps, and version issues. Use when the user says "audit my dependencies", "check my packages", "what deps should I update", "clean up package.json", "are there security issues in my deps", or pastes a package.json.
Also in 3 projects that use this
In this repository34 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agent-qa-run-reviewSkill
- ai-output-validationSkill
- api-designSkill
- ci-cd-pipelinesSkill
- citruscoastaiSkill
- code-explanationSkill
- code-reviewSkill
- context-loadingSkill
- debugging-methodologySkill
- documentationSkill
- error-handlingSkill
- frontend-engineeringSkill
- git-workflowSkill
- goal-driven-executionSkill
- hallucination-preventionSkill
- idea-to-specSkill
- incremental-codingSkill
- integration-testingSkill
- meeting-notes-to-tasksSkill
- multi-agent-orchestrationSkill
- observabilitySkill
- performance-optimizationSkill
- production-deploymentSkill
- prompt-injection-defenseSkill
- rag-and-memorySkill
- research-and-summarizeSkill
- security-hardeningSkill
- simplicity-firstSkill
- surgical-changesSkill
- task-decompositionSkill
- test-driven-developmentSkill
- think-before-codingSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

