refactor-guided

refactor-guided is a command for coding agents from CloudAI-X/claude-workflow-v2. It costs 21 tokens per session (1,044 once invoked), scanned A, original, MIT.

A command for changing a codebase's internal structure while keeping its behavior the same. It makes one small refactoring at a time and checks tests after each change.

In plain words
What is it for?
Use it to inspect recent changes, identify the test setup, and carry out verified refactoring steps. It is suited to tasks such as reorganizing code or improving its structure without changing inputs or outputs.
Why use it?
It reduces the risk of breaking working software during cleanup. It also prevents structural changes from being mixed with new features, making problems easier to find and undo.

Command

Part of the claude-workflow-v2 plugin — 14 skills, 26 commands, 7 agents, 6 hooks shipped together

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/cloudai-x/claude-workflow-v2/refactor-guided
Clone the repo
git clone --depth 1 https://github.com/CloudAI-X/claude-workflow-v2

Or install claude-workflow-v2, the plugin that ships this one along with the rest of its 14 skills, 26 commands, 7 agents, 6 hooks.

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-guided

README.md
[![agentmods](https://agentmods.dev/badge/commands/cloudai-x/claude-workflow-v2/refactor-guided.svg)](https://agentmods.dev/commands/cloudai-x/claude-workflow-v2/refactor-guided)
Your own site
<a href="https://agentmods.dev/commands/cloudai-x/claude-workflow-v2/refactor-guided"><img src="https://agentmods.dev/badge/commands/cloudai-x/claude-workflow-v2/refactor-guided.svg" alt="Measured on agentmods" height="20"></a>
Per session 21 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,044 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.00021 $0.01044
Opus 5 $0.00010 $0.00522
Sonnet 5 $0.00004 $0.00209
Haiku 4.5 $0.00002 $0.00104

Measured 4d ago against content hash 4afd3b792eaf, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refactor-guided 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 4d 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.

commands/refactor-guided.md · 118 lines

How it starts

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

Guided Refactoring

Perform safe, incremental refactoring with test verification at every step.

Context

  • Recent changes: !git diff --name-only HEAD~3 2>/dev/null | head -10 || echo "No recent changes"
  • Current branch: !git branch --show-current
  • Working tree status: !git status --short
  • Test framework: !cat package.json 2>/dev/null | grep -E '"(jest|vitest|mocha)"' | head -1 || ls pytest.ini pyproject.toml 2>/dev/null | head -1 || ls Cargo.toml go.mod 2>/dev/null | head -1 || echo "Unknown"
  • Existing tests: !find . -name "*test*" -o -name "*spec*" 2>/dev/null | grep -E '\.(ts|tsx|js|jsx|py|go|rs)$' | head -10 || echo "No test files found"

Safety Rules (NON-NEGOTIABLE)

  1. NEVER refactor AND add features simultaneously. Each change is purely structural.
  2. NEVER proceed without passing tests. If tests fail after a refactoring, revert immediately.
  3. ONE refactoring at a time. Each commit is a single, atomic refactoring step.
  4. Preserve external behavior. Inputs and outputs must remain identical.
  5. Ensure clean working tree before starting. Stash or commit uncommitted changes first.

Workflow

Phase 1: Analyze Scope

  1. Identify the target file(s) or directory from $ARGUMENTS
  2. Map all dependencies — files that import/use the target
  3. Map all dependents — files that the target imports/uses
  4. Assess blast radius: how many files could be affected?
  5. Report scope summary before proceeding:
    ## Refactoring Scope
    - Target: [file/directory]
    - Files affected: [count]
    - Dependencies: [list]
    - Dependents: [list]
    - Risk level: [low/medium/high]
    

Phase 2: Ensure Test Coverage

  1. Check if tests exist for the current behavior of the target
  2. Run existing tests to confirm they pass (this is your safety net)
  3. If test coverage is insufficient:
    • Write tests that capture the current behavior BEFORE refactoring
    • Run them to confirm they pass
    • Commit these tests separately: test: add coverage for [target] before refactoring
  4. Record baseline test results (pass count, time)

Read the full file on GitHub · 118 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. 4d ago First seen · 118 lines · 21 tokens per session scan A 4afd3b792eaf

Subscribe to this mod's changes

refactor-guided is a command published in the GitHub repository CloudAI-X/claude-workflow-v2 (1,413 stars, last pushed 9d ago), licensed MIT. It adds 21 tokens to every session and 1,044 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-30.