server: Command for Claude Code

.claude/commands/aide/refactor.md

refactor is a command for Claude Code from aidemd-mcp/server. It costs 0 tokens per session (1,952 once invoked), scanned A, original, MIT.

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

Written for Claude Code: installed under .claude/.

This is aidemd-mcp/server's own configuration. It tells Claude Code how to work on server itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything server configures →

Reuse

Borrowing it

Nothing to install: this file belongs to aidemd-mcp/server. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/aidemd-mcp/server/main/.claude/commands/aide/refactor.md
Clone the repo
git clone --depth 1 https://github.com/aidemd-mcp/server

Made for: Claude Code.

Wrote 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.

agentmods badge for refactor

README.md
[![agentmods](https://agentmods.dev/badge/commands/aidemd-mcp/server/refactor/github.svg)](https://agentmods.dev/commands/aidemd-mcp/server/refactor)
Your own site
<a href="https://agentmods.dev/commands/aidemd-mcp/server/refactor"><img src="https://agentmods.dev/badge/commands/aidemd-mcp/server/refactor/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for refactor

Your own site · 80×15
<a href="https://agentmods.dev/commands/aidemd-mcp/server/refactor"><img src="https://agentmods.dev/badge/commands/aidemd-mcp/server/refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
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. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00000 $0.01952
Opus 5.5 $0.00000 $0.00781
Sonnet 5.5 $0.00000 $0.00390
Haiku 4.5 $0.00000 $0.00195

Measured 2mo ago against content hash 4eb49cfc18eb, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 2mo 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/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-auditor → aide-implementor → aide-qa
--specs .aide files Brevity Contract aide-aligner → aide-spec-writer and/or aide-strategist → aide-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. 2mo ago 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 (4 stars, last pushed 2d 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.