refactor

A command that routes a refactoring request to a suitable code-analysis or code-changing workflow. Refactoring means restructuring code to improve its design without changing what it does.

In plain words
What is it for?
Use it with a file, directory, or description when you want to review or refactor code. It can recognize requests about code review, architecture, plans, and structural improvements.
Why use it?
It helps turn a broad request into the appropriate kind of review, such as checking architecture, an existing plan, or code structure. The supplied excerpt does not describe every routed workflow.

Command

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 commands/bienhoang/refactoring-kit/refactor
Clone the repo
git clone --depth 1 https://github.com/bienhoang/refactoring-kit
Per session 17 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 697 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.00017 $0.00697
Opus 5 $0.00009 $0.00349
Sonnet 5 $0.00003 $0.00139
Haiku 4.5 $0.00002 $0.00070

Measured yesterday against content hash 78d1da30ba9b, 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 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.

commands/refactor.md · 59 lines

How it starts

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

Analyze target and route to the best refactoring command: $ARGUMENTS

Decision Tree

0. Empty arguments:

  • If $ARGUMENTS is empty → Use AskUserQuestion:
    • "What would you like to refactor? Provide a file path, directory, or description."

1. Check for review intent:

  • If $ARGUMENTS contains action keywords: "review", "analyze", "audit", "scan", "assess", "inspect", "report" as standalone words (not inside file paths)
  • Or if $ARGUMENTS starts with --review/refactor:review <target> (strip the keyword, pass remaining as target)
  • Note: If target is a .md plan file AND contains a review keyword (e.g., "review my plan.md"), prefer plan routing (Step 2) — the user likely wants to execute the plan, not review it

1.5. Check for architecture intent:

  • If $ARGUMENTS contains architecture keywords: "architecture", "architectural", "arch-review", "style detection", "boundary analysis", "layer violations" as standalone words (not inside file paths)
  • Or if $ARGUMENTS starts with --architecture or --arch/refactor:architecture <target> (strip the keyword, pass remaining as target)

2. Check for existing plan:

  • If $ARGUMENTS is a path to a .md plan file → /refactor:implement <path>
  • If active refactoring plan exists in ./plans/ matching "refactor" → /refactor:implement

3. Route by scope:

A) Single File (target is a file path like src/utils.ts, lib/helpers.js) → /refactor:fast <target>

B) Small Scope (target mentions specific function, class, or method) → /refactor:fast <target>

C) Multi-file list or glob patterns (e.g., src/*.ts, file1.js file2.js) → /refactor:plan <target>

D) Directory / Module (target is a directory like src/services/, lib/) → /refactor:plan <target>

E) Large Scope (keywords: system, module, large, entire, whole, codebase) → /refactor:plan <target>

F) Ambiguous (cannot determine scope from arguments) → Use AskUserQuestion with options:

  • "/refactor:review — Read-only analysis report"
  • "/refactor:architecture — Architectural style & smell analysis"
  • "/refactor:fast — Quick autonomous refactoring"
  • "/refactor:plan — Brainstorm & plan first"
  • "/refactor:implement — Execute with review-then-apply"

Read the full file on GitHub · 59 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. yesterday First seen · 59 lines · 17 tokens per session scan A 78d1da30ba9b

Subscribe to this mod's changes

refactor is a command published in the GitHub repository bienhoang/refactoring-kit (4 stars, last pushed 6mo ago), licensed MIT. It adds 17 tokens to every session and 697 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.