refactor-module

A guide for restructuring code while keeping its behavior unchanged; this process is called refactoring.

In plain words
What is it for?
Use it to extract functions, split files, rename code, reduce duplication, preserve public interfaces, and verify the result with tests and linting.
Why use it?
It provides a controlled way to improve code organization and readability without accidentally changing what the software does.

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

Made for: Claude Code, Codex.

Per session 63 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 474 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.00063 $0.00474
Opus 5 $0.00032 $0.00237
Sonnet 5 $0.00013 $0.00095
Haiku 4.5 $0.00006 $0.00047

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

Security

Grade A, and why

refactor-module 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 yesterday.

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.

runner/skills/refactor-module/SKILL.md · 37 lines

What it actually says

Refactor a module

A refactor changes structure, not behaviour. The contract: tests are green before you start and green after, with no scope creep into new features or fixes.

Steps

  1. Establish the safety net. Run the suite first (run-tests) and confirm it's green. If the module under refactor is thinly tested, add characterization tests (the add-unit-test skill) that pin the current behaviour before you touch anything.
  2. Read the lore. Call search_lore (Memory MCP) for the repo's module boundaries, layering, and naming conventions so the new structure fits the codebase.
  3. Refactor in small, behaviour-preserving steps — extract, rename, move, dedupe — re-running tests after each step. Keep the public interface stable unless the ticket explicitly allows changing it; update call sites if you do.
  4. Change no behaviour. No new features, no bug fixes, no dependency changes riding along. If you spot a real bug, note it for a separate ticket — don't fix it here.
  5. Confirm green after. Run the full suite and lint (run-tests, run-lint) and confirm identical behaviour and no new failures.
  6. Evidence: before/after passing summaries (proving behaviour preserved) and a diff_summary. Then use the record-evidence skill and submit for review.

Rules

  • Behaviour-preserving only: tests green before and after, same outcomes.
  • No scope creep — no features, fixes, or dependency bumps in a refactor ticket.
  • Keep the public interface stable unless the AC says otherwise.
  • If you uncover a bug, log it separately; don't fix it inside the refactor.
  • Run on a branch (the create-branch skill), never a protected branch.
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. yesterday First seen · 37 lines · 63 tokens per session scan A a0d748c0f5f7

Subscribe to this mod's changes

refactor-module is a skill published in the GitHub repository tmj-90/gaffer (2 stars, last pushed 7d ago), licensed Apache-2.0. It adds 63 tokens to every session and 474 once invoked, about $0.0003 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.