refactor

refactor is a command for Claude Code from spideynolove/claude-dotfiles. It costs 13 tokens per session (2,795 once invoked), scanned A, original, MIT.

A command for improving existing code in small steps while checking common software design principles. It also estimates technical debt, meaning the future cost of leaving hard-to-maintain code unfixed.

In plain words
What is it for?
Use it to split large methods, consolidate duplicate functions, assess classes against the SOLID principles, improve complex conditions, and address marked technical debt.
Why use it?
It helps identify long functions, repeated code, deeply nested conditions, and TODO or FIXME comments before they make the code harder to change.

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/spideynolove/claude-dotfiles/refactor
Clone the repo
git clone --depth 1 https://github.com/spideynolove/claude-dotfiles

Made for: Claude Code.

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

README.md
[![agentmods](https://agentmods.dev/badge/commands/spideynolove/claude-dotfiles/refactor.svg)](https://agentmods.dev/commands/spideynolove/claude-dotfiles/refactor)
Your own site
<a href="https://agentmods.dev/commands/spideynolove/claude-dotfiles/refactor"><img src="https://agentmods.dev/badge/commands/spideynolove/claude-dotfiles/refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 13 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,795 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.00013 $0.02795
Opus 5 $0.00006 $0.01398
Sonnet 5 $0.00003 $0.00559
Haiku 4.5 $0.00001 $0.00280

Measured 3d ago against content hash 70927ebeb986, 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 3d 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-global-backup/commands/refactor.md · 311 lines

How it starts

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

Refactor

Performs safe, step-by-step code refactoring with quantitative SOLID principles evaluation. Visualizes technical debt and clarifies improvement priorities.

Usage

# Identify complex code and create refactoring plan
find . -name "*.js" -exec wc -l {} + | sort -rn | head -10
"Refactor large files to reduce complexity"

# Detect and consolidate duplicate code
grep -r "function processUser" . --include="*.js"
"Consolidate duplicate functions using Extract Method"

# Evaluate SOLID principles violations
grep -r "class.*Service" . --include="*.js" | head -10
"Assess whether these classes follow Single Responsibility Principle"

Basic Examples

# Find long methods
grep -A 50 "function" src/*.js | grep -B 50 -A 50 "return" | wc -l
"Split methods over 50 lines using Extract Method"

# Find complex conditions
grep -r "if.*if.*if" . --include="*.js"
"Improve nested conditions using Strategy pattern"

# Find code smells
grep -r "TODO\|FIXME\|HACK" . --exclude-dir=node_modules
"Resolve technical debt in comments"

Refactoring Techniques

Extract Method (Split Big Functions)
// Before: Long method
function processOrder(order) {
  // 50 lines of complex processing
}

// After: Separation of responsibilities
function processOrder(order) {
  validateOrder(order);
  calculateTotal(order);
  saveOrder(order);
}
Replace Conditional with Polymorphism (Remove Switch/If Chains)
// Before: switch statement
function getPrice(user) {
  switch (user.type) {
    case "premium":
      return basePrice * 0.8;
    case "regular":
      return basePrice;
  }
}

// After: Strategy pattern
class PremiumPricing {
  calculate(basePrice) {
    return basePrice * 0.8;
  }
}

SOLID Principles Scoring (0-100 points)

Evaluation Criteria and Scoring
S - Single Responsibility (20 points)
├─ Number of responsibilities: 1 (20pts) | 2 (15pts) | 3 (10pts) | 4+ (5pts)
├─ Method count: <7 (+5pts) | 7-15 (+3pts) | >15 (0pts)
├─ Clear reasons for change: Clear (+5pts) | Unclear (0pts)
└─ Example score: UserService (auth + data processing) = 10 points

O - Open/Closed (20 points)
├─ Extension points: Strategy/Template Method (20pts) | Inheritance only (10pts) | None (5pts)
├─ Existing code changes for new features: Not needed (+5pts) | Minimal (+3pts) | Required (0pts)
├─ Interface usage: Appropriate (+5pts) | Partial (+3pts) | None (0pts)
└─ Example score: PaymentProcessor (Strategy) = 20 points

L - Liskov Substitution (20 points)
├─ Derived class contract compliance: Complete (20pts) | Partial (10pts) | Violated (0pts)
├─ Precondition strengthening: None (+5pts) | Present (-5pts)
├─ Postcondition weakening: None (+5pts) | Present (-5pts)
└─ Example score: Square extends Rectangle = 0 points (violated)

I - Interface Segregation (20 points)
├─ Interface size: 1-3 methods (20pts) | 4-7 (15pts) | 8+ (5pts)
├─ Unused method implementations: None (+5pts) | 1-2 (+2pts) | 3+ (0pts)
├─ Role clarity: Single role (+5pts) | Multiple roles (0pts)
└─ Example score: Readable/Writable separation = 20 points

D - Dependency Inversion (20 points)
├─ Dependency direction: Abstractions only (20pts) | Mixed (10pts) | Concretions only (5pts)
├─ DI usage: Constructor Injection (+5pts) | Setter (+3pts) | None (0pts)
├─ Testability: Mockable (+5pts) | Difficult (0pts)
└─ Example score: Repository Pattern = 20 points

Total Score = S + O + L + I + D
├─ 90-100 points: Excellent (SOLID compliant)
├─ 70-89 points: Good (Minor improvements needed)
├─ 50-69 points: Fair (Refactoring recommended)
├─ 30-49 points: Poor (Major improvements required)
└─ 0-29 points: Critical (Design overhaul required)

Read the full file on GitHub · 311 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. 3d ago First seen · 311 lines · 13 tokens per session scan A 70927ebeb986

Subscribe to this mod's changes

refactor is a command published in the GitHub repository spideynolove/claude-dotfiles (2 stars, last pushed 3mo ago), licensed MIT. It adds 13 tokens to every session and 2,795 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-31.