refactor-guided

refactor-guided is a command for Claude Code from CloudAI-X/claude-workflow-v2. It costs 21 tokens per session (989 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 for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the project-starter plugin — 14 skills, 26 commands, 7 agents, 6 hooks shipped together

Good fit 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.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/cloudai-x/claude-workflow-v2/refactor-guided
About the project

Project Starter is a workflow plugin that equips coding agents with specialized subagents, reusable skills, commands, hooks, and output styles for software projects. It is for developers who want structured assistance with tasks such as planning, debugging, code review, security, and automation across several coding-agent platforms. Catalogue add-ons are components of its own workflow.

CloudAI-X/claude-workflow-v2 · 1,420 stars · on GitHub

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.

Clone the repo
git clone --depth 1 https://github.com/CloudAI-X/claude-workflow-v2

Made for: Claude Code.

Or install project-starter, 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/github.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/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-guided

Your own site · 80×15
<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="Reviewed on agentmods" width="80" 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 989 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.00021 $0.00989
Opus 5.5 $0.00008 $0.00396
Sonnet 5.5 $0.00004 $0.00198
Haiku 4.5 $0.00002 $0.00099

Measured 18d ago against content hash d4bde545c1a0, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 18d 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
  • Current branch: !git branch --show-current
  • Working tree status: !git status --short
  • Project root files (infer the test framework from these): !ls -a
  • Existing tests: !git ls-files 2>/dev/null | grep -i -e test -e spec | head -10

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. If there are uncommitted changes, stop and ask the user — do not stash or commit their work yourself.

Workflow

Phase 1: Analyze Scope

  1. Identify the target file(s) or directory from $ARGUMENTS
  2. Map all dependents — files that import/use the target
  3. Map all dependencies — 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)

Phase 3: Refactor Incrementally

For each refactoring step:

  1. Describe the specific refactoring about to be applied (e.g., "Extract method X from class Y", "Rename variable A to B", "Move function to separate module")
  2. Apply the single refactoring change
  3. Run tests immediately after applying
  4. If tests PASS:
    • Commit with message: refactor: [specific change description]
    • Move to next refactoring step
  5. If tests FAIL:
    • Revert the change: git checkout -- ., and delete any new files this step created (they are untracked, so checkout leaves them behind)
    • Analyze why it failed
    • Try a different approach or break it into smaller steps
    • Document what went wrong

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. 18d ago Changed d4bde545c1a0
  2. 1mo 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,420 stars, last pushed 15d ago), licensed MIT. It adds 21 tokens to every session and 989 once invoked, about $0.0001 per session on Opus 5.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.