workflow-refactor
Skill10 starsChanged 13 days agoMITView on GitHub
Scoped, behavior-preserving refactor: map dependencies, change structure, run affected tests. Use when "refactor this", "reduce duplication", or "improve readability". Dead code → plan-dead-code. Repo-wide smells → audit-code-quality.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- aloilor/lean-coding-agenttheir own version, first seen Nov 29, 2026
- kensaurus/skillsword for word, first seen Nov 17, 2026
Other versions2 projects use a version of this.
Word for word · 1
- kensaurus/skills★ 10100% same
Edited · 0
None found.
Wrote their own version · 1
- aloilor/lean-coding-agent★ 7same 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 repository166 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .cursor/rules/approved-plan-execution.mdcCursor rule
- .cursor/rules/skill-workflows.mdcCursor rule
- .cursor/rules/verification-before-completion.mdcCursor rule
- llms.txtllms.txt
- audit-accessibilitySkill
- audit-agent-speedSkill
- audit-analyticsSkill
- audit-auth-flowsSkill
- audit-backend-architectureSkill
- audit-bundle-sizeSkill
- audit-cicdSkill
- audit-codemod-safetySkill
- audit-code-qualitySkill
- audit-code-reviewSkill
- audit-db-schemaSkill
- audit-doctrineSkill
- audit-env-paritySkill
- audit-fe-apiSkill
- audit-gate-logicSkill
- audit-i18nSkill
- audit-infra-costSkill
- audit-langfuse-llmSkill
- audit-llm-securitySkill
- audit-monetization-iapSkill
- audit-payment-systemSkill
- audit-performanceSkill
- audit-realworldSkill
- audit-registry-listingSkill
- audit-resilienceSkill
- audit-responsiveSkill
- audit-securitySkill
- audit-skill-conflictsSkill
- audit-ui-statesSkill
- audit-uiux-design-systemSkill
- audit-ux-journeysSkill
- audit-uxSkill
- backend-db-performanceSkill
- backend-error-handlingSkill
- backend-observabilitySkill
- backend-patternsSkill
- backend-realtimeSkill
- burndown-fullSkill
- complete-everythingSkill
- data-pipelineSkill
- data-visualizationSkill
- debug-errorSkill
- debug-fe-be-integrationSkill
- debug-sentry-monitorSkill
- deploy-npmSkill
- deploy-verifySkill
- design-apiSkill
- design-canvasSkill
- design-emailSkill
- design-frontendSkill
- design-generative-artSkill
- design-mobile-firstSkill
- design-motionSkill
- design-prdSkill
- design-systemSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
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
- Very specific: line 65
Use Grep and SemanticSearch to find:
- Distinctive: line 68
Every file that imports or depends on the code being refactored
- Distinctive: line 72
Before changing any function, class, or component:
- Distinctive: line 82
If the refactoring introduces a new pattern, verify it's current best practice:
- Distinctive: line 278
No test coverage (write tests first)
- Distinctive: line 279
Don't understand the code yet (read and learn first)
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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 Code Skill
Degree of freedom: MIXED. Structure target [HIGH freedom];
behavior-preserving checks and affected tests [LOW freedom — run exactly].
This skill vs neighbors
| Skill | Owns |
| workflow-refactor (this) | Scoped, behavior-preserving structure change with affected tests run |
audit-code-quality | Repo-wide anti-patterns and consistency drift, detected and fixed |
plan-dead-code | Plan-only dead-code audit with Knip; deletes nothing |
How to reason
- Observe — current structure, callers, tests
- Interpret — duplication vs needed variation
- Classify — extract / inline / rename / stop (behavior would change)
- Severity — a public API change is not this skill
Everything here preserves behavior. Removing code is a different
contract: plan-dead-code proves it unreachable and housekeep-dead-code
deletes it against an approved list. Duplication findings arrive here from
those skills; deletions do not leave from here.
Worked example
Observe: three copy-pasted date formatters; tests only cover one. Interpret: same behavior, three implementations. Classify: extract
formatDate; add the missing two call-site tests first (red), then extract (green). Verify: same output; no new features.
Self-critique before reporting
- Behavior same — existing tests still pass; no silent product change
- Scoped — not a repo-wide drive-by
- Tests first — missing coverage added before the move when needed
- Right owner — repo-wide anti-pattern →
audit-code-quality; mechanical rename →burndown-full
Improve code quality without changing external behavior. Research-aware.
Pre-refactoring checks [LOW freedom — run exactly]
Before refactoring any code:
1. Read Relevant Documentation
README.md (project overview)
src/[domain]/@_[domain]-README.md (domain architecture)
CONTRIBUTING.md (code standards)2. Understand Existing Patterns
Use Grep and SemanticSearch to find:
- How similar code is structured elsewhere in the codebase
- What patterns are already established
- Every file that imports or depends on the code being refactored
3. Map the Blast Radius
Before changing any function, class, or component:
rg "functionName" --type ts # find all callers
rg "import.*from.*module" --type ts # find all importersList every file that will be affected by the change.
4. Research Modern Patterns (for non-trivial refactors)
If the refactoring introduces a new pattern, verify it's current best practice:
firecrawl:firecrawl_search
{
"query": "<framework> <pattern> best practice <current year>",
"limit": 5,
"sources": [{ "type": "web" }]
}Scrape the most authoritative result:
firecrawl:firecrawl_scrape
{
"url": "<best-result-url>",
"formats": ["markdown"],
"onlyMainContent": true
}This prevents refactoring FROM one outdated pattern TO another outdated pattern.
5. Verification Statement
Before refactoring, state:
"Pre-refactoring check:
- README/docs read: [list]
- Dependent files identified: [list files that import this code]
- Blast radius: [N files affected]
- Tests exist: [YES/NO — if NO, write tests first]
- Pattern verified: [YES via research / YES matches codebase / SKIP — trivial refactor]"Refactoring Principles [HIGH freedom]
- Behavior stays the same — tests pass before and after
- Small steps — one change at a time, verify after each
- Test frequently — run tests after each change
- Commit often — easy to revert if something breaks
- Research first — don't replace old patterns with other old patterns
- Scope holds — a smell outside the named target is a note in the report, not part of this refactor; a bug you find is a follow-up. Tests added here cover the seam being moved or match what the repo already keeps; scratch checks stay out of the repo. Move code in place rather than rewriting whole files.
Code Smells and Fixes [HIGH freedom]
| Smell | Symptom | Solution |
| Long Function | >20 lines, does multiple things | Extract functions |
| Duplicate Code | Same logic in 2+ places | Extract shared function/hook |
| Magic Numbers | Unexplained literals | Named constants or config |
| Deep Nesting | 3+ levels of if/loops | Early returns, extract functions |
| Long Parameter List | >3 parameters | Object parameter with interface |
| Feature Envy | Function uses another module's data heavily | Move function to that module |
| God Object | One class/component does everything | Split by responsibility |
| Primitive Obsession | Using strings/numbers where a type would be safer | Create domain types |
| Shotgun Surgery | One change requires editing many files | Consolidate related logic |
| Dead Code | Unreachable or unused code | Not this skill — proving it dead is plan-dead-code, deleting it is housekeep-dead-code. Note it and move on |
Common Refactorings [HIGH freedom]
Extract Function
Before:
function processOrder(order: Order) {
if (!order.items.length) throw new Error('Empty order');
if (!order.customer) throw new Error('No customer');
if (order.total < 0) throw new Error('Invalid total');
const subtotal = order.items.reduce((sum, i) => sum + i.price, 0);
const tax = subtotal * 0.1;
const total = subtotal + tax;
db.orders.insert({ ...order, total });
}After:
function processOrder(order: Order) {
validateOrder(order);
const total = calculateTotal(order);
saveOrder({ ...order, total });
}Flatten Nested Conditionals
Before:
function getDiscount(user: User, order: Order) {
if (user) {
if (user.isPremium) {
if (order.total > 100) {
return 0.2;
} else {
return 0.1;
}
}
}
return 0;
}After:
function getDiscount(user: User | null, order: Order) {
if (!user) return 0;
if (user.isPremium && order.total > 100) return 0.2;
if (user.isPremium) return 0.1;
return 0;
}Replace Magic Numbers
// Before
if (password.length < 8) { ... }
if (retries > 3) { ... }
const tax = amount * 0.1;
// After
const MIN_PASSWORD_LENGTH = 8;
const MAX_RETRIES = 3;
const TAX_RATE = 0.1;Use Object Parameters
// Before — positional args are error-prone
function createUser(name: string, email: string, age: number, role: string) { ... }
// After — named, self-documenting, extensible
interface CreateUserParams {
name: string;
email: string;
age: number;
role: string;
}
function createUser(params: CreateUserParams) { ... }Refactoring Process [LOW freedom — run exactly]
1. Verify tests pass → 2. Make one small change → 3. Verify tests pass → 4. Commit → 5. RepeatCommit Message Format
refactor(scope): description of structural change
- What was changed and why
- No behavior changeRefactoring Checklist [LOW freedom — do not skip]
Before Starting
- Tests pass (if no tests, write them first)
- Understand current behavior
- All dependent files identified
- Pattern researched (if introducing new pattern)
- Specific smell identified
During Refactoring
- One change at a time
- Tests run after each change
- Working states committed
After Refactoring
- All tests still pass
- Code is more readable
- No behavior changes
- Performance not degraded
- All dependent files updated
- Types still correct (no new
anyor casts)
When NOT to Refactor [LOW freedom — do not skip]
- No test coverage (write tests first)
- Don't understand the code yet (read and learn first)
- Code is being deleted soon
- The refactoring has no clear benefit
- Under deadline pressure (ship first, refactor in a follow-up)
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.

