code-smell-detection

Use when reviewing code quality, before refactoring, when complexity increases, when code feels "hard to change", during code review, or when onboarding to unfamiliar code - systematic identification of code smells with specific refactoring recipes

$ Installer

git clone https://github.com/HTRamsey/claude-config /tmp/claude-config && cp -r /tmp/claude-config/skills/code-smell-detection ~/.claude/skills/claude-config

// tip: Run this command in your terminal to install the skill


name: code-smell-detection description: Use when reviewing code quality, before refactoring, when complexity increases, when code feels "hard to change", during code review, or when onboarding to unfamiliar code - systematic identification of code smells with specific refactoring recipes

Code Smell Detection

Persona: Code quality auditor who catalogs issues without judgment, focusing on objective metrics.

Core principle: Detect smells early, refactor incrementally, prevent accumulation.

Should NOT Attempt

  • Refactoring while detecting (separate concerns)
  • Flagging style preferences as smells (smell != dislike)
  • Reporting smells without refactoring recipes
  • Detecting smells in generated or vendored code

Smell Categories

Bloaters (Too Big)

SmellDetectionRefactoring
Long Method>20 lines, multiple indentsExtract Method
Large Class>300 lines, many responsibilitiesExtract Class
Long Parameter List>3 parametersIntroduce Parameter Object
Primitive ObsessionStrings for IDs, ints for moneyValue Object
Data ClumpsSame 3+ fields appear togetherExtract Class

Change Preventers (Hard to Modify)

SmellDetectionRefactoring
Divergent ChangeOne class changed for many reasonsExtract Class per reason
Shotgun SurgeryOne change requires many file editsMove Method, Inline Class

Couplers (Too Connected)

SmellDetectionRefactoring
Feature EnvyMethod uses another class more than ownMove Method
Message Chainsa.b().c().d()Hide Delegate

Dispensables (Remove)

SmellDetectionRefactoring
Dead CodeUnreachable, unusedDelete
Duplicate CodeSame logic in multiple placesExtract Method/Class
CommentsExplaining bad codeRefactor code to be clear

Detection

# Long methods/Large files
find ./src -name "*.py" -exec wc -l {} \; | awk '$1 > 300'

# Feature Envy: Count method's references to own vs other class
# If other > own, method belongs elsewhere

Refactoring Recipe: Extract Method

# Before: Long method with comment sections
def process_order(order):
    # Validate order
    if not order.items: raise ValueError("Empty order")
    # Calculate totals
    total = sum(item.price for item in order.items) * 1.1
    # Notify
    send_email(order.customer.email, f"Total: {total}")

# After: Extracted methods
def process_order(order):
    validate_order(order)
    total = calculate_total(order)
    notify_customer(order.customer, total)

Prioritization

SeveritySmellsAction
HighDuplicate code, Feature envy, God classFix immediately
MediumLong methods, Long params, Data clumpsFix when touching file
LowComments, Lazy classFix during cleanup

Output Format

## Code Smell Report: {path}

### High Priority
| File:Line | Smell | Evidence | Refactoring |
|-----------|-------|----------|-------------|
| user.py:45 | Long Method | 67 lines | Extract Method |

Escalation Triggers

ConditionAction
>10 High severity smellsEscalate to orchestrator agent for planning
God class (>1000 lines)Use batch-editor agent for systematic extraction
Circular dependenciesEscalate to architecture review
No test coverageSTOP. Add tests before ANY refactoring

Failure Behavior

If detection cannot complete:

  • Report smells found so far with file:line references
  • State reason for incomplete analysis (e.g., "Circular imports prevented full analysis")
  • Recommend next steps (e.g., "Break circular dependency A→B→A first")

Red Flags

  • "It works, don't touch it" - Smells accumulate
  • Refactoring without tests - Recipe for regression

Related Skills

  • receiving-code-review: Both focus on code quality improvement
  • verification-before-completion: Verify fixes don't introduce new smells

Integration

  • orchestrator agent - Plan safe refactoring after detecting smells
  • code-reviewer agent - Find dead code during review
  • test-driven-development skill - Write tests before refactoring