refactor-surgical

refactor-surgical is a command for Claude Code from orlando-japan/claude-code-setting. It costs 14 tokens per session (381 once invoked), scanned A, original, MIT.

A command for restructuring code while keeping its observable behavior unchanged. It requires tests to pass before and after each small change.

In plain words
What is it for?
Use it to move, extract, or rename internal code in small verified steps without changing public interfaces or intended behavior.
Why use it?
It limits refactoring to internal organization and makes regressions easier to detect. The step-by-step process also helps prevent scope creep and accidental feature changes.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/orlando-japan/claude-code-setting/refactor-surgical
Clone the repo
git clone --depth 1 https://github.com/orlando-japan/claude-code-setting

Made for: Claude Code.

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-surgical

README.md
[![agentmods](https://agentmods.dev/badge/commands/orlando-japan/claude-code-setting/refactor-surgical.svg)](https://agentmods.dev/commands/orlando-japan/claude-code-setting/refactor-surgical)
Your own site
<a href="https://agentmods.dev/commands/orlando-japan/claude-code-setting/refactor-surgical"><img src="https://agentmods.dev/badge/commands/orlando-japan/claude-code-setting/refactor-surgical.svg" alt="Measured on agentmods" height="20"></a>
Per session 14 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 381 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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.00014 $0.00381
Opus 5 $0.00007 $0.00191
Sonnet 5 $0.00003 $0.00076
Haiku 4.5 $0.00001 $0.00038

Measured 5d ago against content hash a8d1420186c0, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

refactor-surgical 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 5d ago.

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.

templates/claude-user/commands/refactor-surgical.md · 27 lines

What it actually says

Refactor: $ARGUMENTS

The contract: behavior before == behavior after. Only internal structure changes.

Protocol:

  1. Run the existing tests first. Green baseline. If they're not green, stop and fix them first — a refactor on red is a rewrite.
  2. List the refactor in ≤5 bullets before touching code: what's moving, what's renaming, what's extracting. If the list grows beyond 5, you're doing too much — split it.
  3. One step at a time. Make one refactor, run tests, commit. Make the next, run tests, commit. Don't batch.
  4. Don't change public interfaces. If you must, it's not a refactor — it's a migration, and it needs a spec.
  5. Don't rename things "while you're in there." Renames are cheap with tooling and expensive with ad-hoc edits. If they're worth doing, they're worth doing in their own commit.
  6. Don't introduce new abstractions. The purpose is to clean up what exists, not to speculate about the future.

Stop conditions:

  • Tests go red → stop, revert, diagnose.
  • Scope creep detected → stop, surface to user, ask.
  • You discover the original code was wrong (not just ugly) → stop, surface the bug, don't silently fix it in the refactor.

Done looks like: same tests green, diff is smaller and clearer than before, no new public API.

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. 5d ago First seen · 27 lines · 14 tokens per session scan A a8d1420186c0

Subscribe to this mod's changes

refactor-surgical is a command published in the GitHub repository orlando-japan/claude-code-setting (2 stars, last pushed 3mo ago), licensed MIT. It adds 14 tokens to every session and 381 once invoked, about $0.0001 per session on Opus 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-31.