refactor
Skill3 starsChanged 30 days agoMITView on GitHub
Guided refactoring with behavior preservation verification. Identifies candidates (long functions, deep nesting, duplicated logic, god classes), proposes a refactoring plan, executes incrementally with tests between steps, and verifies no behavior change. Use when user says "refactor", "clean up this code", "simplify", "extract", "restructure", "reduce complexity", "split this file", or wants to improve code structure without changing behavior. For new features, use /plan; for bug fixes, use /investigate; for code review, use /review.
196 other projects use a version of this.
Adopted by
Most recently taken up by
- Doist/todoist-aitheir own version, first seen Nov 9, 2026
- Doist/todoist-clitheir own version, first seen Nov 8, 2026
- rvdbreemen/OTGW-firmwaretheir own version, first seen Nov 8, 2026
- paulocsb/worldcup-fifa-pooltheir own version, first seen Nov 8, 2026
- DnsQueen/orcinus-skillstheir own version, first seen Nov 8, 2026
- taixuann/development-spacetheir own version, first seen Nov 8, 2026
Used with
Projects with it also use ascii-diagram, debug-fix 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.
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
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
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
Other versions196 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 196
- 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★ 710same name
- membrane/api-gateway★ 658same name
186 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 repository42 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- asideSkill
- assessmentSkill
- auditSkill
- benchmarkSkill
- brainSkill
- checkpointSkill
- cleanupSkill
- concise-modeSkill
- cross-modelSkill
- deploySkill
- designSkill
- explainSkill
- fix-issueSkill
- ganSkill
- guardSkill
- hotfixSkill
- incidentSkill
- infraSkill
- interview-meSkill
- investigateSkill
- migrateSkill
- module-auditSkill
- morningSkill
- onboardSkill
- planSkill
- profileSkill
- pr-summarySkill
- readmeSkill
- researchSkill
- resolveSkill
- respondSkill
- retroSkill
- reviewSkill
- session-logSkill
- setupSkill
- shipSkill
- skill-newSkill
- spikeSkill
- tddSkill
- testSkill
- zoom-outSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
24 rules. 0 are common, 21 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 169 edited versions we read keep these.
21
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 23
No arguments: analyze the current branch diff for refactoring candidates.
- Distinctive: line 33
Record coverage: If a coverage tool is configured, record the current coverage numbers for affected files.
- Very specific: line 36
Write characterization tests first: tests that pin the current observable behavior, including behavior that looks wrong, through the public …
- Distinctive: line 37
Stop and report which units lack coverage.
- Very specific: line 65
If --plan-only was passed, stop here.
- Distinctive: line 72
Predict the test outcome: All existing tests must continue to pass with no modifications.
- Distinctive: line 74
Run tests: If tests fail:
- Distinctive: line 78
If the alternative also fails, skip this candidate and move to the next.
- Distinctive: line 87
Run the formatter check. No changes.
- Distinctive: line 88
Run the full test suite. All tests pass.
- Distinctive: line 89
Run the linter. Zero warnings.
- Distinctive: line 90
Run the type checker. Zero errors.
- Distinctive: line 91
Run the build. Clean build.
- Distinctive: line 97
Never change behavior. A refactoring that alters what the code does is a bug, not a refactoring.
- Distinctive: line 98
Never combine refactoring with feature work in the same commit.
- Distinctive: line 99
Never modify test assertions during refactoring.
- Distinctive: line 102
Do not refactor code you do not understand.
- Distinctive: line 115
Stop before any change when the Phase 1 test run fails.
- Distinctive: line 116
Stop and write characterization tests, or report the gap, when a candidate touches lines no test reaches.
- Distinctive: line 117
Stop and revert when a test fails after a step.
- Distinctive: line 118
Stop and read the function, its callers, and its tests when the next edit targets code you have not read.
- Distinctive: line 119
Stop and split the commit when its diff mixes a structural change with a behavior change.
- Very specific: line 120
Stop at the Phase 3 table when --plan-only was passed.
- Distinctive: line 128
Every skipped candidate is listed with the test failure that ruled it out.
“Common” is measured: kept by at least 6 in 10 of the 169 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
Incremental refactoring workflow that enforces behavior preservation at every step. Each refactoring is a separate commit with test verification before and after.
The refactoring principles follow ../../rules/code-style.md. This skill provides the execution workflow.
When to Use
- Tests pass, and a function, file, or class crosses one of the Phase 2 thresholds.
- A feature is next, and the code it lands in has to be made easy to change first.
/module-auditproduced a consolidation the user picked.- For new behavior, use
/plan; for a bug, use/investigate; for feedback on a diff, use/review.
Arguments
- No arguments: analyze the current branch diff for refactoring candidates.
<path>: refactor the specified file or directory.--plan-only: identify and rank candidates without executing any changes.
Process
Phase 1: Establish Baseline
- Run the full test suite. Record the result. If tests fail, stop. Do not refactor code with a failing test suite. The user must fix tests first.
- Record coverage. If a coverage tool is configured, record the current coverage numbers for affected files. Coverage must not decrease after refactoring.
- Gate on coverage of the target. Every line and branch the refactoring will move needs a test that observes its behavior; the suite passing proves nothing about code no test reaches. When coverage of the target is insufficient, or no coverage tool exists to show it, take one of two paths:
- Write characterization tests first: tests that pin the current observable behavior, including behavior that looks wrong, through the public interface. Commit them alone as
test(<scope>): characterize <unit>before any structural change. - Stop and report which units lack coverage. Never refactor uncovered code.
- Write characterization tests first: tests that pin the current observable behavior, including behavior that looks wrong, through the public interface. Commit them alone as
Phase 2: Identify Candidates
Scan the target files for refactoring candidates. Check each category:
| Category | Threshold | Refactoring |
| Long functions | >30 lines | Extract function |
| Deep nesting | >3 levels | Guard clauses, early returns |
| Duplicated blocks | >5 lines appearing 2+ times | Extract shared function |
| Large files | >500 lines, per rules/code-style.md | Split by responsibility |
| God classes | >7 public methods | Split into focused classes |
| Long parameter lists | >4 parameters | Extract options object |
| Circular imports | Any cycle | Restructure module boundaries |
| Dead code | Unreachable branches, unused exports | Remove |
| Primitive obsession | Repeated string/number with domain meaning | Extract type or enum |
| Feature envy | Function using more of another module's data than its own | Move to the correct module |
Phase 3: Rank and Present
Rank candidates by impact score: lines affected multiplied by complexity reduction. Present as a table:
| Priority | File | Line | Issue | Proposed refactoring | Impact |
| 1 | ... | ... | ... | ... | High |
| 2 | ... | ... | ... | ... | Medium |
If --plan-only was passed, stop here.
Phase 4: Execute Incrementally
For each approved candidate, in priority order:
- Describe the change. State what will change and what will stay the same.
- Predict the test outcome. All existing tests must continue to pass with no modifications.
- Apply the refactoring. One structural change at a time.
- Run tests. If tests fail:
- Revert the change.
- Analyze why the refactoring broke tests. If the tests were testing implementation details rather than behavior, note this as a separate finding.
- Try an alternative approach.
- If the alternative also fails, skip this candidate and move to the next.
- Run formatter, linter, type checker, and build. Fix any new warnings introduced by the refactoring before the commit.
- Commit. One commit per refactoring step:
refactor(scope): extract validateInput from processOrderrefactor(scope): flatten nested conditionals in AuthServicerefactor(scope): remove duplicate price calculation
Phase 5: Final Verification
- Run the formatter check. No changes.
- Run the full test suite. All tests pass.
- Run the linter. Zero warnings.
- Run the type checker. Zero errors.
- Run the build. Clean build.
- Compare coverage. Coverage is equal to or higher than the baseline.
- Review the full diff. Confirm no behavior changes leaked in.
Rules
- Never change behavior. A refactoring that alters what the code does is a bug, not a refactoring.
- Never combine refactoring with feature work in the same commit. Structure changes and behavior changes are separate commits.
- Never modify test assertions during refactoring. If a test breaks, the refactoring changed behavior.
- One refactoring per commit. If a commit does two things, split it.
- Revert immediately when tests fail. Do not debug a failed refactoring for more than 5 minutes. Try a different approach or skip the candidate.
- Do not refactor code you do not understand. Read the function, its callers, and its tests before touching it.
Common Rationalizations
- "The test only broke because it asserts an implementation detail, so updating the assertion is fine": assertions stay untouched. Revert, and report the brittle test as its own finding.
- "The off-by-one is right here, fixing it during the extraction is quicker": a behavior change goes in its own commit, apart from the structural one.
- "Two tiny refactorings fit in one commit": one refactoring per commit, so each step reverts alone.
- "The suite was already red before I started": the baseline stays green. Stop until the user fixes the failing tests.
- "The suite is green, so the refactoring is safe": green says nothing about lines no test reaches. Characterize them first, or stop.
- "Five more minutes of debugging will save this candidate": revert, try one alternative, and skip the candidate when that also fails.
Red Flags
- Stop before any change when the Phase 1 test run fails.
- Stop and write characterization tests, or report the gap, when a candidate touches lines no test reaches.
- Stop and revert when a test fails after a step.
- Stop and read the function, its callers, and its tests when the next edit targets code you have not read.
- Stop and split the commit when its diff mixes a structural change with a behavior change.
- Stop at the Phase 3 table when
--plan-onlywas passed.
Verification
- The full test suite passes, and the diff touches no test assertion.
- The linter reports zero warnings, the type checker zero errors, and the build is clean.
- Coverage of the affected files is at or above the Phase 1 baseline.
git logshows onerefactor(<scope>)commit per applied candidate.- Every skipped candidate is listed with the test failure that ruled it out.
Related skills
/review-- Review the refactoring diff before shipping./test-- Run the test suite during verification./ship commit-- Commit each refactoring step./investigate-- Debug if a refactoring unexpectedly changes behavior.
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.

