/code:refactorfrom code
Plans and executes behavior-preserving structural changes like decomposing functions, splitting modules, and breaking import cycles. Requires explicit approval before each move.
Ships in code. 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.
Refactor changes the structure of working code; it does not change behavior.
It differs from simplify by risk rather than size: simplify applies edits whose behavior preservation is verifiable on the spot, and refactor takes the edits that are not — the ones that move contracts, cross module boundaries, or touch files far from where the request started.
Those need a plan the user rules on before anything lands, because the resulting diff is too large to review after the fact.
Every move is approved individually and executed on its own, with verification green between moves.
simplify: duplication, dead code, comment noise, local de-nesting.code-review: correctness, security, test adequacy, merge readiness.refactor.
Skip the notice when the user asked for the skill by name or slash command; spelling and spacing need not match.
A phrase from this skill's own trigger list is not a name — naming the work is not naming the skill.A proposal comes from one of three sources. Use whichever the request provides:
simplify-*.md or refactor-*.md in the location project instructions set, .review/, ._scratch/, .scratch/ at the repo root, or $TMPDIR.
Its Deferred section is the work list; each entry carries a proposed move, blast radius, and verification plan.
If no ledger exists, say so and ask what to work on.
A ledger written to $TMPDIR in another session or harness may not be visible here; ask for its path.simplify pass first usually shrinks the job, because dead code and duplication are cheaper to delete than to carry into a new structure.
If the user declines, proceed.The ledger format lives in the simplify skill's references/edit-ledger.md; read it when consuming or writing one.
If that file is not available, the sections are simple enough to mirror from any existing ledger: Applied, Removed, Deferred, Skipped.
Find the repo's checks and establish the strongest available check:
Run the baseline before any edit. If the suite is red, stop; without a green start, no later failure is attributable. Record the check, the command, and the result — and the starting commit, which Phase 3's scope check needs.
Look for a spec source: an openspec/ or specs/ tree, or artifacts from the sdd family.
Structural change must leave the code compliant.
If a move cannot preserve compliance, record it and stop.
Suggested spec revisions go in the ledger, and this skill never applies them.
If the code-review-graph MCP plugin is available, call build_or_update_graph_tool() then list_graph_stats_tool().
If either call fails or the graph is empty, continue on the git-only path and do not retry.
See references/code-review-graph-integration.md for per-phase use.
The graph matters more here than in a review, because blast radius is what the plan is built from. Without it, establish the same facts by grep: every caller, importer, subclass, and test of what you are about to move — and every textual reference: strings, config keys, fixtures, serialized data.
Produce a plan before touching anything.
For each move, follow the procedure in references/structural-moves.md and record these fields:
| Field | What to record |
|---|---|
| Move | Which structural operation, on what |
| Preconditions | What must be true for the move to preserve behavior |
| Blast radius | Files touched, callers updated, tests affected, public surface changed |
| Test impact | Which tests must change, and why each is coupled to structure and not behavior |
| Verification | What proves behavior is unchanged, beyond a passing suite |
| Order | The sequence that leaves verification green between moves |
Count the blast radius; do not estimate it.
Split anything large into the smallest moves that each leave the tree green. One 900-line move is not a plan the user can rule on.
State what you are not doing. Do not widen the plan after approval. The user approved what you presented, not a larger version of it.
Present the plan and stop.
The user approves moves individually, not the plan wholesale. They will often want two of six. Note declined moves in the ledger so the record shows they were considered.
Approval of a move covers the test changes its Test impact field enumerated; do not re-ask for those during execution.
Do not begin executing while asking.
Take one approved move at a time, in the planned order.
For each move:
If a test edit surfaces that the approved plan did not enumerate, stop and get agreement first, stating three things:
| State | What it means |
|---|---|
| What changed | The specific assertion, and what it asserted |
| Why it was coupled | What made it depend on structure and not on behavior |
| Why behavior is stable | What else proves the observable contract holds, now that this test no longer does |
A test edit that cannot supply all three is a behavior change, not a refactor. Revert it and say so.
If the blast radius exceeds the plan, stop and re-plan. Discovering three more call sites mid-move means the user approved a plan that was wrong.
If the work came from a ledger, append an outcome block under each executed entry: what changed, files touched, verification result, anything discovered.
Note declined proposals.
Add new Deferred entries for structural work this pass surfaced but did not do.
If the work came from chat or a review report, write a fresh ledger for the pass instead (same format), named refactor-<YYYY-MM-DD-HHMMSS>-<scope-slug>.md.
Pick its destination in this order:
.review/, ._scratch/, or .scratch/ that already exists at the repo root.$TMPDIR.Never create those repo directories; they belong to the user. If the write fails, put the ledger in chat and say no file was written.
Rationale goes in the ledger, not the code. Do not leave comments narrating the restructuring.
Ledger IDs are ephemeral. T3 addresses an entry in one file.
It never appears in source, comments, commit messages, or PR descriptions.
Then report: moves executed, moves declined, net file and line movement, final verification result, ledger path, and what remains deferred.
references/structural-moves.md — the move catalog: preconditions, procedure, and verification for each operation.references/code-review-graph-integration.md — graph tool dispatch for blast-radius analysis and post-move verification.simplify skill, references/edit-ledger.md — the ledger format this skill consumes and appends to.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub ahgraber/skills --plugin codeOther plugins' skills for the same job
10 skills in this plugin
/api-designUse when designing, reviewing, or planning REST or GraphQL APIs — endpoint structure, schema design, versioning, error handling, pagination, URI naming, or choosing between REST and GraphQL. Also triggers for OpenAPI spec creation and API contract review./changelogUse when writing, updating, or generating a CHANGELOG.md — for a new release, an unreleased section update, or drafting from git history or diff. Triggers: "update the changelog", "write release notes", "what changed since X", "generate changelog for v1.2.0", "add this to the changelog", "draft unreleased section". Not for commit messages (use commit-message skill) or internal deployment runbooks./code-reviewUse when reviewing code changes before committing or merging — staged diffs, branch diffs, or PR readiness checks. Triggers: 'review my code', 'check these changes', 'review this branch', 'give feedback on my diff', 'is this PR ready?'. Not for implementing features, running test suites, formatting-only passes, or building understanding of a change (use teach-me).