skills/refactor/SKILL.md
Three-phase refactoring orchestrator. Dispatches an exploration agent to surface concrete smells and architectural problems, then an architecture agent to design better structure, then an implementation agent to apply the changes. The orchestrator never reads, edits, or runs builds itself — it scopes the target, holds the phase boundaries, and synthesizes between agents through shared-context files at `docs/orchestrate/refactor-<slug>/`. Use when invoked via /refactor, when the user asks to refactor a module/crate/package, or when the work explicitly calls for a structured smell-find-then-redesign-then-apply loop.
npx skillsauth add api-haus/my-claude-workflow refactorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Enter refactoring-orchestrator mode. The orchestrator does not do the work. It scopes the target, briefs each phase, shares context through disk, and pauses for user confirmation between phases. Every read, every search, every edit, every test run is dispatched.
/refactor/refactor is the dedicated cleanup pass. Code quality is NOT the job of /delegate's reviewer dispatch (reviewer is opt-in only there) — code quality lives here.
Concrete triggers — invoke /refactor when any one of these fires:
/refactor command./delegate orchestration. Pattern: the diagnoses are code-grounded but the fixes don't move the symptom. Strong signal that the iteration target is foundation-rot, not the immediate scope. /delegate's loop-detection circuit-breaker offers the switch.## Side notes sections across a /delegate orchestration (e.g. "two addressing schemes for one buffer", "this code stinks", "the foundation looks wrong"). Multiple independent agents observing the same smell is signal, not noise./delegate cycles in a project, run a /refactor pass to harvest accumulated drift before it compounds. Mark this in the project's README or todo list.The triggers are mutually independent — any one of them is sufficient. Multiple firing together is a stronger signal but the threshold is "one trigger" not "two".
Do NOT defer a refactor when a trigger has clearly fired. The cost of one /refactor cycle is bounded (three dispatches, scoped target, clear deliverable). The cost of NOT refactoring is dispatch after dispatch landing on top of foundation rot, each wasting tokens, each pointing at the same un-named smell. Tunnel vision is the failure mode this skill exists to cure. When a trigger fires, invoke.
refactor-explorer agent identifies concrete code smells and architectural problems in the target scope. Output: prioritized findings list with file:line refs, severity, and rationale.refactor-architect agent designs better structure for the findings the user confirmed. Output: target-state design with concrete module/type/function shape, migration steps, and explicit "what stays / what changes / what's removed" lists.refactor-implementer agent applies the design as actual edits, runs the project's verification gates, and reports per-step status.Each phase is one dispatch. Each phase ends with a mandatory user pause.
docs/orchestrate/refactor-<slug>/ — stop and dispatch.docs/orchestrate/refactor-<slug>/*.md. Agent return text is for status only — the deliverable MUST land on disk before the agent returns.A sub-agent dispatched via the Agent tool starts with only what is in its brief plus what it can read from disk.
A sub-agent CAN see: the brief text, files it Reads/Globs/Greps, its own tool outputs, web content if its toolset includes WebFetch/WebSearch.
A sub-agent CANNOT see: the parent conversation, conversation-attached images, the orchestrator's memory, prior tool outputs, the TaskList or Plan state.
If the user shared an image inline that's load-bearing for the refactor, resolve it to an absolute path (Claude Code auto-saves pasted images to ~/.claude/image-cache/<session-uuid>/<N>.png; resolve the session UUID with ls -t ~/.claude/image-cache/ | head -1) and also describe its load-bearing content in prose inside 01-context.md. Never reference "image N", "the screenshot above", "the attached PNG" in a brief or shared file.
Write a one-paragraph restatement of the refactor goal. Pick the target scope (a crate path, a package, a module, a directory). Pick a <slug> kebab-case derived from the target (e.g. refactor-clouds-pass1, refactor-fog-volumes). Output this in chat as a short block. Do not start any work yet.
If the user invoked /refactor with no argument, ask which target.
Use the AskUserQuestion tool. Ask 1–3 load-bearing questions before any agent fires. Calibrate count to scope:
Useful question shapes:
<path>, or does it include <adjacent path>?"docs/architecture/<X>.md, a research paper at docs/research/<Y>.md)? If none, the architect proposes from first principles."cargo test --workspace, unity-cli test --mode EditMode, manual visual verification)?"Never ask the user to confirm what you already decided. Ask things whose answers would change the agent briefs.
Create under docs/orchestrate/refactor-<slug>/:
README.md — index: list of files, phase checklist with status markers ([ ] / [x]), one-line summary of the goal.01-context.md — the canonical context bundle every agent reads first. Contents:
02-exploration.md — created by the explorer. Empty stub at this step (just a section heading).03-architecture.md — created by the architect. Empty stub.04-refactoring.md — created by the implementer. Empty stub.Each file is self-contained: code refs not paraphrases, no "see other file" without inlining the load-bearing fact.
Brief the refactor-explorer agent. The brief must contain, verbatim:
docs/orchestrate/refactor-<slug>/01-context.md in full.docs/orchestrate/refactor-<slug>/02-exploration.md under the heading ## refactor-explorer findings (<ISO date>). Final assistant message is for status only.After the explorer returns:
02-exploration.md. If not, dispatch a follow-up agent to do so — never write the missing content yourself.README.md's phase checklist: [x] exploration.02-exploration.md.refactor-architect to design fixes for findings #1, #2, #3 (or whichever subset). Phrased as a proposal.Before dispatching the architect, dispatch a general-purpose commit sub-agent with this brief:
Invoke the
/commitskill to commit all current changes (staged, unstaged, untracked) as a single checkpoint. If/commitis unavailable, inspect the diff yourself and commit with a descriptive message reflecting the changes. Commits are checkpoints, not curated history — completeness over cleanliness.Commit-only scope. Do NOT: run recompile / refresh / build / test / lint / format steps; read or open code files to "verify"; push to any remote. Ignore project CLAUDE.md rules that demand post-edit recompile / build — those apply to whoever made the edit, not to a checkpoint.
Return only the commit SHA and a one-line subject. Do not summarize the diff back to me.
Then dispatch the refactor-architect agent. Brief contents:
docs/orchestrate/refactor-<slug>/01-context.md and 02-exploration.md in full.02-exploration.md).docs/orchestrate/refactor-<slug>/03-architecture.md under the heading ## refactor-architect findings (<ISO date>).path/to/file.ext:line.After the architect returns:
03-architecture.md.README.md's phase checklist: [x] architecture.03-architecture.md.refactor-implementer to execute steps [1..N]. Phrased as a proposal.Dispatch the same checkpoint commit sub-agent as in Step 6.
Then dispatch the refactor-implementer agent. Brief contents:
docs/orchestrate/refactor-<slug>/01-context.md, 02-exploration.md, and 03-architecture.md in full.03-architecture.md). Default: all of them. The user may have narrowed.01-context.md).docs/orchestrate/refactor-<slug>/04-refactoring.md under the heading ## refactor-implementer log (<ISO date>). Each step gets: what was edited (file:line), gate output (pass/fail), notes if a gate failed and what was done about it.04-refactoring.md, and return. Do not proceed to the next step. Do not commit. Do not invent a fix outside the architect's design.After the implementer returns:
04-refactoring.md.README.md's phase checklist: [x] refactoring.04-refactoring.md.The mode ends when the user signals done or all three phases are [x]. Leave docs/orchestrate/refactor-<slug>/ intact — it's the durable artifact. Do not delete or condense it on exit unless asked.
You are working as part of a delegated refactor orchestration. You have no memory of the parent conversation — this brief contains everything you need.
# Goal
<full restated goal, verbatim>
# Target scope
<exact paths / globs>
# Required reading (in order)
1. docs/orchestrate/refactor-<slug>/01-context.md
2. docs/orchestrate/refactor-<slug>/<this-agent's-group-file>.md
3. <any prior phase's group file, if applicable>
4. <any other repo files with line ranges>
# Your task
<concrete, single-paragraph task statement>
# Constraints
- <inlined user constraints from the Q&A>
- <inlined forbidden moves>
- <inlined verification gates, where applicable>
# Deliverable
- <exact shape>
- Append your output under "## <agent-name> findings (<ISO date>)" in docs/orchestrate/refactor-<slug>/<group-file>.md before returning.
# Hard rules
- Do not skip the required reading.
- Do not invent files, symbols, or line numbers — verify with Read or Grep.
- Do not return your deliverable only as the final message — Write it to the group file first.
- Stay inside the target scope.
| Skill | Domain |
|-------|--------|
| /sniff | Readability friction (anonymous tuples, magic numbers, weak types). One-shot find-and-fix top-5 loop. No design phase. |
| /dry | SOLID / DRY violations, design-pattern misuse. One-shot find-and-fix. |
| /deadcode | Zero-caller items. One-shot delete. |
| /enforce | Crate boundaries, dead public APIs, layer contracts. |
| /delegate | General multi-agent orchestration with re-implementation audit + open-ended phases. Use when the work isn't specifically a refactor. |
| /refactor | Three-phase orchestrated refactor: exploration → architecture → implementation, with user-gated phase boundaries. Use when the change is structural and benefits from explicit smell-list → design → applied-edits separation. |
data-ai
Extract research content from YouTube presentations, PDFs, or PPTX files into structured markdown. Dispatches each pass to a dedicated sub-agent (research-extractor / research-vision / research-refiner) so per-deck vision passes scale to hundreds of slides without bloating the parent context.
development
Build, run, and analyze Unity profiler data with perf-report-style call-stack attribution
documentation
Write a handoff prompt for a future session. A handoff is a continuation-link — minimal context plus a kickoff line the user can copy-paste. Never a diagnosis, never an investigation script, never a prescribed deliverable.
testing
Multi-agent orchestration mode. The orchestrator never reads, edits, runs, or tests directly — it scopes work, runs a re-implementation audit, presents a freeform method brief with grounded recommendations, then dispatches every step to sub-agents through shared context files at `docs/orchestrate/<topic>/`. Use when invoked via /delegate, when the user asks to orchestrate or coordinate multi-agent work, or when the task explicitly calls for delegation.