/code-quality:refactor [file-or-dir] [--focus=srp|ocp|lsp|isp|dip] [--threshold=low|medium|high]from code-quality
Analyzes code for SOLID violations, code smells, and duplication, suggesting targeted refactoring improvements. Useful when a module has design issues or high complexity.
Ships in code-quality. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Analyze code for SOLID violations and suggest targeted improvements.
Identify refactoring opportunities based on:
Determine the refactoring scope from user input:
# Get file/directory stats (TARGET is the path from $ARGUMENTS)
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
Look for:
# Find large files
find . \( -name "*.ts" -o -name "*.js" -o -name "*.py" \) -exec wc -l {} + 2>/dev/null | sort -rn | head -10
# Functions with high line count (approximate)
grep -rn "function\|def \|fn " --include="*.ts" --include="*.js" --include="*.py" --include="*.rs" . | head -20
Look for:
Look for:
Look for:
Look for:
new Service())# Duplication patterns
grep -rn --include="*.ts" --include="*.js" --include="*.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" --include="*.js" . 2>/dev/null | head -10
# Deep nesting (4+ levels)
grep -rn "^\s\{16,\}" --include="*.ts" --include="*.js" --include="*.py" . 2>/dev/null | head -10
For each issue found, assess:
Target: [file/directory] Lines Analyzed: [count]
| Principle | Status | Issues Found |
|---|---|---|
| Single Responsibility | 🟡 | 3 large classes |
| Open/Closed | 🟢 | OK |
| Liskov Substitution | 🟢 | OK |
| Interface Segregation | 🔴 | 2 fat interfaces |
| Dependency Inversion | 🟡 | 5 direct instantiations |
UserServiceViolation: Single Responsibility Current: 450 lines handling auth + profile + notifications Suggested:
UserService.ts (450 lines)
↓ Extract
AuthService.ts (~150 lines)
ProfileService.ts (~150 lines)
NotificationService.ts (~100 lines)
Risk: Medium (update imports) Tests Needed: Update dependency injection in tests
Location: src/handlers/payment.ts:45
Current:
switch (paymentType) {
case 'card': // 50 lines
case 'bank': // 50 lines
case 'crypto': // 50 lines
}
Suggested: Strategy pattern with PaymentProcessor interface
Risk: Low (isolated change)
| Smell | Location | Severity |
|---|---|---|
| Long Method | api.ts:calculateTotal (120 lines) | 🟠 High |
| Duplicate Code | utils/*.ts (3 similar blocks) | 🟡 Medium |
| Deep Nesting | parser.ts:parse (6 levels) | 🟡 Medium |
validateEmail() to shared utils (used in 4 places)processOrder()Before applying suggestions:
Analyze specific file:
/refactor src/services/user.ts
Analyze directory:
/refactor src/api/
Focus on specific principle:
/refactor --focus=srp src/services/
With complexity threshold:
/refactor --threshold=high
$ARGUMENTS
What SKILL.md sets; muted values are Claude Code's defaults
Use when a module has SOLID violations, code smells, or duplication to address.
mediumThree short reads, in order
npx claudepluginhub florianbruniaux/claude-code-plugins --plugin code-quality18 skills in this plugin
/ast-grep-patternsStructural code search and refactoring with ast-grep: choose it over Grep, then write tested pattern and YAML rule recipes. Use when renaming calls or changing an API signature across a large codebase, migrating a framework, or finding code by shape (async functions without try/catch, empty catch blocks, long parameter lists). Not for plain text searches, which Grep handles faster./audit-codebaseCodebase health audit scoring 7 categories with progression plan/check-cache-bugsAudit Claude Code setup for cache bugs (CC#40524): sentinel, --resume/--continue, attribution header + ArkNill B3/B4/B5/design-patternsDetect, suggest, and evaluate GoF design patterns in TypeScript/JavaScript codebases. Use when refactoring code, applying singleton/factory/observer/strategy patterns, reviewing pattern quality, or finding stack-native alternatives for React, Angular, NestJS, and Vue./diagnoseInteractive troubleshooting assistant for Claude Code issues/eval-skillsAudit a project or library of skills for metadata, trigger boundaries, workflow completion criteria, local resource closure, instruction economy, tool scope, effort, and routing evidence. Use before shipping skills, after importing a skill collection, or when a skill triggers too often or not at all.Other plugins' skills for the same job