refactoring
Skill50 starsChanged 7 days agoMITView on GitHub
Executes the 'Then Make it Right' discipline: pins behavior, eliminates duplication, enforces CRAP < 10, runs mutation gates, and improves architecture without altering observable behavior.
58 other projects use a version of this.
Adopted by
Most recently taken up by
- ishandutta2007/Awesome-Claude-Skillstheir own version, first seen Nov 8, 2026
- REPOZY/superpowers-optimizedtheir own version, first seen Nov 8, 2026
- nisarth/claude-skills-storetheir own version, first seen Nov 8, 2026
- ericwang200608-beep/LANYANT-Skillstheir own version, first seen Nov 8, 2026
- AnyOrgName/php-skillstheir own version, first seen Nov 8, 2026
- SWEStash/swe-workflow-skillstheir own version, first seen Nov 8, 2026
Used with
Projects with it also use ci-cd, dependency-management and 10 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
dkprogSkilldependency-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
javalenciacaiSkillmulti-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
harrissohail6Skilldatabase-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
MicrosoftSkillerror-handling
统一错误处理系统。在添加 API 端点、修改错误处理、添加前端 API 调用、编写错误相关测试时使用。
Also in 7 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 7 projects that use this
Other versions58 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 58
- handsontable/handsontable★ 22ksame name
- ciembor/agent-rules-books★ 2.8ksame name
- hitobito/hitobito★ 485same name
- databrickslabs/ontobricks★ 457same name
- DevelopersGlobal/ai-agent-skills★ 216same name
- REPOZY/superpowers-optimized★ 146same name
- extra-org/extra★ 119same name
- tmcfarlane/team-avatar★ 112same name
- nimadorostkar/Claude-Skills-collection★ 33same name
- dan-the-dev/xp-developer-skills★ 31same name
48 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 repository11 other files it gives its agents.
- agent-loopSkill
- codebase-context-generatorSkill
- code-reviewSkill
- email-triageSkill
- manual-automationSkill
- planning-and-task-breakdownSkill
- project-change-intelligenceSkill
- pull-requestSkill
- slack-cliSkill
- test-driven-developmentSkill
- yt-random-comment-pickerSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. 0 are common, 16 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 53 edited versions we read keep these.
16
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 14
Pin what the code does: Ensure existing tests (or characterization tests) cover the current behavior.
- Distinctive: line 16
Prove the behavior did not change: All tests must stay green.
- Distinctive: line 27
If Cyclomatic Complexity ($\text{CC}$) is $\ge 10$, the function will fail even with 100% test coverage—it *must* be decomposed.
- Distinctive: line 36
Killed mutant: Test suite fails (Good—test verified behavior).
- Distinctive: line 37
Surviving mutant: Test suite passes (Bad—weak assertion or dead code).
- Distinctive: line 61
Put the domain in a structure that makes illegal states impossible to represent.
- Distinctive: line 63
If existing code is already clear and local, leave it alone.
- Distinctive: line 66
Check data where it enters the system boundaries.
- Distinctive: line 68
Keep business logic in pure, deterministic functions without side-effects.
- Distinctive: line 73
Do not silence compiler, type-checker, or linter warnings with suppressions.
- Distinctive: line 76
Ensure running an operation twice, or running it after a crash halfway through, results in the exact same state.
- Distinctive: line 79
If two components do not need the same mutable state, give each its own.
- Distinctive: line 80
If they do need shared state, allow only one writer, and enforce that single writer strictly in the structure.
- Distinctive: line 87
Run the project's test suite.
- Distinctive: line 95
Verify that the refactored code and tests leave zero surviving mutants.
- Distinctive: line 97
Run the full test suite and confirm 100% pass rate.
“Common” is measured: kept by at least 6 in 10 of the 53 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 ("Then Make it Right")
Refactoring is the disciplined process of changing internal code structure without changing its external observable behavior. It follows the Red $\to$ Green minimal implementation ("Make it Work") to ensure code health, architectural integrity, and long-term maintainability across any programming language.
The Core Rule
- Pin what the code does. Ensure existing tests (or characterization tests) cover the current behavior.
- Change the structure. Refactor code toward cleaner abstractions, lower complexity, and single responsibility.
- Prove the behavior did not change. All tests must stay green. A failing test during refactoring is a regression, not progress.
The Three Automated Quality Gates
To prevent subjective or superficial refactoring, enforce the three automated quality gates using the native tools of the target project's ecosystem:
1. risk-gate (Complexity & CRAP Score)
- Rule: Reduce each function under CRAP 10 by splitting it, by testing it, or both. Consider whether case statements are worth reducing.
- The Formula: $\text{CRAP} = \text{CC}^2 \times (1 - \text{coverage})^3 + \text{CC}$.
- If Cyclomatic Complexity ($\text{CC}$) is $\ge 10$, the function will fail even with 100% test coverage—it must be decomposed.
2. clone-check (Structural Duplication)
- Rule: Eliminate structural duplication that ranks 0.8 or above (or $\ge 80%$).
- Extract repeated logic, algorithmic patterns, or mirrored workflows into clean, reusable functions or shared classes.
3. mutant-gate (Mutation Testing)
- Rule: Cover the uncovered. Kill the survivors. Delete dead code.
- Injects programmatic mutations (inverting comparison operators, arithmetic, or booleans) to verify that tests actually assert behavior.
- Killed mutant: Test suite fails (Good—test verified behavior).
- Surviving mutant: Test suite passes (Bad—weak assertion or dead code).
Native Tooling Matrix by Language
Execute the corresponding native CLI tool for the project being refactored:
| Ecosystem | risk-gate ($\text{CRAP} / \text{CC} < 10$) | clone-check (Duplication $< 0.8$) | mutant-gate (Mutation Kill) |
| Universal (150+ langs) | Check linter complexity rules | npx jscpd --threshold 80 <path> | — |
| TypeScript / JavaScript | npx eslint --rule 'complexity: ["error", 10]' | npx jscpd --threshold 80 src/ | npx stryker run |
| Go | gocyclo -over 10 . or golangci-lint run | npx jscpd --threshold 80 . | go-mutesting ./... |
| Rust | cargo clippy -- -D clippy::cognitive_complexity | npx jscpd --threshold 80 src/ | cargo mutants |
| Python | radon cc -s -n B . or flake8 --max-complexity 10 | npx jscpd --threshold 80 . | mutmut run |
| Java / JVM | Checkstyle CyclomaticComplexity or Sonar | npx jscpd --threshold 80 src/ | mvn org.pitest:pitest-maven:mutationCoverage |
Architectural Disciplines
Refactoring must drive the code toward the following architectural standards:
Model the Domain
- Put the domain in a structure that makes illegal states impossible to represent.
- Maintain a glossary of domain terms in documentation or domain models.
- If existing code is already clear and local, leave it alone.
Boundary Discipline
- Check data where it enters the system boundaries.
- Inside system boundaries, trust it.
- Keep business logic in pure, deterministic functions without side-effects.
Type System Discipline
- Make the illegal value impossible to write.
- Parse outside data once, where it comes in (parse, don't validate).
- Do not silence compiler, type-checker, or linter warnings with suppressions.
Make Operations Idempotent
- Ensure running an operation twice, or running it after a crash halfway through, results in the exact same state.
Separate Before Serializing Shared State
- If two components do not need the same mutable state, give each its own.
- If they do need shared state, allow only one writer, and enforce that single writer strictly in the structure.
Step-by-Step Refactoring Workflow
- Verify Baseline Tests: Run the project's test suite. Ensure all tests pass. If tests do not exist for the code being refactored, write characterization tests to lock in current behavior before touching code.
- Run Quality Gates:
Execute the ecosystem's
risk-gateandclone-checkcommands to identify high-risk functions ($\text{CRAP} \ge 10$) and structural duplicates ($\ge 0.8$). - Execute Surgical Refactorings:
- Split complex methods into cohesive pure helper functions.
- Eliminate duplication by extracting shared logic.
- Apply domain and type system discipline.
- Run
mutant-gate: Verify that the refactored code and tests leave zero surviving mutants. - Prove Invariance: Run the full test suite and confirm 100% pass rate.
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.

