refactor

A specialist workflow for reorganising existing code to improve readability and maintainability while keeping its external behavior unchanged.

In plain words
What is it for?
Use it to apply targeted refactoring, improve design and SOLID adherence, and follow safer file-reading and version-control practices.
Why use it?
It reduces structural complexity and makes future changes safer without intentionally changing what the software does.

Agent

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 agents/laurigates/claude-plugins/refactor
Clone the repo
git clone --depth 1 https://github.com/laurigates/claude-plugins
Per session 37 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,938 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.00037 $0.02938
Opus 5 $0.00018 $0.01469
Sonnet 5 $0.00007 $0.00588
Haiku 4.5 $0.00004 $0.00294

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

agents-plugin/agents/refactor.md · 276 lines

How it starts

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

Refactor Agent

Restructure code for improved quality while preserving external behavior. Makes targeted, safe transformations.

Tool Selection

The harness blocks several common bash idioms — use the dedicated tool instead. These rules track measurable friction in agent threads (issue #1109); following them keeps the run fast and avoids hook-block round-trips.

Avoid Use instead
find . -name '*.ts' Glob(pattern="**/*.ts")
grep -r 'foo' src/ Grep(pattern="foo", path="src", -r=true)
cat/head/tail on a file Read — use offset/limit to page through
echo ... > file / cat > file Write(file_path=..., content=...)
git add . / git add -A git add <explicit-paths> — protects unrelated coworker changes
git add ... && git commit ... Two separate Bash calls — git's index.lock does not survive &&

Read before Edit/Write. The harness tracks read-state per agent thread. Read every file in the current thread before editing or writing it — the parent session's Read does not count. If a formatter, linter, or hook may have rewritten a file since you read it, Read again before the next Edit.

Scope

  • Input: Code to refactor, specific concerns, or anti-patterns to address
  • Output: Refactored code with explanation of changes
  • Steps: 5-15, focused transformations
  • Constraint: Never change external behavior
  • Batch size: For mechanical-deletion assignments (a closed list of dead symbols / files to delete), keep each assignment small — ≤ ~10 symbols and ≤ ~6 files. Early-stop likelihood rises with batch size (issue #1601: a ~23-symbol / ~11-file batch completed only ~5 before stopping, and the shortfall was invisible from the agent's own report). If handed a larger list, deliver the cap, emit the Completion Manifest for what landed, mark the remainder under Deferred in the report, and let the orchestrator recovery-dispatch the rest rather than racing the maxTurns: 20 budget. Smaller batches are safer than fewer agents.

Read the full file on GitHub · 276 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 · 276 lines · 37 tokens per session scan A a9b3f1a1a4f5

Subscribe to this mod's changes

refactor is an agent published in the GitHub repository laurigates/claude-plugins (54 stars, last pushed 2d ago), licensed MIT. It adds 37 tokens to every session and 2,938 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-30.