refactoring

A guide to refactoring, which means changing code structure without changing what the program does. It emphasizes small steps, preserved interfaces, and the project’s architectural layers.

In plain words
What is it for?
Use it when extracting functions, splitting large files, renaming code, removing duplication, or reducing complexity before a feature change.
Why use it?
It reduces the risk of breaking existing behavior while improving names, file structure, readability, or duplicated code.

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

Made for: Claude Code, Codex.

Per session 26 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 750 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.00026 $0.00750
Opus 5 $0.00013 $0.00375
Sonnet 5 $0.00005 $0.00150
Haiku 4.5 $0.00003 $0.00075

Measured 2d ago against content hash 1c7df088788e, 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.

.claude/skills/refactoring/SKILL.md · 86 lines

How it starts

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

Skill: Refactoring

Purpose

Change the shape of code without changing its behavior, safely and in small steps, while preserving the project's layers and public contracts.

When to Use This Skill

  • Improving structure, naming, or readability of existing code.
  • Extracting a function/module, splitting a large file, or removing duplication.
  • Preparing code for a feature by reshaping it first.
  • Reducing complexity flagged during code/architecture review.

Files to Read First

  • AGENTS.md (boundaries and "no large uncontrolled rewrites").
  • .ai/skills/architecture-review.md (invariants you must preserve).
  • The tests covering the code you intend to change.
  • Any doc/ADR describing the contracts the code implements.

Core Principles

  • Preserve public behavior. A refactor changes structure, not observable behavior or contracts.
  • Tests first for risky changes. If coverage is thin, add characterization tests before refactoring.
  • Small steps. Many tiny, verified changes beat one big rewrite.
  • Stay in scope. Do not refactor unrelated code you happen to pass by.
  • Don't collapse layers for convenience, and don't introduce circular dependencies.
  • Rename concepts deliberately. Update docs/ADRs/tests when a name changes.
  • Prefer simple extraction over introducing complex patterns.

Process

  1. Define the goal and boundary. State exactly what improves and which files are in scope.
  2. Ensure a safety net. Confirm or add tests that pin current behavior.
  3. Refactor in small steps, running make test after each meaningful step.
  4. Keep layers intact. Verify the change respects architecture invariants.
  5. Update names everywhere. If a concept is renamed, fix code, tests, and docs in the same change.
  6. Keep commits logically scoped (one refactor idea per commit).
  7. Final validation. Run make check; diff should be structure-only.

Read the full file on GitHub · 86 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 · 86 lines · 26 tokens per session scan A 1c7df088788e

Subscribe to this mod's changes

refactoring is a skill published in the GitHub repository extra-org/extra (108 stars, last pushed 4d ago), licensed MIT. It adds 26 tokens to every session and 750 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-30.