refactor
Skill9 starsChanged 3 months agoMITView on GitHub
Evidence-driven refactoring — where does structural improvement actually pay off, then make that change without changing behavior. Survey mode diagnoses by evidence, not aesthetics — git churn × complexity hotspots, the recurring-bug log, upcoming work — and verdicts each candidate REFACTOR/PREP/LEAVE/WATCH, where LEAVE is the default and "the textbook recommends it" is never a reason. Execute mode takes one approved candidate in small behavior-preserving moves, suite green after each. Keeps a debt register in out/refactor/tracker.md so repeat surveys open with what changed. Use for "clean up this module", "improve the architecture", "pay down tech debt" — e.g. "/refactor", "/refactor <target>". For new behavior use feature; for something broken use bugfix.
111 other projects use a version of this.
Adopted by
Most recently taken up by
- AllThingsSmitty/proven-skillstheir own version, first seen Oct 6, 2026
- GUOJIE-HONG/skillstheir own version, first seen Oct 5, 2026
- morodomi/dev-crewtheir own version, first seen Oct 5, 2026
- gilsmt/skillstheir own version, first seen Oct 4, 2026
- Integralist/agent-skillstheir own version, first seen Oct 4, 2026
- AlvaroVFon/skillstheir own version, first seen Oct 3, 2026
Used with
Projects with it also use modern-go, to-design 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.
jidechaoSkillmodern-go
Modernize Go code by applying version-appropriate idioms and APIs (gofix-style transformations). Scans go.mod for the Go version, then transforms Go source files to use modern patterns—from Go 1.0 through 1.26+. Use when the user says "现代化","现代Go语言", "地道的", "idiomatic", "modernize", "modern-go", "update Go code", "gofix", or wants to upgrade Go idioms.
Also in 3 projects that use this
jidechaoSkillto-design
Generate a design document (design proposal) from a PRD, in the style of Go's official design proposals — Abstract / Background / Design / Rationale / Compatibility / Implementation, heavy on the 'why' and tradeoffs. Triggers on: to-design, prd-to-design, prd转设计文档, 生成设计文档, 写设计文档, design doc, design proposal, 设计提案, 技术设计文档.
Also in 3 projects that use this
chidekinaSkilltest-gen
Generate test cases from type constraints and specs. Creates boundary tests, edge cases, and fixtures automatically. Pact-lang inspired. Triggers on: generate tests, test from spec, create fixtures, boundary tests.
Also in 5 projects that use this
pvnarpSkillincident
Guides incident response and post-mortem analysis. Covers triage, mitigation, root cause analysis, and prevention. Use when responding to active incidents, writing post-mortems, or improving incident processes.
Also in 6 projects that use this
platformplatformSkilldb-query
Query the local Postgres database of the active Aspire worktree via psql.
Also in 3 projects that use this
JetBrainsSkillfix-bug
End-to-end bug fix workflow for the Exposed project. Accepts a GitHub issue (#NUMBER), YouTrack issue (EXPOSED-NUMBER), or YouTrack URL (https://youtrack.jetbrains.com/issue/EXPOSED-NUMBER). Fetches the issue, creates a failing reproducer test, commits on a new branch, implements the fix, validates, and opens a PR. Use this skill whenever the user wants to fix a bug from an issue tracker, mentions a EXPOSED issue number, or references a GitHub issue to fix.
Also in 6 projects that use this
- +2 more from jidechao
Other versions111 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 111
- github/awesome-copilot★ 40ksame name
- parcadei/Continuous-Claude-v3★ 3.9ksame name
- codeaholicguy/ai-devkit★ 1.6ksame name
- SethGammon/Citadel★ 922same name
- solatis/claude-config★ 909same name
- boshu2/agentops★ 447same name
- nwiizo/tfmcp★ 373same name
- smallnest/goal-workflow★ 287same name
- oasm-platform/open-asm★ 204same name
- sd0xdev/sd0x-harness★ 191same name
101 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.
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 7 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 94 edited versions we read keep these.
7
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 107
Red after a step → revert that step: Never patch forward to green — a patched-forward red is a behavior change wearing a refactor's name.
- Distinctive: line 110
Every checkpoint leaves the tree shippable.
- Distinctive: line 124
No new features, no "while I'm here" improvements outside the stated goal, no public-interface changes the goal didn't name.
- Distinctive: line 129
Run done on the diff. The spec it reviews against is exactly: *behavior unchanged, structure goal met* — its evidence checklist and …
- Distinctive: line 132
Update the tracker row (status, date, commit).
- Distinctive: line 157
Tests are the arbiter: No suite → characterization tests first.
- Distinctive: line 159
Interface depth is the score: If callers didn't get simpler, adding a pattern made it worse — pattern count is not a metric.
“Common” is measured: kept by at least 6 in 10 of the 94 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 — earn it first, then preserve behavior
/refactor — survey the repo, emit a brief of where improvement pays off
/refactor <target or goal> — execute one candidate, safely
Answer one question: where does structural improvement actually pay for itself in this codebase — and how is that change made without changing behavior? The skill exists to prevent the two documented failure modes of "improve the architecture": refactoring the wrong code (most ugly code is never touched again, so cleaning it returns nothing), and pattern-itis — applying design patterns because they're best practices rather than because a problem here demands them, turning straight-line code into abstraction lasagna.
Survey mode — /refactor
Step 1 — Evidence, not aesthetics
Candidates come from signals, never from "this code looks bad":
- Hotspots — churn × complexity. Churn from git itself:
git log --format= --name-only --since="12 months ago" | sort | uniq -c | sort -rn | head -30, crossed with a complexity proxy (file length, indentation depth). Code that is both complex and frequently edited is where interest compounds; complex-but-cold code is a LEAVE by default. - The bug log —
out/dev/bugfix-log.mdif present. A file that shows up repeatedly is structural debt announcing itself. - Upcoming work — the user's stated goals, open specs and plans under
out/dev/. These seed PREP candidates: make the change easy, then make the easy change — preparatory refactoring is the highest-payoff kind because the payoff is scheduled, not hoped for. - The map —
AGENTS.mdgotchas and conventions; a documented gotcha is often a workaround for structure that could stop needing one. - Memory —
out/refactor/tracker.mdif it exists: verdicts already made. A LEAVE with a reason isn't re-litigated unless its evidence changed; repeat surveys open with "Since last survey".
Step 2 — Verdicts, with the pattern gate
For each candidate: REFACTOR / PREP / LEAVE / WATCH.
- LEAVE is the default. Promotion needs positive evidence: churn, a recurring bug, or scheduled work in the area. "This violates a principle" alone promotes nothing — cold code keeps its sins.
- The pattern gate: a design pattern is vocabulary, not a goal. Every proposal that introduces one names the problem in this codebase (with a file:line locator and its evidence), why this pattern fits, and what simpler shape was considered first. "The textbook recommends it" is discarded, not weighed. Two quick tests: the deletion test — imagine deleting the module; if complexity vanishes it was a pass-through, if it reappears across N callers it was earning its keep — and one adapter is a hypothetical seam, two are a real one: don't introduce a seam until something actually varies across it.
- The score is interface depth, not pattern count. A proposal wins if interfaces get simpler and callers get dumber — abstractions that hide more than they add. A refactor that grows the number of things a reader must understand has failed even if every step was clean.
- Each REFACTOR/PREP carries: the problem + locator, the target shape, a
sketch of the move sequence, effort, and risk. Candidates too big to stay
behavior-preserving (real redesigns) are phrased as ready
/featureor/autopilothandoffs instead — offered, never performed.
Step 3 — Brief and register
Render the brief in chat per references/brief-template.md (read it
when you reach this step), save to out/refactor/<slug>-<YYYY-MM-DD>.md
(date via date +%F; create the folder if needed; committing is the user's
call), and update out/refactor/tracker.md — one row per candidate:
candidate · verdict · evidence · date · status. The user picks what to
execute; the survey never starts cutting on its own.
Execute mode — /refactor <target>
Step 1 — Safety net before scalpel
- Find the test command (
AGENTS.md, manifests, CI config) and run the suite for a green baseline. A pre-existing red is reported and stops the run — refactoring on red has no arbiter. - Area untested? Write characterization tests around exactly the code to be touched — pin current behavior as it is, bugs included — and commit them separately before any restructuring. Without them, "behavior preserved" is an opinion.
Step 2 — Small named moves, green after each
Plan the sequence as named moves — extract function, move module, rename, inline, introduce parameter object — then per move: apply it, run the suite, checkpoint commit titled with the move. The rhythm is the safety:
- Red after a step → revert that step. Never patch forward to green — a patched-forward red is a behavior change wearing a refactor's name. Rethink the move or split it smaller.
- Every checkpoint leaves the tree shippable. There is no big-bang branch where everything is broken until the end.
- Wide mechanical moves (a rename or retype fanning across hundreds of call sites) sequence as expand–contract: add the new form beside the old so nothing breaks, migrate call sites in blast-radius-sized batches (per package or directory, checkpoint each), then contract — delete the old form once no caller remains. The tree stays shippable through the whole fan-out.
Step 3 — Behavior-preserving is the definition
- A bug found mid-refactor is logged (
out/dev/bugfix-log.md, offered as a ready/bugfixinvocation) and its behavior deliberately preserved. Fixing it in flight changes behavior and poisons the diff's reviewability. - No new features, no "while I'm here" improvements outside the stated goal, no public-interface changes the goal didn't name.
Step 4 — Ship, then refresh the map
- Run done on the diff. The spec it reviews against is exactly: behavior unchanged, structure goal met — its evidence checklist and fresh-context review apply verbatim.
- Update the tracker row (status, date, commit).
- Structure changed means the map is stale: finish with
/map refresh.
Auto mode — under autopilot
Driven by autopilot (or explicit auto), the survey's brief-approval
becomes a self-approval on the record in the run's log.md, and only
candidates whose evidence survives the pattern gate proceed; anything
arguable parks. Execution changes nothing — the suite was already the
arbiter, and every hard rule above holds verbatim.
State
out/refactor/: tracker.md (the debt register) and dated briefs. An
interrupted execution resumes from git log — the checkpoint commits are
the state — plus the tracker row; never from conversation memory.
Guardrails
- LEAVE is the default. Payoff requires churn, bugs, or scheduled work; aesthetics promote nothing.
- "The textbook recommends it" is never a reason. A pattern needs a named, located problem in this codebase.
- Behavior-preserving or it isn't refactoring. Bugs are logged and kept, features wait, the goal bounds the diff.
- Tests are the arbiter. No suite → characterization tests first; red step → revert, never patch forward.
- Interface depth is the score. If callers didn't get simpler, adding a pattern made it worse — pattern count is not a metric.
- The survey never cuts. Diagnosis and execution are separate consents; the brief recommends, the user picks the target.
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.

