refactor

A structured process for changing the organization of existing code while keeping its behavior the same.

In plain words
What is it for?
Use it to restructure components, simplify repeated patterns, assess code dependencies, run tests around a refactor, and prepare work in an isolated branch.
Why use it?
It helps reveal affected parts of the project before changes are made and requires validation before and after the work. It also prevents accidental automatic commits.

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/qwickapps/ai-sdlc-workflows/refactor
Clone the repo
git clone --depth 1 https://github.com/qwickapps/ai-sdlc-workflows

Made for: Claude Code.

Per session 6 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,077 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.00006 $0.01077
Opus 5 $0.00003 $0.00539
Sonnet 5 $0.00001 $0.00215
Haiku 4.5 $0.00001 $0.00108

Measured 2d ago against content hash 18db9bcb269c, 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 2d 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/.claude/commands/refactor.md · 147 lines

How it starts

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

Refactoring Workflow

You are now in Refactoring Mode. Follow this workflow strictly.

Input: $ARGUMENTS (code, component, or pattern to refactor)

CRITICAL RULES

  1. Plan before refactoring - understand scope and impact (see RESEARCH-DEPTH.md)
  2. NEVER auto-commit - always wait for explicit user approval
  3. NEVER add legacy support - clean breaks are OK
  4. Preserve behavior - refactoring should not change functionality
  5. No attributions in commit messages
  6. When blocked - STOP and discuss (see COMMUNICATION-PROTOCOL.md)
  7. Use worktree script - NEVER use git commands directly (see WORKTREE-ENFORCEMENT.md)
  8. Validate thoroughly - tests must pass before and after (see VALIDATION-GATES.md)

Interactive Setup

Check if $ARGUMENTS is provided.

If $ARGUMENTS is empty, ask:

"What would you like to refactor? Please describe:

  • The code, component, or pattern to restructure
  • Why refactoring is needed
  • The desired end state
  • Issue/ticket number (if this refactoring is tracked)"

Extract and store the issue/ticket number (if provided) for:

  • Branch naming (refactor/ISSUE-123)
  • Document attachment
  • Commit messages

Wait for response before proceeding.

Workflow Phases

PHASE 1: Analysis (Architect)

  1. Understand current state:

    • What code is being refactored?
    • Why is refactoring needed?
    • What is the desired end state?
  2. Impact analysis:

    • What files/components are affected?
    • What depends on this code?
    • Are there breaking changes?
  3. Create Refactoring Proposal:

    • Save to: .claude/engineering/refactors/REFACTOR-<id>-<short-name>.md
    • Include: current state, proposed state, migration steps, risks
  4. Attach Refactoring Proposal to issue/ticket (if issue number provided):

    • For GitHub issues: Use gh issue comment <issue-number> --body-file <refactor-proposal-path>
    • For JIRA tickets: Use JIRA CLI or REST API to attach document
    • If attachment fails or not applicable: Inform user to attach manually

Read the full file on GitHub · 147 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. 2d ago First seen · 147 lines · 6 tokens per session scan A 18db9bcb269c

Subscribe to this mod's changes

refactor is a command published in the GitHub repository qwickapps/ai-sdlc-workflows (2 stars, last pushed 5mo ago), licensed MIT. It adds 6 tokens to every session and 1,077 once invoked, about $0.0000 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-31.