refactor

A guided code-refactoring workflow that uses repository evidence to find structural improvements worth making while preserving behavior.

In plain words
What is it for?
Use it to survey a codebase for worthwhile refactoring targets, then safely carry out a selected change.
Why use it?
It helps avoid spending time cleaning code that rarely changes or adding unnecessary design patterns. It also keeps refactoring from 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/duthaho/skillhub/refactor
Any agent
npx skills add duthaho/skillhub --skill refactor
Clone the repo
git clone --depth 1 https://github.com/duthaho/skillhub

Made for: Claude Code, Codex.

Per session 166 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,965 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.00166 $0.01965
Opus 5 $0.00083 $0.00983
Sonnet 5 $0.00033 $0.00393
Haiku 4.5 $0.00017 $0.00197

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

.claude/skills/refactor/SKILL.md · 163 lines

How it starts

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

refactor — earn it first, then preserve behavior

/refactor — survey the repo, emit a brief of where improvement pays off /refactor <target or goal> — execute one candidate, safely

Answer one question: where does structural improvement actually pay for itself in this codebase — and how is that change made without changing behavior? The skill exists to prevent the two documented failure modes of "improve the architecture": refactoring the wrong code (most ugly code is never touched again, so cleaning it returns nothing), and pattern-itis — applying design patterns because they're best practices rather than because a problem here demands them, turning straight-line code into abstraction lasagna.

Survey mode — /refactor

Step 1 — Evidence, not aesthetics

Candidates come from signals, never from "this code looks bad":

  • Hotspots — churn × complexity. Churn from git itself: git log --format= --name-only --since="12 months ago" | sort | uniq -c | sort -rn | head -30, crossed with a complexity proxy (file length, indentation depth). Code that is both complex and frequently edited is where interest compounds; complex-but-cold code is a LEAVE by default.
  • The bug logout/dev/bugfix-log.md if present. A file that shows up repeatedly is structural debt announcing itself.
  • Upcoming work — the user's stated goals, open specs and plans under out/dev/. These seed PREP candidates: make the change easy, then make the easy change — preparatory refactoring is the highest-payoff kind because the payoff is scheduled, not hoped for.
  • The mapAGENTS.md gotchas and conventions; a documented gotcha is often a workaround for structure that could stop needing one.
  • Memoryout/refactor/tracker.md if it exists: verdicts already made. A LEAVE with a reason isn't re-litigated unless its evidence changed; repeat surveys open with "Since last survey".

Step 2 — Verdicts, with the pattern gate

For each candidate: REFACTOR / PREP / LEAVE / WATCH.

Read the full file on GitHub · 163 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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 · 163 lines · 166 tokens per session scan A eb33f09f5693

Subscribe to this mod's changes

refactor is a skill published in the GitHub repository duthaho/skillhub (9 stars, last pushed 9d ago), licensed MIT. It adds 166 tokens to every session and 1,965 once invoked, about $0.0008 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.