refactor

A code-review command that looks for SOLID design violations, code smells, duplicated logic, and overly complex code. SOLID is a set of principles for keeping software responsibilities and dependencies manageable.

In plain words
What is it for?
It is for reviewing a file, directory, function, or class and suggesting focused refactoring based on its size, complexity, duplication, and mixed responsibilities.
Why use it?
It points out structural problems that can make code harder to change, understand, or test.

Command

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/florianbruniaux/claude-code-plugins/refactor
Clone the repo
git clone --depth 1 https://github.com/FlorianBruniaux/claude-code-plugins
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 1,332 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.01332
Opus 5 $0.00006 $0.00666
Sonnet 5 $0.00003 $0.00266
Haiku 4.5 $0.00001 $0.00133

Measured yesterday against content hash 2a56e6620c11, 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 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.

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.

plugins/code-quality/commands/refactor.md · 216 lines

How it starts

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

SOLID Refactoring Assistant

Analyze code for SOLID violations and suggest targeted improvements.

Purpose

Identify refactoring opportunities based on:

  • SOLID principle violations
  • Code smells and anti-patterns
  • Complexity metrics
  • Duplication detection

Instructions

Step 1: Scope Analysis

Determine the refactoring scope from user input:

  • Single file: Deep analysis
  • Directory: Pattern detection across files
  • Function/class: Focused extraction suggestions
# Get file/directory stats
if [ -f "$TARGET" ]; then
  wc -l "$TARGET"
  echo "Single file analysis"
elif [ -d "$TARGET" ]; then
  find "$TARGET" -type f \( -name "*.ts" -o -name "*.js" -o -name "*.py" \) | wc -l
  echo "Directory analysis"
fi

Step 2: SOLID Violations Detection

S - Single Responsibility

Look for:

  • Files > 300 lines
  • Functions > 50 lines
  • Classes with > 10 methods
  • Mixed concerns (data + UI + business logic)
# Find large files
find . -name "*.{ts,js,py}" -exec wc -l {} + 2>/dev/null | sort -rn | head -10

# Functions with high line count (approximate)
grep -rn "function\|def \|fn " --include="*.{ts,js,py,rs}" . | head -20
O - Open/Closed Principle

Look for:

  • Switch/case statements on types
  • Repeated if/else type checking
  • Direct modifications vs extensions
L - Liskov Substitution

Look for:

  • Overridden methods that throw "not implemented"
  • Type checks before method calls
  • Empty method overrides
I - Interface Segregation

Look for:

  • Large interfaces (> 10 methods)
  • Classes implementing unused interface methods
  • Fat service classes
D - Dependency Inversion

Look for:

  • Direct instantiation of dependencies (new Service())
  • Hardcoded class references
  • Missing dependency injection

Step 3: Code Smells

# Duplication patterns
grep -rn --include="*.{ts,js,py}" . 2>/dev/null | \
  awk -F: '{print $3}' | sort | uniq -c | sort -rn | head -10

# Long parameter lists (> 4 params)
grep -rn "function.*,.*,.*,.*," --include="*.{ts,js}" . 2>/dev/null | head -10

# Deep nesting (4+ levels)
grep -rn "^\s\{16,\}" --include="*.{ts,js,py}" . 2>/dev/null | head -10

Read the full file on GitHub · 216 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 · 216 lines · 13 tokens per session scan A 2a56e6620c11

Subscribe to this mod's changes

refactor is a command published in the GitHub repository FlorianBruniaux/claude-code-plugins (40 stars, last pushed 2mo ago), licensed MIT. It adds 13 tokens to every session and 1,332 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.