refactor-surgical

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

A method for restructuring code while keeping its observable behavior unchanged.

In plain words
What is it for?
Use it for covered renames, function extraction, function inlining, and moving code between files or classes, with tests after each step.
Why use it?
It reduces the risk that cleanup work quietly changes how the software works.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it for covered renames, function extraction, function inlining, and moving code between files or classes, with tests after each step.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/orlando-japan/claude-code-setting/refactor-surgical
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.

Any agent
npx skills add orlando-japan/claude-code-setting --skill refactor-surgical
Clone the repo
git clone --depth 1 https://github.com/orlando-japan/claude-code-setting

Made for: Claude Code, Codex.

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/skills/orlando-japan/claude-code-setting/refactor-surgical/github.svg)](https://agentmods.dev/skills/orlando-japan/claude-code-setting/refactor-surgical)
Your own site
<a href="https://agentmods.dev/skills/orlando-japan/claude-code-setting/refactor-surgical"><img src="https://agentmods.dev/badge/skills/orlando-japan/claude-code-setting/refactor-surgical/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-surgical

Your own site · 80×15
<a href="https://agentmods.dev/skills/orlando-japan/claude-code-setting/refactor-surgical"><img src="https://agentmods.dev/badge/skills/orlando-japan/claude-code-setting/refactor-surgical.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 25 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 633 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.00025 $0.00633
Opus 5 $0.00013 $0.00316
Sonnet 5 $0.00005 $0.00127
Haiku 4.5 $0.00003 $0.00063

Measured 8d ago against content hash cf1d26e3caff, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, 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 8d 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/extra/skills/refactor-surgical/SKILL.md · 63 lines

How it starts

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

Surgical refactor

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

Pre-flight

  1. Tests must be green. A refactor on red isn't a refactor — it's a rewrite.
  2. There must be enough test coverage that tests would catch a behavior change. If coverage is thin, write characterization tests first, then refactor.
  3. You must have a concrete reason. "Cleaner" is not a reason. "Duplicated in 4 places, next change needs to happen in 5" is a reason.

The protocol

  1. List the refactor in ≤5 steps before touching code.
  2. Execute one step.
  3. Run tests. They must still pass.
  4. Commit.
  5. Next step.

If step 2 turns into "and also…", stop — you're scope-creeping. Split into another refactor.

Safe refactors (tooling handles these)

  • Rename. IDE rename, not search-and-replace.
  • Extract function. Select the code, extract, run tests.
  • Inline function. When a function has one caller and adds nothing.
  • Move symbol. Between files, between classes.

These are almost always safe if tests cover the behavior.

Risky refactors (do carefully)

  • Change a public API. This isn't a refactor, it's a migration. Needs a spec and callers updated.
  • Change data structures. Tests catch behavior, not performance or memory shape. Profile before and after.
  • Change concurrency model. Tests rarely cover race conditions. Think hard.
  • Remove abstraction. Removing an indirection can reveal behavior that depended on it.

Never refactors

  • "Fix a bug while refactoring." Refactor is behavior-preserving. Bug fixes change behavior. Separate them.
  • "Clean up while adding a feature." Feature and cleanup in one PR = unreviewable. Split.
  • "Rename while restructuring." Rename first, restructure second. Each on its own commit.

Stop conditions

  • Tests go red → revert the last step, diagnose, redo.
  • You discover the original code was wrong, not just ugly → stop. Surface the bug separately.
  • You need to touch public API → stop. This is a migration.
  • Scope creep detected → stop. Commit what you have, start a new refactor.

Read the full file on GitHub · 63 lines

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. 8d ago First seen · 63 lines · 25 tokens per session scan A cf1d26e3caff

Subscribe to this mod's changes

refactor-surgical is a skill published in the GitHub repository orlando-japan/claude-code-setting (2 stars, last pushed 3mo ago), licensed MIT. It adds 25 tokens to every session and 633 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.

Related

Other skills, from other repositories

coding

Use when five specialized coding agents (linter, perf, refactor, security, test) that enforce quality gates across the development lifecycle. From lint enforcement through performance profiling, refactoring, security auditing, and test coverage. Use when working with coding agents.

oyi77/1ai-skills · 54 tokens

receiving-code-review

Use when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation.

obra/superpowers · 38 tokens

requesting-code-review

Use when completing tasks, implementing major features, or before merging to verify work meets requirements.

obra/superpowers · 22 tokens

claude_code_delegation

Delegate coding, review, and refactor tasks to Claude Code CLI through Row-Bot's approval-gated shell workflow.

siddsachar/row-bot · 31 tokens

chimera

Use this skill for post-session code quality review of files added or modified during a WrongStack session. It runs automatically when a session ends, and on demand. Trigger on the explicit vocabulary — "review", "code review", "quality check", "post-session review", "chimeric review", "chimera" — and on the task…

WrongStack/WrongStack · 182 tokens

auto-review

Use this skill to configure and understand the built-in auto-review plugin (wstack-auto-review) that fires automated code review subagents on every code change during a session. Triggers: user says "auto review", "otomatik review", "auto code review", "her değişiklikte review", "/auto-review".

WrongStack/WrongStack · 67 tokens