refactoring

A guide for changing the structure of code while keeping its observable behavior the same. Refactoring means improving code shape without intentionally changing its results or public interface.

In plain words
What is it for?
Adding tests that capture current behavior, making small behavior-preserving code changes, and checking the relevant test suite after each step.
Why use it?
It provides a safer way to simplify difficult code, reduce duplication, and make future changes easier while tests check for accidental behavior changes.

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/duyet/oma/refactoring
Any agent
npx skills add duyet/oma --skill refactoring
Clone the repo
git clone --depth 1 https://github.com/duyet/oma

Made for: Claude Code, Codex.

Per session 82 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 918 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.00082 $0.00918
Opus 5 $0.00041 $0.00459
Sonnet 5 $0.00016 $0.00184
Haiku 4.5 $0.00008 $0.00092

Measured 2d ago against content hash e8c7aa635d30, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refactoring 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 2d 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.

examples/skills/refactoring/SKILL.md · 76 lines

How it starts

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

refactoring

Refactoring changes the shape of code without changing what it does. The entire point is that behavior stays identical — if a "refactor" changes an output, a fixed bug, or a public interface, it isn't a refactor anymore, it's a feature change wearing a refactor's name, and it needs to be reviewed and tested as one.

A safety net comes first

  • Tests must exist and pass before you start. If the code you're touching has no tests, write characterization tests first — tests that pin down its current behavior (including its current bugs, if any) so you have a ground truth to refactor against.
  • Run the full relevant test suite before starting, so you know your baseline is green, and after every step, so a regression is caught the moment it's introduced rather than three steps later when it's hard to trace.
  • If behavior turns out to be ambiguous or buggy while refactoring, don't fix it inline — note it and fix it as a separate, explicitly-labeled change.

Small, reversible steps

  • Each step should be a single mechanical move (see the catalog below) that leaves the code in a working, still-green state. If you can't describe the step in one sentence, it's too big — split it.
  • Commit after each green step. A refactor that's several small commits is easy to review and easy to git revert one step of if something breaks later; one giant "refactor everything" commit is neither.
  • Prefer the smallest change that gets you to the next clean state over the "ideal" end structure in one leap — you can always take the next step.

Common moves

  • Extract function/variable — name a chunk of logic or a magic value so intent is visible without re-deriving it.
  • Inline — the reverse: remove a needless indirection that adds a hop without adding clarity.
  • Rename — the cheapest, highest-leverage refactor there is. A correct name removes the need for a comment explaining what the old name didn't say.
  • Replace conditional with guard clause / early return — flatten nested ifs so the common case reads top-to-bottom instead of buried three levels deep.
  • Remove duplication — but only once you've seen the pattern three times (rule of three). Abstracting after one or two occurrences usually guesses the wrong abstraction and costs more to unwind later than the duplication did.
  • Replace conditional with polymorphism/strategy — when a type-switch or long if/else chain keeps growing a new branch per feature; skip this if there are only two cases and none are coming.

Read the full file on GitHub · 76 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. 2d ago First seen · 76 lines · 82 tokens per session scan A e8c7aa635d30

Subscribe to this mod's changes

refactoring is a skill published in the GitHub repository duyet/oma (5 stars, last pushed 13d ago), licensed Apache-2.0. It adds 82 tokens to every session and 918 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-31.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

next-cache-components-adoption

Turn on Cache Components in a Next.js app and resolve the blocking routes it surfaces. Use when the user wants to enable, adopt, or migrate to Cache Components, flip the cacheComponents flag, work through a flood of blocking-prerender / instant validation errors, run the cache-components-instant-false codemod, or…

vercel/next.js · 95 tokens

babysit-pr

Babysit a GitHub pull request after creation by continuously polling review comments, CI checks/workflow runs, and mergeability state until the PR is merged/closed or user help is required. Diagnose failures, retry likely flaky failures up to 3 times, auto-fix/push branch-related issues when appropriate, and keep…

openai/codex · 114 tokens

imagegen

Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output…

openai/codex · 113 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens

next-cache-components-optimizer

Drive a Next.js route to instant navigation by setting up an agentic loop, under Cache Components / PPR, on initial load (hard navigation) and client-side navigation (soft navigation). Encode the goal as a failing @next/playwright instant() e2e and work it to green, one verified route at a time; the shipped test then…

vercel/next.js · 170 tokens