refactor

A code-cleanup process that changes the internal structure of code without changing what the program does. It uses tests to record current behaviour and check each small change.

In plain words
What is it for?
Use it to split up long code, remove duplication, rename unclear parts, or move logic into a more suitable layer.
Why use it?
It makes code easier to understand, test, and maintain while reducing the chance that cleanup introduces a bug.

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

Made for: Claude Code, Codex.

Per session 46 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 526 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.00046 $0.00526
Opus 5 $0.00023 $0.00263
Sonnet 5 $0.00009 $0.00105
Haiku 4.5 $0.00005 $0.00053

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

skills/development/refactor/SKILL.md · 68 lines

What it actually says

Refactor Skill

Improve the code structure without changing external behavior.

Step 1 — Understand the Goal

Ask or infer:

  • What is wrong with the current code? (too long, duplicated, wrong layer, hard to test)
  • What is the desired outcome? (extracted function, renamed variable, moved to correct layer)
  • Are there tests in place? (if not, write characterization tests before refactoring)

Step 2 — Establish a Safety Net

Before changing anything, verify tests exist that cover the code being refactored. If tests are missing, write characterization tests first:

  • A characterization test captures current behavior (even if the behavior is wrong).
  • It prevents accidental behavior changes during refactoring.

Step 3 — Apply Refactoring in Small Steps

Work in small, safe increments. After each step, verify tests still pass:

Common refactoring moves:

  • Extract function/method: identify a coherent chunk of logic with a clear purpose.
  • Rename: choose a name that accurately describes the thing at the current abstraction level.
  • Move to correct layer: domain logic in a controller → move to use case or domain service.
  • Replace conditional with polymorphism: complex switch/if chains on type → strategy pattern.
  • Introduce value object: raw primitive used to represent a domain concept → wrap it.
  • Remove duplication: extract shared logic to a shared function; do not abstract prematurely.

Step 4 — Verify Behavior is Unchanged

After refactoring:

  • All tests pass.
  • The public API (exported signatures) is unchanged.
  • No new dependencies introduced.

Step 5 — Summarize

## Refactor Summary

**What changed**: [List of moves applied]
**Why**: [The design problem that was addressed]
**Tests**: [Pass / added N new characterization tests]
**Breaking changes**: None (internal only)
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 · 68 lines · 46 tokens per session scan A 1e8e7a9ce836

Subscribe to this mod's changes

refactor is a skill published in the GitHub repository soulcodex/agentic (10 stars, last pushed 2d ago), licensed MIT. It adds 46 tokens to every session and 526 once invoked, about $0.0002 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

improve-codebase-architecture

Use when surfacing architectural friction inside a single EVOKORE bounded context and proposing deepening refactors (shallow modules, leaky seams, low locality) that turn shallow modules into deep ones — informed by ADR-0005 bounded contexts and the project's domain language.

mattmre/EVOKORE-MCP-PUBLIC · 61 tokens

research-repository

Build a repository that makes findings findable, reusable, and cumulative across teams. Use when the same research keeps getting redone. For synthesising one study, use affinity-diagram.

Owl-Listener/designer-skills · 43 tokens

survey-design

Design unbiased survey instruments — question wording, scales, and sampling — to measure attitudes at scale. Use when you need quantitative breadth. For behavioural experiments, use a-b-test-design (prototyping-testing).

Owl-Listener/designer-skills · 47 tokens

localization-design

Design for multiple languages, writing directions, and cultural contexts — text expansion, RTL mirroring, and locale formats. Use when shipping beyond one locale. For the words themselves, use ux-writing (designer-toolkit).

Owl-Listener/designer-skills · 49 tokens

design-negotiation

Advocate for design quality, scope, and timeline with partners and leadership using evidence and shared goals. Use in the conversation itself. For the commercial vocabulary behind it, use business-design (ux-strategy).

Owl-Listener/designer-skills · 48 tokens

design-debt-audit

Inventory and prioritise accumulated design inconsistencies across a product. Use when drift has built up over time. For token coverage specifically use design-token-audit (designer-toolkit); for WCAG gaps use accessibility-audit (design-systems).

Owl-Listener/designer-skills · 59 tokens