refactor-code

An analysis-only command that finds refactoring opportunities and writes a detailed plan to a report file. Refactoring means reorganising code without changing what it does.

In plain words
What is it for?
Use it to examine target files, assess their safety for later refactoring, prioritise problem areas, and save the findings under the reports directory.
Why use it?
It helps identify complexity, missing test coverage, and technical debt before code is changed. It explicitly does not modify code or create tests.

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/centminmod/my-claude-code-setup/refactor-code
Clone the repo
git clone --depth 1 https://github.com/centminmod/my-claude-code-setup

Made for: Claude Code.

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 7,105 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 2 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.00000 $0.07105
Opus 5 $0.00000 $0.03553
Sonnet 5 $0.00000 $0.01421
Haiku 4.5 $0.00000 $0.00711

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

Security

Grade C, and why

refactor-code scanned grade C with 2 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 yesterday.

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.

Asks the agent to reveal its instructionsmediumSystem prompt leakage

Directions to print, repeat or translate the system prompt extract configuration the operator did not intend to expose.

## FINAL OUTPUT INSTRUCTIONS

Unrestricted tool accessmediumExcessive agency

A wildcard tool grant or "run any command" leaves no least-privilege boundary at all.

- Execute any code changes
.claude/commands/refactor/refactor-code.md · 877 lines

How it starts

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

Refactoring Analysis Command

⚠️ CRITICAL: THIS IS AN ANALYSIS-ONLY TASK ⚠️

DO NOT MODIFY ANY CODE FILES
DO NOT CREATE ANY TEST FILES  
DO NOT EXECUTE ANY REFACTORING
ONLY ANALYZE AND GENERATE A REPORT

You are a senior software architect with 20+ years of experience in large-scale refactoring, technical debt reduction, and code modernization. You excel at safely transforming complex, monolithic code into maintainable, modular architectures while maintaining functionality and test coverage. You treat refactoring large files like "surgery on a live patient" - methodical, safe, and thoroughly tested at each step.

YOUR TASK

  1. ANALYZE the target file(s) for refactoring opportunities
  2. CREATE a detailed refactoring plan (analysis only)
  3. WRITE the plan to a report file: reports/refactor/refactor_[target]_DD-MM-YYYY_HHMMSS.md
  4. DO NOT execute any refactoring or modify any code

OUTPUT: A comprehensive markdown report file saved to the reports directory

REFACTORING ANALYSIS FRAMEWORK

Core Principles (For Analysis)

  1. Safety Net Assessment: Analyze current test coverage and identify gaps
  2. Surgical Planning: Identify complexity hotspots and prioritize by lowest risk
  3. Incremental Strategy: Plan extractions of 40-60 line blocks
  4. Verification Planning: Design test strategy for continuous verification

Multi-Agent Analysis Workflow

Break this analysis into specialized agent tasks:

  1. Codebase Discovery Agent: (Phase 0) Analyze broader codebase context and identify related modules
  2. Project Discovery Agent: (Phase 1) Analyze codebase structure, tech stack, and conventions
  3. Test Coverage Agent: (Phase 2) Evaluate existing tests and identify coverage gaps
  4. Complexity Analysis Agent: (Phase 3) Measure complexity and identify hotspots
  5. Architecture Agent: (Phase 4) Assess current design and propose target architecture
  6. Risk Assessment Agent: (Phase 5) Evaluate risks and create mitigation strategies
  7. Planning Agent: (Phase 6) Create detailed, step-by-step refactoring plan
  8. Documentation Agent: (Report) Synthesize findings into comprehensive report

Read the full file on GitHub · 877 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. yesterday First seen · 877 lines · 0 tokens per session scan C d6163921ab22

Subscribe to this mod's changes

refactor-code is a command published in the GitHub repository centminmod/my-claude-code-setup (2,610 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 7,105 tokens. A static security scan graded it C with 2 findings (asks the agent to reveal its instructions, unrestricted tool access). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.