refactor

refactor is a command for Claude Code from tzachbon/smart-ralph. It costs 0 tokens per session (1,657 once invoked), scanned A, original, MIT.

A command that updates existing software specification files after implementation work. It reviews requirements, design, and task documents and delegates the actual edits to a specialist.

In plain words
What is it for?
Use it to review specification files one by one, update selected or all files, handle downstream changes, and finalize the revised documents.
Why use it?
It keeps the specification aligned with what was learned during execution and helps propagate changes to later documents when one file changes.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: mentions subagents; names the AskUserQuestion tool.

Runs only inside its plugin — its command needs a path that Claude Code sets for a plugin’s own hooks and for nothing else. Install the plugin, not this.

Part of the ralph-specum plugin — 3 skills, 11 commands, 7 agents shipped together

Good fit Use it to review specification files one by one, update selected or all files, handle downstream changes, and finalize the revised documents.

Compare 6 commands from other repositories ↓
Install

Getting it into your agent

This one installs as part of its plugin. Adding the marketplace and installing the plugin brings it with everything else the plugin ships.

Claude Code
/plugin marketplace add tzachbon/smart-ralph
Claude Code
/plugin install ralph-specum

Made for: Claude Code.

Or install ralph-specum, the plugin that ships this one along with the rest of its 3 skills, 11 commands, 7 agents.

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/tzachbon/smart-ralph/refactor/github.svg)](https://agentmods.dev/commands/tzachbon/smart-ralph/refactor)
Your own site
<a href="https://agentmods.dev/commands/tzachbon/smart-ralph/refactor"><img src="https://agentmods.dev/badge/commands/tzachbon/smart-ralph/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/tzachbon/smart-ralph/refactor"><img src="https://agentmods.dev/badge/commands/tzachbon/smart-ralph/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,657 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.01657
Opus 5.5 $0.00000 $0.00663
Sonnet 5.5 $0.00000 $0.00331
Haiku 4.5 $0.00000 $0.00166

Measured 1mo ago against content hash d6a785f75472, 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 1mo 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.

plugins/ralph-specum/commands/refactor.md · 169 lines

How it starts

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

Refactor Spec

Update specification files after execution. You are a coordinator, not a writer -- delegate actual updates to the refactor-specialist subagent.

Checklist

Create a task for each item and complete in order:

  1. Gather context -- resolve spec, read existing files and learnings
  2. Determine scope -- which files to refactor (from --file flag or all)
  3. File-by-file review -- section-by-section review with user for each file
  4. Delegate updates -- dispatch refactor-specialist for each file
  5. Handle cascades -- propagate changes downstream if needed
  6. Finalize -- update state, commit

Step 1: Gather Context

  1. If $ARGUMENTS contains a spec name, use ralph_find_spec() to resolve it; otherwise use ralph_resolve_current()
  2. If no active spec, error: "No active spec. Run /ralph-specum:new first."
  3. Check the resolved spec directory exists
  4. Read .ralph-state.json if exists
  5. Identify which spec files exist: requirements.md, design.md, tasks.md
  6. If no spec files exist, error: "No spec files found. Run /ralph-specum:start first."
  7. Read .progress.md to understand implementation learnings

Step 2: Determine Scope & Present Overview

Check $ARGUMENTS for --file= flag:

  • --file=requirements: Only requirements.md
  • --file=design: Only design.md
  • --file=tasks: Only tasks.md
  • No flag: All files in order (requirements -> design -> tasks)

Present overview to user:

Spec: $spec

Files to review:
- requirements.md: [exists/missing] - [brief summary: X user stories, Y requirements]
- design.md: [exists/missing] - [brief summary: X components, Y decisions]
- tasks.md: [exists/missing] - [brief summary: X tasks, Y completed]

Implementation learnings from .progress.md:
- [Key learning 1]
- [Key learning 2]

Prototype Refactor Gate

After resolving the ordered file list above and before any refactor dispatch:

  1. Whenever .ralph-state.json exists, reconcile candidates and finals once, even when activePrototypes is absent or empty:
    python3 "${CLAUDE_PLUGIN_ROOT}/hooks/scripts/prototype-records.py" reconcile --base-path "$SPEC_PATH" --state "$SPEC_PATH/.ralph-state.json"
    
  2. For each resolved file in scope, run selection with that exact file as both target and path:
    python3 "${CLAUDE_PLUGIN_ROOT}/hooks/scripts/prototype-records.py" select-downstream --base-path "$SPEC_PATH" --state "$SPEC_PATH/.ralph-state.json" --target "$FILE" --path "$FILE"
    
  3. Stop that file's refactor dispatch when activeBlockers targets the file or transition, when its task index appears in staleTaskIndexes, or when staleArtifacts contains the file or an upstream dependency.
  4. Preserve a file only when its matching targetDecisions entry has proofAvailable: true and eligible: true. Missing dependency or approved-transfer proof blocks that file conservatively.
  5. When refactor resumes execution, restore taskIndex from the relevant entry's returnTaskIndex before task dispatch.

Read the full file on GitHub · 169 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. 1mo ago First seen · 169 lines · 0 tokens per session scan A d6a785f75472

Subscribe to this mod's changes

refactor is a command published in the GitHub repository tzachbon/smart-ralph (559 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,657 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-09-03.