refactor
Skill1 starsChanged 27 days agoMITView on GitHub
Guide safe, disciplined code refactoring. Always use this skill when asked to refactor, restructure, reorganize, clean up, or improve the design of existing code. Use when the user says "this code is messy", "help me clean this up", "this function does too much", "extract this", "break this apart", "this is hard to read", "the codebase is tangled", or any time code structure needs to change without changing behavior. Read this skill before making any structural code changes.
We split this skill into the rules it gives an agent
20 rules. 0 are common, 20 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 160 edited versions we read keep these.
20
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 12
If the tests aren't passing before you refactor, you don't have a baseline.
- Distinctive: line 14
If there are no tests for the code you're about to refactor, write enough to cover the behavior you're going to disturb before touching …
- Distinctive: line 20
If the code you need to refactor has no obvious seam, your first task is to introduce one safely (often by extracting a function or class …
- Distinctive: line 26
Leave the tests green
- Distinctive: line 30
Don't do five things in one commit and call it a refactoring.
- Distinctive: line 36
Extract function/method: when a block of code has a single purpose and could be named:
- Distinctive: line 40
Verify the caller's behavior is identical before and after
- Distinctive: line 42
Rename: when a name is misleading, vague, or no longer accurate:
- Distinctive: line 45
Update documentation and comments at the same time
- Distinctive: line 47
Inline: when an abstraction is adding indirection without adding clarity:
- Distinctive: line 50
Don't inline just to reduce line count
- Distinctive: line 52
Move: when code belongs in a different module, class, or file:
- Distinctive: line 55
Update all call sites before committing
- Distinctive: line 57
Simplify conditionals: when nested ifs are hard to follow:
- Distinctive: line 63
Reduce coupling: when a module knows too much about another:
- Distinctive: line 70
Not a feature: Don't add new behavior while refactoring.
- Distinctive: line 84
Don't refactor code that's stable and rarely touched.
- Distinctive: line 88
When working on a refactoring:
- Distinctive: line 92
Call out any risks: "This change touches the auth middleware, which has no tests.
- Distinctive: line 93
Keep commits focused so the reviewer can tell what changed and why
“Common” is measured: kept by at least 6 in 10 of the 160 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
Refactor
Refactoring is changing code structure without changing behavior. The key word is without. Every technique here is designed to preserve correctness while improving the code's shape.
The cardinal rule: tests must be green before you start
If the tests aren't passing before you refactor, you don't have a baseline. You can't tell whether a broken test is the result of your change or was already broken. Fix failing tests first. That's a separate job from the refactoring.
If there are no tests for the code you're about to refactor, write enough to cover the behavior you're going to disturb before touching anything. You don't need 100% coverage: you need enough that a behavioral regression would show up.
Identify the seam before cutting
A seam is a place where behavior can change without editing the code that uses it, typically a function boundary, interface, or injection point. Find the seam before you start cutting. The seam defines the scope of your refactoring: you're rearranging what's inside it while keeping the seam's behavior the same from the outside.
If the code you need to refactor has no obvious seam, your first task is to introduce one safely (often by extracting a function or class around the region you want to change).
Work in small, reversible steps
Each step should:
- Leave the tests green
- Be a single logical change (rename, extract function, move, inline, etc.)
- Be independently reviewable
Don't do five things in one commit and call it a refactoring. If something goes wrong, you want to be able to bisect to the exact step that introduced the problem.
A useful rhythm: change → run tests → commit. If the tests go red, undo and understand why before proceeding.
Common refactoring moves
Extract function/method: when a block of code has a single purpose and could be named:
- Name it for what it does, not how it does it
- Pass in what it needs as parameters (avoid reaching for outer scope)
- Verify the caller's behavior is identical before and after
Rename: when a name is misleading, vague, or no longer accurate:
- Rename completely and immediately; don't leave both names alive unless there's a real API boundary requiring it
- Update documentation and comments at the same time
Inline: when an abstraction is adding indirection without adding clarity:
- Inline functions that are called in only one place and whose name doesn't add understanding
- Don't inline just to reduce line count
Move: when code belongs in a different module, class, or file:
- Move one thing at a time
- Update all call sites before committing
Simplify conditionals: when nested ifs are hard to follow:
- Early returns / guard clauses to eliminate nesting
- Pull boolean conditions into well-named variables
- Replace complex switch/if chains with a dispatch table or polymorphism when appropriate
Reduce coupling: when a module knows too much about another:
- Identify what information actually needs to cross the boundary
- Pass only what's needed, not the whole object
What refactoring is not
Not a feature: Don't add new behavior while refactoring. If you notice something missing, make a note and add it after the refactoring is done and reviewed.
Not cleanup: Fixing a bug while refactoring mixes two concerns. When a test reveals a bug during refactoring, stop, fix the bug separately, then continue the refactoring.
Not rewriting: Rewriting is starting over. Refactoring is incremental improvement of existing code. If you find yourself wanting to throw it all out and start fresh, that's a different conversation; it may be justified, but it's not refactoring.
When to stop
Refactoring is in service of a goal, not an end in itself. Stop when:
- The code is clear enough that a reader can understand it without your help
- The next feature would be straightforward to add
- The change you're making has diminishing returns
Don't refactor code that's stable and rarely touched. The cost of changing it (risk, review time) exceeds the benefit. Focus effort on code that's actively worked on.
Communicate what you're doing
When working on a refactoring:
- State the goal up front: "I'm going to extract the validation logic into a separate function so the handler is easier to read."
- Note the technique: "This is an extract-and-replace. I'm not changing behavior."
- Call out any risks: "This change touches the auth middleware, which has no tests; I'll add coverage before moving it."
- Keep commits focused so the reviewer can tell what changed and why
Other versions187 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 187
- github/awesome-copilot★ 41ksame name
- unkeyed/unkey★ 5.5ksame name
- parcadei/Continuous-Claude★ 3.9ksame name
- parcadei/Continuous-Claude-v2★ 3.9ksame name
- parcadei/Continuous-Claude-v3★ 3.9ksame name
- adobe/S3Mock★ 1.2ksame name
- SethGammon/Citadel★ 927same name
- poshan0126/dotclaude★ 871same name
- JordanCoin/codemap★ 707same name
- membrane/api-gateway★ 656same name
177 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 debug-fix, ascii-diagram 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.
zebbernSkilldebug-fix
Find and fix a bug or issue — from any source (GitHub issue, error message, user report, or observed behavior)
Also in 4 projects that use this
SethGammonSkillascii-diagram
Generate perfectly aligned ASCII diagrams — architecture, flow, sequence, box-and-arrow. Uses a programmatic character-grid approach so alignment is guaranteed by math, not token prediction. Includes post-render verification.
Also in 4 projects that use this
parcadeiSkillagent-context-isolation
Agent Context Isolation
Also in 3 projects that use this
parcadeiSkillagentica-infrastructure
Reference guide for Agentica multi-agent infrastructure APIs
Also in 3 projects that use this
- +8 more from parcadei
In this repository25 other files it gives its agents.
- api-designSkill
- arch-reviewSkill
- db-reviewSkill
- debugSkill
- dotnet-asyncSkill
- dotnet-opsSkill
- dotnet-testingSkill
- dotnet-typesSkill
- go-concurrencySkill
- go-opsSkill
- go-testingSkill
- go-typesSkill
- incidentSkill
- node-asyncSkill
- node-opsSkill
- perfSkill
- pr-prepSkill
- py-asyncSkill
- py-opsSkill
- py-testingSkill
- py-typesSkill
- securitySkill
- test-genSkill
- ts-testingSkill
- ts-typesSkill
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.

