/supermatt:refactor [method, file, path, or 'the changes on this branch since <ref>']from SuperMatt
Refactors code at method, file, or project scope. Assesses whether refactoring is warranted first, stops if code is already clean, and gates edits on test coverage. Language-agnostic.
Ships in SuperMatt. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Improve code structure without changing behavior. Works at three scopes: project, file, or method. Starts by assessing whether refactoring is even warranted: if the code is already clean, say so and stop.
Refactoring vs architecture: this skill handles code-level improvements: complexity, duplication, naming, dead code, method extraction. If the assessment shows that the real problem is module boundaries, coupling between packages, or shallow modules that need deepening, say so. That is an architecture problem this skill won't fix: tell the user to run /improve-architecture in Claude linked installs or Cursor, /supermatt:improve-architecture from the Claude plugin, $improve-architecture in Codex, or /skill:improve-architecture in OMP.
These principles calibrate what "good enough" means and guide every step below:
Read a reference only when the assessment actually turns on it:
SIMPLICITY-VS-EASY.md: when the choice is between a familiar approach and a simpler oneDATA-OVER-ABSTRACTIONS.md: when custom types could be plain data structuresDESIGN-IS-TAKING-APART.md: when a coupled system needs decomposingEXPENSIVE-TO-ADD-LATER.md: when deciding whether something missing is worth adding nowInfer from the user's request:
| Trigger | Scope |
|---|---|
| "refactor this method/function" or a specific symbol name | method |
| "refactor this file" or a file path | file |
| "refactor this project/codebase" or no specific target | project |
"The changes on this branch since <ref>" is file scope over each file in git diff --name-only <ref>...HEAD, judged on the changed code. If the scope is still ambiguous, ask the user, with the three scopes as the options.
This step is mandatory. Read the target code and evaluate it against the criteria below. The default verdict is Clean: only escalate when there's clear evidence.
All method-level checks, plus:
All file-level checks, plus:
A whole codebase always offers more findings than are worth acting on. Read HOTSPOTS.md and rank by change frequency crossed with complexity before listing anything. It decides what to look at first, not what is wrong.
Read the ranked candidates through subagents, one per area, each returning findings rather than file contents. A project-scope assessment reads far more code than it reports on, and most of it comes back Clean. Step 4 reads what it actually edits. A project under about 1,000 source lines is the exception: read it directly, a few files per call, so each output stays under the 30,000-character limit that moves a result to a file.
Before you list any finding, read each issue the target's commits reference, with its comments, through the Read an issue operation in docs/agents/issue-tracker.md. Drop a finding that a comment already settled, such as a user's answer to the same question during implement, and name that comment in the verdict.
A finding that removes an indirection (a function where a value would do, a parameter, a hook, a seam) can take out what the next planned change needs. Before you list one, also read the open children of those issues' parent issue. Drop a finding that a planned issue needs, and name that issue in the verdict.
| Rating | Meaning | Action |
|---|---|---|
| Clean | No meaningful improvements available | Tell the user the code looks good and end the run there. Stop here unless they provide a specific reason to continue. An item worth offering the user makes the verdict Minor. |
| Minor | Small improvements possible (naming, minor duplication) | List findings. Recommend applying them or leaving the code as is, give the deciding reason, then ask. These are optional. |
| Significant | Clear code smells or structural issues | List findings with priorities. Proceed to Step 3. |
| Critical | Major structural problems blocking maintainability | List findings urgently. Proceed to Step 3. |
Idempotency rule: if you run this skill on the same code twice and it's already been refactored, the verdict must be Clean.
User override: if the user provides a specific reason to refactor code rated Clean (e.g., "I know it looks fine but I want to extract this into smaller functions"), proceed with their request, but scope the changes strictly to what they asked for. Don't expand into a broader refactoring.
Architecture signal: if the assessment shows problems that are really about module boundaries (tightly coupled packages, shallow modules, missing abstractions at the architectural level), say so: refactoring code inside a badly-bounded module won't fix the real problem. Tell the user to run /improve-architecture in Claude linked installs or Cursor, /supermatt:improve-architecture from the Claude plugin, $improve-architecture in Codex, or /skill:improve-architecture in OMP.
For method scope, skip to Step 3.5. Planning is unnecessary for single-symbol changes, but the test gate still applies.
Enter plan mode, where the host has one, before planning, so no file changes while the plan is drafted. If the request is too ambiguous to plan safely, ask rather than start.
For file scope with 1-3 changes, a bullet list is sufficient:
Changes:
- Extract X into helper function
- Remove unused imports
- Rename Y to describe intent
For file scope with 4+ changes or project scope, produce a structured plan:
## Refactor Plan: [title]
### Current State
[What's wrong and why it matters]
### Target State
[What the code looks like after: fewer lines, fewer concepts, clearer boundaries]
### Changes
| File | Action | Why | Blocked by |
|------|--------|-----|------------|
| path | modify/create/delete | reason | dependencies |
### Sequence
Phase 1: [contracts/types/interfaces if applicable]
Phase 2: [implementation changes]
Phase 3: [callers]
Phase 4: [test updates, mechanical renames and moves only]
Phase 5: [cleanup, delete dead code]
Verify after each phase: [command]
Final validation: [command that must pass before this is done]
### Rollback
For the riskiest phase: [how to undo it]
### Risks
- [What could go wrong and how to mitigate]
Key principle: the target state should have less or equal total code. If your plan adds net lines without removing complexity, reconsider. "Better organized but more code" is not a win: it's more entropy.
Present the plan through the host's native approval mechanism when exposed, otherwise in chat. Proceed only after explicit approval.
Before changing any code, check that tests exist for the target:
tdd skill through the host's skill mechanism and use its characterization tests in their own test: commit.Judge coverage over the code you are about to change, not over the repository. A repo at 85% overall tells you nothing if the target sits in the untested 15%.
This gate is especially important for code with business logic (calculations, validation rules, state transitions, money). Structural code (routing, configuration, glue) is lower-risk without tests, but still worth flagging.
Do not skip this step. Refactoring means "change structure, preserve behavior", and you can only guarantee "preserve behavior" if there are tests to prove it.
<baseline>. Any characterization tests from Step 3.5 must already be committed.refactor:, and never mix structural and behavioral change in one commit: a move and an optimization are two commits even though both are structural.Apply whichever are relevant. Do not apply moves that don't improve the specific code.
When one move repeats across more than a handful of sites, read MECHANICAL-SWEEPS.md before editing by hand.
Reduce complexity:
Eliminate duplication:
Improve clarity:
Reduce entropy:
"Less code" is the measure, not the goal. Reject a transformation that wins on line count and loses on reading:
When refactoring a specific method for complexity:
After refactoring:
git diff --name-only <baseline> includes committed, staged, and unstaged changes. Characterization tests committed in Step 3.5 are already in the baseline; subsequent changes to them belong in that list and follow the same frozen-test rule. If an existing test file was modified beyond a rename or a move, stop and say so: the behavioral contract was rewritten to match the new code, which hides exactly the failure this step exists to catch.CREDITS.md (opens in a new tab)DATA-OVER-ABSTRACTIONS.md (opens in a new tab)DESIGN-IS-TAKING-APART.md (opens in a new tab)EXPENSIVE-TO-ADD-LATER.md (opens in a new tab)HOTSPOTS.md (opens in a new tab)MECHANICAL-SWEEPS.md (opens in a new tab)NOTICE (opens in a new tab)SIMPLICITY-VS-EASY.md (opens in a new tab)agents/openai.yaml (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
42 skills in this plugin
/ask-supermattAsk which skill or flow fits your situation. A router over the skills in this repo./babysit-prWatch a pull request until it is ready to merge: open it when the branch has none, handle review feedback before CI, recover CI within a bounded budget, keep the branch current, and stop without merging./codebase-designShared vocabulary for designing deep modules. Use when designing interfaces, data contracts, state transitions, shared mutable state, or retryable effects; deepening a module; choosing test seams; or consulting the deep-module vocabulary./code-reviewReview the changes since a fixed point (commit, branch, tag, or merge-base) along three axes: Standards (does the code follow this repo's documented coding standards?), Spec (does the code match what the originating issue/spec asked for?), and Adversarial (how does the change fail in production?). Runs each axis in an independent host reader and applies the repository external-peer policy. Use when the user wants to review a branch, a PR, work-in-progress changes, or asks to "review since X"./commitCommit all changes on the current branch, main included./dependency-vettingVerify a package or tool is authentic before installing, adding, upgrading, or recommending it. Use whenever a task would add a dependency to a project, suggest a CLI tool, or pull a package from npm, PyPI, crates.io, Go modules, RubyGems, Homebrew, or any other registry. Also use when a registry page, install command, or installed artifact looks inconsistent with the project that supposedly publishes it.npx claudepluginhub svyatov/supermatt --plugin supermattOther plugins' skills for the same job