Best for
- Use when the user wants to refactor, restructure, clean up, simplify, or improve the design of existing code, or to apply refactoring recommendations from a code-review or architectural-analysis report.
testdouble/han/han-coding/skills/refactor/SKILL.md
Restructure existing code without changing its behavior, through a test-gated refactoring loop: a named target, a green suite over that target before any edit, a planned sequence of small named refactorings, and the full suite re-run after every step. Use when the user wants to refactor, restructure, clean up, simplify, or improve the design of existing code, or to apply refactoring recommendations from a code-review or architectural-analysis report. This skill changes code; it does not review c
Decision brief
As your first action, use the Read tool on .han/config.md inside the personal config directory path above. A read that returns no file is no personal configuration: continue silently. When that file or the project .han/config.md probe supplies content, apply it per config-rule.m…
Compatibility matrix
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Not declared | No explicit evidence | Portability before use |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/testdouble/han --skill "han-coding/skills/refactor"Inspect the Agent Skill "refactor" from https://github.com/testdouble/han/blob/a86259a348dd0ec8a04b0357dd33753a36f38c2d/han-coding/skills/refactor/SKILL.md at commit a86259a348dd0ec8a04b0357dd33753a36f38c2d. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
Bind the target. Resolve the request to a named target: specific files or directories, a named code smell in a named place, or the refactoring findings in a provided document (a /code-review report, an /architectural-analysis report, or equivalent). When a findings document is g…
Check the tree. If working tree in Project Context shows failing mid-cycle work or the user describes an in-flight tdd loop on this code, stop and say why (the never-alongside-tdd constraint). Uncommitted but complete work is fine; recommend committing it first so refactoring di…
Plan the whole run before the first edit. Produce a numbered refactoring plan where each item is:
Take the plan items in order. For each:
Run the full test suite, the lint command, and the build command from Step 1. Paste the summary line from each. If lint or build fails on code this skill touched, fix it and re-run; that is in scope.
Permission review
The documentation asks the agent to read local files, directories, or repositories.
open-ended ("clean up the codebase", "improve quality") with no named target, ask the user for one before doingThe documentation asks the agent to run terminal commands or scripts.
*Run the full suite.** Run the resolved test command with Bash. **Paste the runner's summary line.** If anything isThe documentation asks the agent to run terminal commands or scripts.
Run the full test suite, the lint command, and the build command from Step 1. **Paste the summary line from each.** IfEvidence record
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 92/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 229 | Source | Repository attention, not individual Skill quality |
| Compatibility | 0 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
which git 2>/dev/null || echo "not installed"git branch --show-current 2>/dev/null || echo unknowngit status --porcelain 2>/dev/null | head -5find . -maxdepth 1 -name "CLAUDE.md" -type ffind . -maxdepth 3 -name "project-discovery.md" -type fbash "${CLAUDE_PLUGIN_ROOT}/scripts/han-config-dir.sh" 2>/dev/null || echo "$HOME/.claude"cat .han/config.md 2>/dev/null || echo ""As your first action, use the Read tool on .han/config.md inside the personal config directory path above. A read
that returns no file is no personal configuration: continue silently. When that file or the project .han/config.md
probe supplies content, apply it per config-rule.md, which governs precedence
between the two files, relative-path resolution, and what to do with a file that reads but cannot be used.
This skill restructures existing production and test code in your working tree. It is an execution skill, not a document generator. These constraints shape every step and override any instinct to move faster. The canon they derive from, with provenance, is in references/refactoring-discipline.md; pull that reference when a step needs the full rule or a step feels off.
/tdd owns cleanup inside the loop, and restructuring
while a test is red violates the two-hats rule both skills share.Bind the target. Resolve the request to a named target: specific files or directories, a named code smell in a named
place, or the refactoring findings in a provided document (a /code-review report, an /architectural-analysis report,
or equivalent). When a findings document is given, extract only the refactoring-shaped findings (structural suggestions,
duplication, naming, coupling) and record each finding's ID so the summary can trace back to it. If the request is
open-ended ("clean up the codebase", "improve quality") with no named target, ask the user for one before doing
anything: open-ended refactoring runs are the documented failure mode this skill exists to avoid, and a wrong guess here
burns the whole run.
Resolve commands. Read CLAUDE.md's ## Project Discovery section for the test command (under
### Commands and Tests), the lint command, the build command, language, and framework. If absent, fall back to
project-discovery.md. If still absent, run ${CLAUDE_SKILL_DIR}/scripts/detect-refactor-context.sh and parse its
output for git state and manifest-inferred commands. A missing test command is a hard blocker: exhaust inference, then
ask the user, because this skill cannot run without a way to verify behavior. Also note any type-check command the
project has; where one exists it runs alongside the tests as a second behavior-preservation check.
Resolve standards and decisions. Resolve the coding-standards directory and ADR directory the same way: CLAUDE.md's
## Project Discovery section, then project-discovery.md, then Glob defaults (docs/, docs/adr/,
docs/coding-standards/, docs/decisions/). Also check CLAUDE.md and AGENTS.md for inline standards. Read the
standards and ADRs whose titles, paths, or one-line summaries indicate they govern the target area; cap at five
documents. The target's restructured form must conform to these. If none exist, state that plainly and infer conventions
from the surrounding code.
Check the tree. If working tree in Project Context shows failing mid-cycle work or the user describes an in-flight
tdd loop on this code, stop and say why (the never-alongside-tdd constraint). Uncommitted but complete work is fine;
recommend committing it first so refactoring diffs stay clean, then proceed.
Run the full suite. Run the resolved test command with Bash. Paste the runner's summary line. If anything is
red, stop: a red suite is not a license to refactor. Report the failures and recommend fixing them first (via
/investigate or /tdd), or re-scoping the target away from the broken area.
Establish coverage of the target. Confirm the target's observable behavior is exercised by the suite: find the tests that drive the target (Glob and Grep for the target's public symbols in test files), and run them scoped if the runner supports it. State plainly which behaviors are covered and which are not. If the target has no meaningful coverage, stop and offer two ways forward, and wait for the user's choice: narrow the target to the covered part, or write characterization tests first using the protocol in references/refactoring-discipline.md. Characterization tests pin current observed behavior (including current bugs) and are a lower-confidence net than intent-written tests; say so in the report.
Plan the whole run before the first edit. Produce a numbered refactoring plan where each item is:
Order the plan so each step leaves the code releasable: small, independent steps first, dependent steps after the steps they need. Report the plan to the user, then continue immediately; this is a report, not a gate. The one exception: if the request explicitly asks to review or approve the plan first, wait for approval.
Take the plan items in order. For each:
Make the one change. Apply the single named refactoring, touching only the files in its declared blast radius. Stay in the refactoring hat: no behavior fixes, no extras spotted along the way (record them for the summary instead).
Run the full suite (and the type-check command where one was resolved). Paste the runner's summary line. Paste full output only when something fails or looks unexpected.
Green: cross the item off and move to the next.
Running collaboratively. When the request asks to review each named refactoring as it lands, which is what
pairing does when it hands work here, stop at this point and hand control back instead of continuing. Present the
stop in the shape collaborative-stop-rule.md specifies. Absent such a
request, continue as below; an ordinary invocation is unchanged.
Red: revert this step. When git is available and the tree was clean at start, git checkout/git restore the
touched files. When git is absent, or the tree was already dirty at start, undo the edits directly instead, so
reverting this step does not discard the user's other work. Do not patch forward over a red suite; a failed step
means the mechanic was unsafe or the coverage was thinner than it looked. Diagnose, then either retry with a smaller
step or defer the item with what you learned.
Stop rules. If the step needed files outside its declared blast radius, or the only way to make it work changes observable behavior, or two consecutive plan items have been reverted: stop, report where things stand (everything already applied is green and stands), and let the user re-scope.
If the user asked for commits, commit after each green step or each logical group of green steps, message naming the refactoring applied, refactoring only.
Run the full test suite, the lint command, and the build command from Step 1. Paste the summary line from each. If lint or build fails on code this skill touched, fix it and re-run; that is in scope.
Summarize for the user:
/issue-triage or the next
/code-review.Frequently asked questions
As your first action, use the Read tool on .han/config.md inside the personal config directory path above. A read that returns no file is no personal configuration: continue silently. When that file or the project .han/config.md probe supplies content, apply it per config-rule.m…
The source record exposes this install command: npx skills add https://github.com/testdouble/han --skill "han-coding/skills/refactor". Inspect the command and pinned source before running it.
Static rules flagged read-files, exec-script in the source; the page lists the matching lines and excerpts.
Alternatives
mgiovani/cc-arsenal
Restructures existing code without changing its behavior: maps callers and test coverage, adds characterization tests where coverage is thin, then applies the change in small steps verified against the full test suite after each one. Use when the user wants to refactor, extract a method or class, simplify logic, reduce duplication, improve naming, restructure modules, or pay down technical debt in code that already works. Not for adding new functionality (use implement-feature) or fixing broken
coreyhaines31/marketingskills
When the user wants to plan, design, or implement an A/B test or experiment, or build a growth experimentation program. Also use when the user mentions "A/B test," "split test," "experiment," "test this change," "variant copy," "multivariate test," "hypothesis," "should I test this," "which version is better," "test two versions," "statistical significance," "how long should I run this test," "growth experiments," "experiment velocity," "experiment backlog," "ICE score," "experimentation program
narrative-io/narrative-skills-marketplace
Translate a fuzzy analytical question into a rigorous investigation plan. Interrogates the ask, grounds the plan in the available data dictionary, applies analytical best practices, and produces a structured brief of query specifications for a downstream query-writing skill. Plans, does not write SQL. Use when: "why did X drop", "is there a relationship between A and B", "who are our highest-value customers", "what's driving the change in Y", "investigate this trend", "design an analysis for", "
Aperivue/medsci-skills
Interactive sample size calculator for medical research. Decision-tree guided test selection, reproducible R/Python code, effect size interpretation, and IRB-ready justification text. Supports diagnostic accuracy, agreement, proportions, continuous outcomes, survival, ANOVA, logistic regression, and non-inferiority/equivalence designs.