refactor

A refactoring command that brings existing code or project guidance back in line with agreed rules. Refactoring means improving the structure without changing the intended behavior.

In plain words
What is it for?
Use it to audit and update source code, or to shorten and align .aide guidance files with the project's brevity rules.
Why use it?
It finds drift—places where code or guidance no longer matches the project's standards—within a directory you specify.

Command for Claude Code

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/aidemd-mcp/server/refactor
Clone the repo
git clone --depth 1 https://github.com/aidemd-mcp/server

Made for: Claude Code.

Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,952 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.00000 $0.01952
Opus 5 $0.00000 $0.00976
Sonnet 5 $0.00000 $0.00390
Haiku 4.5 $0.00000 $0.00195

Measured yesterday against content hash 4eb49cfc18eb, 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.

.claude/commands/aide/refactor.md · 107 lines

How it starts

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

/aide:refactor — Refactor Phase

Agent: This command is orchestrated by the /aide orchestrator. It has two modes selected by the --specs flag — code-drift refactor (default) and spec-bloat sweep (--specs). Each mode delegates to different agents and follows a different flow.

Refactor existing artifacts to close drift from canonical contracts. The two modes target different artifact classes and use different agents:

Mode Target Drift detected against Agents
Default Source code Coding playbook + progressive disclosure aide-auditoraide-implementoraide-qa
--specs .aide files Brevity Contract aide-aligneraide-spec-writer and/or aide-strategistaide-aligner

This command requires a path argument. It does NOT perform full-app refactoring in one pass. Scope it to a directory and it will audit every .aide-defined section within that path.

Usage

/aide:refactor <path>             # code-drift refactor (default)
/aide:refactor --specs <path>     # spec-bloat sweep

Mode 1 — Code-drift refactor (default)

Audit existing code against the coding playbook and refactor to close convention drift. This is a post-QA mode — it runs on code that already works and already passed QA. The goal is conformance, not new functionality.

Flow

  1. Discover sections — run aide_discover with the given path to find all .aide specs in the subtree
  2. Audit each section — spawn one aide-auditor agent per .aide spec found. Each auditor:
    • Reads the implementation
    • Consults the coding playbook via study-playbook
    • Compares against progressive disclosure conventions
    • Produces plan.aide with refactoring steps
  3. Pause for approval — present all plans to the user. Do not proceed until approved
  4. Execute refactoring — for each approved plan.aide, delegate to aide-implementor agents (one per numbered step, same as build phase)
  5. Re-validate — delegate to aide-qa per section to verify the refactoring didn't break spec conformance

Read the full file on GitHub · 107 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 · 107 lines · 0 tokens per session scan A 4eb49cfc18eb

Subscribe to this mod's changes

refactor is a command published in the GitHub repository aidemd-mcp/server (3 stars, last pushed 3mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,952 tokens. 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.