refactor

refactor is a skill for Claude Code, Codex from genai-io/san. It costs 84 tokens per session (651 once invoked), scanned A, original, Apache-2.0.

A refactoring workflow for changing code structure without changing what the program does. Refactoring can include extracting, renaming, splitting, or deduplicating code.

In plain words
What is it for?
Adding characterization tests when needed, then safely reorganizing existing code in small steps while keeping its behavior fixed.
Why use it?
It reduces the risk of accidental behavior changes by requiring tests to pass before and after each structural change.

Skill for Claude CodeCodex

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 skills/genai-io/san/refactor
Any agent
npx skills add genai-io/san --skill refactor
Clone the repo
git clone --depth 1 https://github.com/genai-io/san

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/genai-io/san/refactor.svg)](https://agentmods.dev/skills/genai-io/san/refactor)
Your own site
<a href="https://agentmods.dev/skills/genai-io/san/refactor"><img src="https://agentmods.dev/badge/skills/genai-io/san/refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 84 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 651 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 $0.00084 $0.00651
Opus 5 $0.00042 $0.00326
Sonnet 5 $0.00017 $0.00130
Haiku 4.5 $0.00008 $0.00065

Measured 4d ago against content hash 103cd98082dc, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 4d 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.

.san/personas/software-engineer/skills/refactor/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.

Refactor: restructure without changing behavior

A refactor changes the shape of code, never what it does. The one rule that makes it safe: behavior is pinned by tests before you touch anything, and the same tests stay green after. If behavior needs to change, that is not a refactor — stop and treat it as a feature or a fix.

Phase 1: Pin the behavior

Before restructuring, make the current behavior observable and guarded.

  1. Find the tests that cover the code you intend to move. Run them and confirm they pass. This green run is your baseline — write it down.
  2. If the code is not covered, add characterization tests first: tests that capture what the code does today (not what it should do), enough to catch a behavior change. Get them green against the current code before you refactor.
  3. If you cannot get the behavior under test at all, say so and stop — an unguarded refactor is a rewrite in disguise, and you would have no way to know you broke something.

Phase 2: Restructure in small steps

Make one structural move at a time, and keep the tests green between moves.

  • Each step is a single transformation — extract a function, rename a symbol, inline a variable, split a file, unify duplicated blocks — not a pile of them.
  • Run the tests after each step. If they go red, the last step changed behavior; undo it and make a smaller move.
  • Change structure only. No new parameters "while you're in there", no bug fixes, no renamed behavior. If you spot a bug, note it for a separate code-review pass — do not fix it inside the refactor.
  • Match the conventions already in the code; a refactor should look like it was always there.

Phase 3: Verify behavior is unchanged

  • Run the full test suite. It must be as green as your Phase 1 baseline — same tests passing, none skipped to get there.
  • Confirm the public interface callers depend on is unchanged, or if it changed, that every call site was updated in the same pass.
  • The diff should contain only structural change. Every hunk traces to the restructuring goal; if a hunk changes behavior, it does not belong here.

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. 4d ago First seen · 63 lines · 84 tokens per session scan A 103cd98082dc

Subscribe to this mod's changes

refactor is a skill published in the GitHub repository genai-io/san (76 stars, last pushed yesterday), licensed Apache-2.0. It adds 84 tokens to every session and 651 once invoked, about $0.0004 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-30.

Related

Other skills, from other repositories