refactor-cycle

A repeatable process for finding technical debt—code maintenance problems that make future changes harder—then refactoring and checking each change for regressions.

In plain words
What is it for?
Use it to scan a module or whole project, prioritize technical debt, make iterative refactors, validate them against regressions, and continue an interrupted cleanup.
Why use it?
It organizes debt cleanup by importance and verifies changes as it goes, reducing the chance that refactoring introduces new failures.

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/catlog22/claude-code-workflow/refactor-cycle
Clone the repo
git clone --depth 1 https://github.com/catlog22/Claude-Code-Workflow

Made for: Claude Code.

Per session 29 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 8,208 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.00029 $0.08208
Opus 5 $0.00015 $0.04104
Sonnet 5 $0.00006 $0.01642
Haiku 4.5 $0.00003 $0.00821

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

Security

Grade A, and why

refactor-cycle 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/commands/workflow/refactor-cycle.md · 966 lines

How it starts

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

Auto Mode

When --yes or -y: Auto-confirm prioritization, use recommended refactoring strategy, skip interactive checkpoints.

Workflow Refactor-Cycle Command

Quick Start

# Discover and fix tech debt in a module
/workflow:refactor-cycle "src/auth 模块的技术债务清理"

# Auto mode - fully autonomous
/workflow:refactor-cycle -y "支付服务重构优化"

# Project-wide scan
/workflow:refactor-cycle --scope=project "全项目技术债务扫描与重构"

# Continue interrupted session
/workflow:refactor-cycle --continue "认证模块"

Context Source: cli-explore-agent + Gemini/Claude multi-dimensional analysis Output Directory: .workflow/.refactor/{session-id}/ Core Innovation: Debt-driven refactoring with regression-safe iterative execution and reflection

What & Why

Core Concept

Closed-loop tech debt lifecycle: Discover → Assess → Plan → Refactor → Validate → Reflect → Next — each refactoring item is executed, validated against regression, and reflected upon before proceeding.

vs Existing Commands:

  • workflow:lite-fix: Single bug fix, no systematic debt analysis
  • workflow-plan + execute: Generic implementation, no debt-aware prioritization or regression validation
  • This command: Full debt lifecycle — discovery through multi-dimensional scan, prioritized execution with per-item regression validation

Value Proposition

  1. Systematic Discovery: Multi-dimensional scan (code quality, architecture, dependencies, test gaps, performance)
  2. Risk-Aware Prioritization: Impact × effort matrix with dependency-aware ordering
  3. Regression-Safe: Each refactoring item validated before proceeding to next
  4. Documented Reasoning: Every debt item, prioritization decision, and refactoring outcome recorded

Output Artifacts

2 core files + 1 trace directory:

Artifact Type Description
reflection-log.md Human-readable ⭐ Debt inventory, prioritization rationale, per-item refactoring reflections, conclusions
state.json Machine-readable Debt items, priority queue, refactoring plans, validation results, iteration state
.trace/ Raw logs CLI analysis outputs, test outputs, diagnostics snapshots

Read the full file on GitHub · 966 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 · 966 lines · 29 tokens per session scan A b5a72e11a977

Subscribe to this mod's changes

refactor-cycle is a command published in the GitHub repository catlog22/Claude-Code-Workflow (2,134 stars, last pushed 2mo ago), licensed MIT. It adds 29 tokens to every session and 8,208 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.