Skip to content
Development
Command

/refactor

Ultra-fast parallel refactoring analysis with 8-10x speedup through concurrent smell detection and intelligent improvement strategies

From plugin
claude-cmd
313180 skills180 commands

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/refactor

Context preview

What this command does when you run it.

Ultra-fast parallel refactoring analysis with 8-10x speedup through concurrent smell detection and intelligent improvement strategies

Command definition

refactor.md
allowed-tools: Read, Write, Edit, MultiEdit, Bash(fd:*), Bash(rg:*), Bash(jq:*), Bash(git:*), Task
name: "Refactor"
description: "Ultra-fast parallel refactoring analysis with 8-10x speedup through concurrent smell detection and intelligent improvement strategies"
author: "wcygan"
tags: ["code","refactor"]
version: "1.0.0"
created_at: "2025-07-14T00:00:00Z"
updated_at: "2025-07-14T00:00:00Z"

Context

  • Session ID: !`gdate +%s%N 2>/dev/null || date +%s000000000 2>/dev/null || echo "session-$(date +%s)000000000"`
  • Current directory: !`pwd`
  • Target: $ARGUMENTS
  • Project structure: !`fd . -t d -d 3 | head -15 || echo "No directory structure detected"`
  • Code files: !`fd "\.(java|go|rs|py|ts|js|cpp|c|kt|scala|rb|php|cs|swift)$" . | wc -l | tr -d ' ' || echo "0"`
  • Test files: !`fd "(test|spec)" . -t f | wc -l | tr -d ' ' || echo "0"`
  • Large files: !`fd "\.(java|go|rs|py|ts|js|cpp|c)$" . -x wc -l {} \; 2>/dev/null | awk '{if($1>500) count++} END {print count+0}' || echo "0"`
  • Technology stack: !`fd "(deno\.json|package\.json|Cargo\.toml|go\.mod|pom\.xml|build\.gradle|requirements\.txt|composer\.json)" . | head -5 || echo "No project files detected"`
  • Dependencies: !`rg "(import|require|use|include)" . --type java --type go --type rust --type python --type typescript | wc -l | tr -d ' ' || echo "0"`
  • Git status: !`git status --porcelain | head -5 || echo "Not a git repository"`
  • Current branch: !`git branch --show-current 2>/dev/null || echo "No git repository"`
  • Recent commits: !`git log --oneline -3 2>/dev/null || echo "No git history"`

Your Task

**CRITICAL: Maximize parallel execution for 8-10x faster refactoring analysis. Sequential processing is obsolete.**

Think deeply about optimal refactoring strategies for this codebase. Consider maintainability, performance, and architectural patterns.

STEP 1: Initialize refactoring session

  • CREATE session state file: `/tmp/refactor-analysis-$SESSION_ID.json`
  • SET initial state:
  {
    "sessionId": "$SESSION_ID",
    "target": "$ARGUMENTS",
    "phase": "discovery",
    "language": "auto-detect",
    "smells": [],
    "refactorings": [],
    "priority_order": [],
    "test_coverage": null,
    "checkpoints": []
  }

STEP 2: Determine analysis scope and approach

Think harder about the optimal analysis strategy based on codebase complexity and architectural depth.

IF $ARGUMENTS is directory AND contains >100 files:

  • USE sub-agent delegation for parallel analysis
  • SET scope to "comprehensive"
  • CREATE inter-agent communication files: `/tmp/refactor-agents-$SESSION_ID/`

ELSE IF $ARGUMENTS is single large file (>1000 lines):

  • USE extended thinking for complex architectural analysis
  • SET scope to "deep"
  • ENABLE ultrathink mode for intricate dependency analysis

ELSE:

  • PERFORM focused sequential analysis
  • SET scope to "targeted"
  • USE extended thinking for critical refactoring decisions

STEP 3: Ultra-fast parallel code smell detection

**IMMEDIATELY DEPLOY 10 PARALLEL AGENTS** for instant comprehensive refactoring analysis:

[Launch ALL agents simultaneously - NO sequential execution]

Task 1: **Architectural Smell Detection Agent**

  • Find god classes, feature envy, inappropriate intimacy
  • Map cyclic dependencies and layering violations
  • Identify monolithic structures needing decomposition
  • Detect misplaced responsibilities and SRP violations
  • Output: `/tmp/refactor-agents-$SESSION_ID/architectural-smells.json`

Task 2: **Code Duplication Hunter Agent**

  • Detect exact and near-duplicate code blocks
  • Find structural duplication patterns across modules
  • Identify copy-paste inheritance and template patterns
  • Calculate duplication hotspots and impact scores
  • Output: `/tmp/refactor-agents-$SESSION_ID/duplication-analysis.json`

Task 3: **Complexity Analyzer Agent**

  • Calculate cyclomatic complexity for all methods
  • Identify deeply nested code blocks and conditionals
  • Find methods exceeding cognitive complexity thresholds
  • Detect complex boolean expressions needing simplification
  • Output: `/tmp/refactor-agents-$SESSION_ID/complexity-metrics.json`

Task 4: **Type Safety Auditor Agent**

  • Scan for weak typing and missing type annotations
  • Identify unsafe casts and type coercions
  • Find null/undefined handling issues
  • Detect generic type inconsistencies
  • Output: `/tmp/refactor-agents-$SESSION_ID/type-safety-report.json`

Task 5: **Performance Bottleneck Agent**

  • Identify O(n²) algorithms and inefficient loops
  • Find memory leaks and resource management issues
  • Detect N+1 queries and database inefficiencies
  • Analyze collection usage and data structure choices
  • Output: `/tmp/refactor-agents-$SESSION_ID/performance-bottlenecks.json`

Task 6: **Design Pattern Violation Agent**

  • Detect anti-patterns (singleton abuse, anemic models)
  • Find missing design patterns opportunities
  • Identify SOLID principle violations
  • Check for proper abstraction levels
  • Output: `/tmp/refactor-agents-$SESSION_ID/pattern-violations.json`

Task 7: **Test Quality Inspector Agent**

  • Analyze test coverage gaps and blind spots
  • Find brittle tests and flaky test patterns
  • Identify missing edge case coverage
  • Detect test code smells and duplication
  • Output: `/tmp/refactor-agents-$SESSION_ID/test-quality-report.json`

Task 8: **Dependency Analysis Agent**

  • Map internal and external dependencies
  • Identify tightly coupled modules
  • Find unused dependencies and imports
  • Detect dependency version conflicts
  • Output: `/tmp/refactor-agents-$SESSION_ID/dependency-analysis.json`

Task 9: **Security Smell Detection Agent**

  • Find hardcoded credentials and secrets
  • Identify injection vulnerabilities
  • Detect insecure random generation
  • Check for missing input validation
  • Output: `/tmp/refactor-agents-$SESSION_ID/security-smells.json`

Task 10: **Documentation Debt Agent**

  • Find undocumented public APIs
  • Identify outdated or misleading comments
  • Detect missing architectural documentation
  • Analyze code-to-d
Read more
Ships withclaude-cmd

A lightweight (~46kB) and comprehensive CLI tool for managing Claude commands, configurations, and workflows.

Get the whole plugin