/claude-swe-workflows:refactorfrom claude-swe-workflows
Redesigns codebases using Musk's five-step simplification algorithm, with behavior verified by differential testing against the original implementation. Runs autonomously on an isolated branch after a single operator checkpoint.
Ships in claude-swe-workflows. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A conventional refactor of the Gen-1 engine produces the Gen-1 engine with better cable management. This skill's mandate is different: redesign the machine with simplification as the end goal — the Gen-3 engine that is more capable and has visibly less machine. It refactors design, not implementation; implementation falls out of the smaller design.
The spine of this skill is the five-step design algorithm Musk describes from the Raptor program (Starbase interview, 2021), in its strict order:
This skill redesigns downward, and its end is deletion. The goal is the reduction of the machine — fewer parts, held to at most today's behavior. Stripping is the primary act; regeneration is the most effective instrument of stripping we have found (it deletes parallel machinery and invented requirements wholesale, by never rebuilding them), but it is means, not end. Three rules:
refactor/<slug> (worktree when asked or conventional). One operator checkpoint — the requirements menu — then autonomous to completion. The deliverable is the branch, its metrics, and its report; merging is the operator's call.Not golf: the machine is counted in concepts, then mechanisms, then branches, then lines — in that order. Comments and whitespace are free and written at house density. A version that is smaller because the same design got denser is a failure, and the structure gate catches it mechanically.
0. ISOLATE branch refactor/<slug> from HEAD
1. BASELINE census the incumbent; the requirements menu — the ONE
operator checkpoint (stakes, probes, verdicts); build the
oracle against the ORIGINAL incumbent, pinned for the run
2. ITERATE until an iteration changes ~nothing (cap: set at the menu; default 4):
a. CENSUS recount the champion → budget numbers
b. QUESTION re-attribute machinery to the standing
verdicts (non-interactive); new nominations
and trades accumulate to the report
c. STRIP ⇄ REGENERATE — an inner loop, not a sequence:
strip until stripping stalls; regenerate
(fresh blind swe-refactor-minimizer) while design-
level work remains; strip again after any
regeneration. A strip that breaks pinned
behavior is repaired by restoring the old
part OR regenerating a minimal replacement
— whichever measures smaller. Every
candidate faces the gates; adopt iff they
pass and the machine shrank — no court
3. FINISH swe-refactor-dx, one pass: local, human-facing tidying only
4. AUTOMATE bequeath: oracle compiled into a standing conformance suite;
behavior-level tests ported; docs amended
5. REPORT per-iteration series; strips; requirements verdicts; trade
menu; side memo
Census the incumbent. Using language tooling where present (LSP document-symbols, ctags) and reading where not, inventory every declared type, function, table, and mechanism regardless of which file it hides in — foo.lang quietly implementing a Bar is exactly what this pass catches. Cluster parallel machinery (the same problem solved twice in different modules), and count the machine: concepts, mechanisms, code lines. Collection may fan out; clustering and counts run in one context over the merged inventory — a duplicate split across two shards is invisible to both.
The requirements menu — the one checkpoint. It opens with stakes, answered once and recorded verbatim: what happens if this breaks? and who maintains it, for how long? — plus the iteration cap (default 4). Stakes calibrate the whole run — how hard questioning presumes death, how deep the corpus must go, what an add-back is worth. Operator probes ride along: custom verification steps ("run make demo and check the output," "hit /health") become oracle corpus. Then the verdicts, one machinery cluster at a time:
After the menu, the run is autonomous.
The oracle. Build the differential harness for everything not relaxed: the original incumbent runs live as the reference for the entire run — every candidate in every iteration is diffed against it, never against the previous champion, so behavior cannot drift by degrees. Diff only what a user could observe: rendered frames or digests, stdout/stderr, exit codes, responses, files written, save formats — never internal state, module APIs, or call patterns. Inputs: recorded/replayed command logs, transcripts, seeded generated streams, and the operator's probes verbatim. Where the "user" is a program (a library's published API), the boundary is that API's documented surface. Keep the incumbent runnable at the base commit; localize divergences by input-prefix bisection, using the old suite as a map, not a gate.
Each iteration is one turn of the crank on the current champion (iteration 1's champion is the raw incumbent). Stop when an iteration changes approximately nothing — a thin strip and a declined or cosmetic regeneration — or at the iteration cap.
a. Census. Recount the champion. Budget numbers for this iteration; the "by iteration" row of the report.
b. Question. Re-attribute the champion's machinery to the standing verdicts — non-interactive; the menu is never reopened mid-run. Newly visible nominations and trades (stripping uncovers them) accumulate to the report for the operator's next run. The dead list persists so nothing is re-invented or re-litigated.
c. Strip ⇄ Regenerate — the inner loop. Stripping and regeneration are two moves in one game, not two stages: stripping often exposes design-level work only regeneration can do, and an aggressive strip sometimes takes a pinned behavior with it — in which case the repair is either restoring the old part or regenerating a minimal replacement for just that hole, whichever measures smaller. Restore-versus-rebuild is a gate question like everything else, not a discussion. Alternate the moves freely — strip until stripping stalls, regenerate while design-level work remains, always strip again after a regeneration lands — and end the iteration when neither move produces an adoptable candidate.
The strip move. Never regenerate what you can simply remove. Spawn swe-refactor-deleter — fresh instance, assigned stance, removal-only jurisdiction — and apply its proposals in batches, highest-confidence first. Each batch is adjudicated by the gates like any candidate: pass → dead; fail → repaired (restore or minimal rebuild, as above), no discussion. The hunt is safe from anchoring for a structural reason — anchoring poisons designers, not deleters: an examiner that may only remove makes no design decisions for the incumbent to bias. Behavior-touching finds route to the trade menu; add-shaped finds to the side memo.
Target identification is an optimizer's job, not a connoisseur's. Reachability finds only what nothing needs; the real prey is live structure that does no work, and compilers have destroyed that mechanically for decades. The deleter runs the classic pass catalog as its detectors — dead-code elimination (references, plus oracle-corpus coverage where the language has instrumentation), copy propagation (forwarding wrappers, aliases, export mirrors), inlining (fan-in-1/fan-out-1 pipe nodes), constant folding (parameters with one value across all call sites; config nothing varies), common-subexpression elimination (the census's parallel-machinery clusters), branch simplification (corpus branch coverage: arms never taken, conditions that never vary) — and cascades them to a fixpoint, because each pass unlocks the next: a folded constant decides a branch, the dead arm orphans a function, DCE takes it. We hold a looser license than any compiler — only boundary behavior is pinned — so every classic pass applies a fortiori, plus the moves no compiler may make (the guard whose input cannot occur). Judgment is spent only on the residue no detector sees. What no pass can do — dissolve a concept, change a data structure, see that three state machines are one — is the regenerate move's jurisdiction: the deleter estimates each mechanism's naive-baseline delta (the dumbest implementation meeting the stakes, versus what stands) and hands the largest gaps to regeneration as its priority list.
How a part dies — the excision protocol. A strip is an excision, not an rm, and it is performed like this:
The regenerate move. Spawn a new swe-refactor-minimizer instance — empty context, blind — with: the pinned behavior (oracle boundary, surviving requirements with sources, relaxations), the stripped champion's census numbers as budget, platform constraints, house style. Never any machine's source, tests, or history — not the original's, not the champion's; census shapes stay behind; no design, note, or rationale from any earlier iteration crosses. It designs first (a concept inventory naming its omissions checkably), then builds whole-target. Converge via add-backs: run the oracle; classify each divergence — the corpus defines behavior: a difference no realistic input can produce is a discovered kill (log it, accept it; the same law governs differences found by reading); a real divergence gets the smallest repairing add-back. Track the add-back ratio (~10% calibrated; ≫25% means a missed requirement class — recheck the verdicts; ~0% read against the structure numbers, a precise spec legitimately needs few). Then the gates. For targets too large for one context: regions with frozen boundaries, but prefer the largest region a context carries — parallel-machinery dissolution happens only inside one designer's view.
Every candidate — strip batch or regeneration — faces the same three gates. Self-reported numbers are never inputs; the orchestrator measures everything itself.
swe-correctness-reviewer on the diff. Findings resolved or the candidate is discarded. Exhaustiveness demoted to a default case, and deleted compile-time assertions, are regressions even when today's behavior matches.Gates pass and the machine shrank → adopt. Anything else → the champion stands. Neither outcome is argued, rebutted, or re-litigated; the minimizer's design note and forecasts are context for humans reading the report, not evidence before a court there isn't one.
The champion is a machine no human has yet read. Spawn swe-refactor-dx (the reader advocate) for a single finalizing pass: think-aloud plus concern spine, but remedies executed here are local only — a rename, a module header, a comment brought to house register, a file split at the ceiling, a magic value named. No structural moves, no rewrites: the machine's shape was settled by the loop. Structural findings go to the report, untaken. After the edits, run the gates once — tidying is behavior-safe by intent, not by assumption.
## Refactor Complete
### Isolation: branch refactor/<slug> @ <sha> (base <sha>)
### The machine, by iteration (0 = raw incumbent):
### concepts C0 → C1 → … → Cn | mechanisms M0 → … → Mn | code lines L0 → … → Ln
### Iterations: N run | terminated by: convergence | cap
### Per iteration: strip (proposed/applied/restored, red lines) + regeneration (adopted/declined, add-back ratio)
### Requirements: K killed (invented) / T traded / S kept — each with source
### Parallel machinery dissolved: [cluster → the one mechanism that remains]
### Oracle: N inputs, boundary [what was diffed], final state green
### Finish pass: F findings — L applied locally, R reported (structural, not taken)
### Bequest: conformance suite [location]; tests ported P, retired Q; docs amended
### Trade menu: [behavior — source — machinery it forces — what removal frees; from question + minimizer proposals]
### Side memo: [bugs and missing capabilities found and not touched — for the operator]
### Merge: the operator's call
refactor: prefix. The branch history is the run's audit trail.What SKILL.md sets; muted values are Claude Code's defaults
opusnpx claudepluginhub chrisallenlane/claude-swe-workflows --plugin claude-swe-workflows22 skills in this plugin
/bug-fixDiagnosis-first bug fixing with test-driven reproduction, root-cause analysis, and a targeted fix plus regression test. Use when the user wants to fix a bug with thorough investigation./bug-huntProactive bug hunting. Assesses where bugs likely hide, confirms each finding with a reproducing test, and iterates until nothing is found above a severity floor. Advisory by default; creates tickets or fixes via /implement only when authorized./implementImplements a ticket, a batch, or an open-ended goal end to end, choosing agents and reviews by judgment over a fixed floor (concept inventory, practical verification, green tests, correctness review). Autonomous after one planning interaction.Other plugins' skills for the same job