refactor-guide
Skill0 starsChanged 23 days agoMITView on GitHub
Refactor safely — keep tests green, change structure without behavior change, no public API breakage. Use for code maintenance.
3 other projects use a version of this.
Adopted by
Most recently taken up by
- mohitmishra786/anti-vibe-skillstheir own version, first seen Nov 1, 2026
- kudeerliu48-web/CloseCodetheir own version, first seen Nov 1, 2026
- JohnJBoren/claude-skills-ecosystemtheir own version, first seen Dec 26, 2025
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- kudeerliu48-web/CloseCode★ 14same name
- mohitmishra786/anti-vibe-skills★ 8same name
- JohnJBoren/claude-skills-ecosystem★ 2same name
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 repository32 other files it gives its agents.
- .claude/CLAUDE.mdCLAUDE.md
- api-designSkill
- arch-constraint-guardSkill
- backend-patternsSkill
- clean-architectureSkill
- codebase-mappingSkill
- context-budgetSkill
- cqrsSkill
- ddd-architectureSkill
- debug-flowSkill
- dependency-auditSkill
- django-patternsSkill
- django-tddSkill
- event-driven-architectureSkill
- fd-codenavSkill
- fd-mapSkill
- frontend-patternSkill
- git-releaseSkill
- git-workflowSkill
- golang-patternsSkill
- hexagonal-architectureSkill
- java-patternsSkill
- layered-architectureSkill
- performance-profilingSkill
- postgres-patternsSkill
- python-patternsSkill
- research-firstSkill
- rust-patternsSkill
- saga-architectureSkill
- security-scanSkill
- tdd-workflowSkill
- test-gap-detectorSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
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 24
No features in refactor commits
- Distinctive: line 25
If any test breaks, undo and try a smaller step
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Refactor Guide Skill
Changes structure without changing behavior. One transformation at a time. Tests must stay green throughout.
When to Activate
Activate when:
- A function is over 50 lines
- A file is over 800 lines
- There is significant code duplication
- Variable or function names are misleading
- You are preparing code for a new feature
Core Principles
- Tests green before you start — if not, fix tests first
- One transformation per commit
- No features in refactor commits
- If any test breaks, undo and try a smaller step
Safe Refactoring Process
1. npm test → must be GREEN before starting
2. Apply ONE transformation
(extract function, rename, move module — one thing only)
3. npm test → must still be GREEN
4. git commit -m "refactor: [description]"
5. Repeat from step 2Extract Function Pattern
// ❌ Before — inline, hard to test independently
function createOrder(items: Item[], userId: string) {
if (!items || items.length === 0) {
throw new Error('Order must have items');
}
const total = items.reduce((s, i) => s + i.price * i.qty, 0);
if (total > 10000) {
throw new Error('Order total exceeds limit');
}
// ... save to DB
}
// ✅ After — each function has a single responsibility
function validateOrderItems(items: Item[]): void {
if (!items || items.length === 0) {
throw new Error('Order must have items');
}
}
function calculateOrderTotal(items: Item[]): number {
return items.reduce((s, i) => s + i.price * i.qty, 0);
}
function assertTotalWithinLimit(total: number): void {
if (total > 10000) throw new Error('Order total exceeds limit');
}
function createOrder(items: Item[], userId: string) {
validateOrderItems(items);
const total = calculateOrderTotal(items);
assertTotalWithinLimit(total);
// ... save to DB
}Extract Variable Pattern
// ❌ Before — magic numbers and complex expression
if (user.createdAt < Date.now() - 30 * 24 * 60 * 60 * 1000) { ... }
// ✅ After — named intent
const THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1000;
const accountAge = Date.now() - user.createdAt;
const isNewUser = accountAge < THIRTY_DAYS_MS;
if (isNewUser) { ... }Danger Signs — Stop Immediately
- Tests breaking during refactor → undo, try smaller step
- Adding a feature while refactoring → separate commit
- Renaming AND moving in same commit → split into two commits
- Touching unrelated code → leave it alone
Output Format
## Refactor Summary
### Transformations (in order applied)
1. Extracted `validateOrderItems()` — order.ts:23-28
2. Extracted `calculateOrderTotal()` — order.ts:29-31
3. Renamed `getData()` → `fetchUserProfile()` — 4 files
### Before/After
- order.ts: 180 lines → 120 lines
- 2 new unit tests for extracted functions
### Test Results
- Before: 45 tests passing
- After: 47 tests passingDoes 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.

