refactor

refactor is a skill for Claude Code from testdouble/han. It costs 203 tokens per session (2,867 once invoked), scanned A, original, MIT.

A workflow for reorganizing existing code while keeping its behavior unchanged. It uses tests before and after each small refactoring, meaning a code-structure change that should not alter what the software does.

In plain words
What is it for?
It helps break a refactor into named steps, check the target with tests, make small structural improvements, and verify the full test suite afterward.
Why use it?
It reduces the risk that cleanup introduces bugs by requiring the relevant tests to pass before editing and after every change.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: mentions CLAUDE.md; mentions AGENTS.md.

Runs only inside its plugin — its command needs a path that Claude Code sets for a plugin’s own hooks and for nothing else. Install the plugin, not this.

Part of the han-coding plugin — 11 skills shipped together

Good fit It helps break a refactor into named steps, check the target with tests, make small structural improvements, and verify the full test suite afterward.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

This one installs as part of its plugin. Adding the marketplace and installing the plugin brings it with everything else the plugin ships.

Claude Code
/plugin marketplace add testdouble/han
Claude Code
/plugin install han-coding

Made for: Claude Code.

Or install han-coding, the plugin that ships this one along with the rest of its 11 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refactor

README.md
[![agentmods](https://agentmods.dev/badge/skills/testdouble/han/refactor/github.svg)](https://agentmods.dev/skills/testdouble/han/refactor)
Your own site
<a href="https://agentmods.dev/skills/testdouble/han/refactor"><img src="https://agentmods.dev/badge/skills/testdouble/han/refactor/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for refactor

Your own site · 80×15
<a href="https://agentmods.dev/skills/testdouble/han/refactor"><img src="https://agentmods.dev/badge/skills/testdouble/han/refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 203 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,867 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00203 $0.02867
Opus 5.5 $0.00081 $0.01147
Sonnet 5.5 $0.00041 $0.00573
Haiku 4.5 $0.00020 $0.00287

Measured 1mo ago against content hash e8a08c677f38, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

refactor scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/detect-refactor-context.sh), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

han-coding/skills/refactor/SKILL.md · 170 lines

How it starts

The opening of the file, as written. The whole thing — 170 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Project Context

  • git installed: !which git 2>/dev/null || echo "not installed"
  • current branch: !git branch --show-current 2>/dev/null || echo unknown
  • working tree: !git status --porcelain 2>/dev/null | head -5
  • CLAUDE.md: !find . -maxdepth 1 -name "CLAUDE.md" -type f
  • project-discovery.md: !find . -maxdepth 3 -name "project-discovery.md" -type f
  • personal config directory: !bash "${CLAUDE_PLUGIN_ROOT}/scripts/han-config-dir.sh" 2>/dev/null || echo "$HOME/.claude"
  • project .han/config.md: !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.

Constraints (read before anything else)

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.

  • Behavior preservation is the definition. A refactoring changes internal structure without changing observable behavior. A change that alters behavior is not a refactoring done badly; it is not a refactoring at all. When a planned step turns out to require a behavior change, it leaves this skill's scope: defer it with a note naming the behavior change it needs.
  • Tests are the license to refactor. No edit until the full suite has been run, observed green, and the target's behavior is covered. If coverage of the target cannot be established, stop and offer the characterization path in the reference; never refactor blind.
  • Small named steps, green to green. Each step is one named refactoring with a bounded mechanic (extract function, rename, move, inline, and so on), and the suite runs after every step. A red suite after a step means revert the step, not patch forward.
  • The declared scope is a contract. The target named in Step 1 bounds every edit. When a step starts pulling in files outside that scope, stop, report the spread, and let the user re-scope. Spreading edits are how a refactoring silently becomes a rewrite.
  • Never alongside an active tdd loop. If the working tree shows a red-green cycle in flight (failing tests, a half-implemented behavior), do not run: the refactor step of /tdd owns cleanup inside the loop, and restructuring while a test is red violates the two-hats rule both skills share.
  • Refactor-only changes. No behavior fixes, no features, no drive-by bug fixes, even when you spot one. Record what you found and leave it. If the user asks for commits, each commit contains refactoring only.
  • YAGNI governs the plan. Apply ../../references/yagni-rule.md: every refactoring in the plan needs evidence the code has a reason to change (a review finding, named duplication, a confusing read documented by the user, upcoming work in that area). Removing duplication is the job; adding speculative abstraction, configuration, or indirection is not. Defer evidence-free items with a reopen trigger.

Read the full file on GitHub · 170 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago Changed · +1 lines · +27 tokens per session e8a08c677f38
  2. 1mo ago First seen · 169 lines · 176 tokens per session scan A 1a70f7aa8c63

Subscribe to this mod's changes

refactor is a skill published in the GitHub repository testdouble/han (304 stars, last pushed today), licensed MIT. It adds 203 tokens to every session and 2,867 once invoked, about $0.0008 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

codex-loop

Fix Elixir/Phoenix code until Codex CLI review comes back clean — bounded review, fix, verify loop before opening a PR. Use when codex is installed and you want an external cross-model critic on your changes before pushing.

oliver-kriska/claude-elixir-phoenix · 52 tokens

codex-ab

Run an A/B codex review experiment — holistic codex review vs 3 focused dimension passes (security, ecto, liveview) on the branch diff, classify findings, report a panel-value verdict. Use when the branch is fresh, before any codex review runs.

oliver-kriska/claude-elixir-phoenix · 60 tokens

implement

Implement a ticket or feature with proportional planning, test first behavior changes, independent review when available, and verification through the real affected surface.

curie-eng/curie · 29 tokens

code-standards

Apply a disciplined engineering workflow to any code change. Use whenever implementing a feature, fixing a bug, or refactoring — before writing code, not after. Walks orient → baseline → smallest change → test → verify → self-review, and enforces language-agnostic hard gates (don't mass-reformat, keep the linter and…

tamdogood/builder-essential-skills · 94 tokens

verify-multispec

A verification workflow for major releases or large code refactors. It uses four specialist teammates to review the change, question each other’s findings, and then shut down cleanly.

easyinplay/harnessed · 196 tokens

daa-review

Use when reviewing existing test code for DAA compliance, identifying anti-patterns, or suggesting improvements to automation test architecture.

gigayaya/DAA-Master · 26 tokens