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.
npx agentmods add commands/halflength-ampleness75/claude-code-recipes/refactorgit clone --depth 1 https://github.com/halflength-ampleness75/claude-code-recipesWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/commands/halflength-ampleness75/claude-code-recipes/refactor)<a href="https://agentmods.dev/commands/halflength-ampleness75/claude-code-recipes/refactor"><img src="https://agentmods.dev/badge/commands/halflength-ampleness75/claude-code-recipes/refactor.svg" alt="Measured on agentmods" height="20"></a>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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00014 | $0.00762 |
| Opus 5 | $0.00007 | $0.00381 |
| Sonnet 5 | $0.00003 | $0.00152 |
| Haiku 4.5 | $0.00001 | $0.00076 |
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 3d 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.
How it starts
The opening of the file, as written. The whole thing — 80 lines — stays where its author put it; the contents beside it link to each section on GitHub.
You are a senior software engineer performing a structured refactoring. The user will describe what they want refactored via $ARGUMENTS (a file, function, module, or pattern).
Phase 1 — Understand the Target
- Locate the code the user wants refactored. Use glob and grep to find relevant files.
- Read the target code and all direct dependents (callers, importers, subclasses).
- Check for existing tests that cover the target code.
- Map out the dependency graph: what does this code depend on, and what depends on it?
Produce a brief summary:
- Target: file(s) and function(s)/class(es) being refactored
- Dependents: list of files/modules that import or call the target
- Test coverage: which tests exist, what they cover
- Current issues: why refactoring is needed (complexity, duplication, coupling, naming, etc.)
Phase 2 — Propose a Refactoring Plan
Propose a numbered plan. Each step should be a single, atomic change. Common refactoring patterns to consider:
- Extract Function/Method — pull a block into its own function
- Inline Function — replace a trivial wrapper with its body
- Rename — improve naming for clarity
- Move — relocate to a more appropriate module
- Extract Interface/Type — decouple via an abstraction
- Replace Conditional with Polymorphism — simplify complex switch/if chains
- Introduce Parameter Object — group related parameters
- Remove Dead Code — delete unreachable or unused code
- Decompose Module — split a large file into focused modules
For each step, state:
- What changes
- Which files are affected
- Why it improves the code
Present the plan and ask the user to confirm before proceeding. Wait for their response.
Phase 3 — Execute the Refactoring
After the user confirms, implement the plan step by step:
- Make one atomic change at a time.
- After each change, verify the code is syntactically valid. If a build command is available (check
package.jsonscripts,Makefile,Cargo.toml, etc.), run it. - Keep all existing tests passing throughout. Run the test suite after each significant step.
- Update imports, references, and type signatures in all dependent files.
- Update any documentation or comments that reference renamed/moved entities.
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.
- 3d ago First seen · 80 lines · 14 tokens per session scan A 03d29110e39e
refactor is a command published in the GitHub repository halflength-ampleness75/claude-code-recipes (2 stars, last pushed 4d ago), licensed MIT. It adds 14 tokens to every session and 762 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-31.
Other commands, from other repositories
coograph-verify
Verify that the described work is complete and correct. Provide evidence for every claim. You verify — you do not implement or fix style.
prune
Trim transcript clutter to extend session lifetime — analyze, prune a copy, or toggle the after-each-turn service. Dry-run by default; gains land at resume/compaction, not the current turn.
add-dep
Vet a new or changed third-party dependency for license, provenance, and supply-chain risk before any install runs.
conflict
Stop everything and surface a rule conflict — persona vs. docs vs. code. Present both sides and the conflict-hierarchy level; the user resolves. No silent reconciliation.
status
Show the project's current state at a glance — stage, open tasks, open questions, overrides since the last checkpoint, current branch. Read-only.
commit
Run the full commit gate — the only sanctioned path to a git commit.