xarchitecture
Design, analyze, and evolve system architecture using Domain-Driven Design, 12-Factor App, and proven patterns
Interactive refactoring assistant based on Martin Fowler's catalog and project-specific rules for code smell detection
How it fires
How this command gets triggered: by you, by Claude, or both.
/xrefactorContext preview
What this command does when you run it.
Interactive refactoring assistant based on Martin Fowler's catalog and project-specific rules for code smell detection
description: Interactive refactoring assistant based on Martin Fowler's catalog and project-specific rules for code smell detection tags: [refactoring, code-smells, quality, patterns, analysis]
Analyze code for refactoring opportunities based on the arguments provided in $ARGUMENTS.
**Basic refactoring analysis:**
/xrefactor
**Detect code smells:**
/xrefactor --smell
**Find duplicate code:**
/xrefactor --duplicates
**Help and options:**
/xrefactor --help
If $ARGUMENTS contains "help" or "--help": Display this usage information and exit.
First, examine the project structure for Python files to analyze: !find . -name "*.py" -type f | grep -v __pycache__ | head -20 !ls -la src/ app/ lib/ 2>/dev/null || echo "No standard Python directories found" !python --version 2>/dev/null || echo "Python not available"
Based on $ARGUMENTS, perform the appropriate refactoring analysis:
If analyzing code smells (--smell, --analyze, --detect): !find . -name "*.py" | xargs wc -l | sort -nr | head -10 !python -c "import ast; print('AST analysis available')" 2>/dev/null || echo "Python AST not available" !grep -r "def " . --include="*.py" | wc -l !grep -r "class " . --include="*.py" | wc -l
Detect common code smells:
If detecting bloaters (--bloaters, --long-methods, --large-classes): !python -c " import ast import os for root, dirs, files in os.walk('.'): for file in files: if file.endswith('.py'): filepath = os.path.join(root, file) try: with open(filepath, 'r') as f: tree = ast.parse(f.read()) for node in ast.walk(tree): if isinstance(node, ast.FunctionDef): if hasattr(node, 'end_lineno') and node.end_lineno - node.lineno > 20: print(f'Long method: {node.name} in {filepath} ({node.end_lineno - node.lineno} lines)') except: pass " 2>/dev/null || echo "Python AST analysis not available"
Analyze bloater patterns:
If detecting change preventers (--change-preventers, --coupling): !grep -r "import " . --include="*.py" | wc -l !python -c " import ast import os for root, dirs, files in os.walk('.'): for file in files: if file.endswith('.py'): filepath = os.path.join(root, file) try: with open(filepath, 'r') as f: content = f.read() if content.count('if ') > 10: print(f'High conditional complexity in {filepath}') except: pass " 2>/dev/null
Identify change preventers:
If detecting dispensables (--dispensables, --dead-code, --duplicates): !grep -r "TODO\|FIXME\|XXX" . --include="*.py" | wc -l !find . -name "*.py" -exec grep -l "^#.*unused\|^#.*deprecated" {} \; | wc -l !python -c " import ast import os from collections import defaultdict
class_methods = defaultdict(list) for root, dirs, files in os.walk('.'): for file in files: if file.endswith('.py'): filepath = os.path.join(root, file) try: with open(filepath, 'r') as f: tree = ast.parse(f.read()) for node in ast.walk(tree): if isinstance(node, ast.ClassDef): methods = [n.name for n in node.body if isinstance(n, ast.FunctionDef)] if len(methods) < 2: print(f'Potential lazy class: {node.name} in {filepath}') except: pass " 2>/dev/null
Find dispensable code:
If detecting couplers (--couplers, --dependencies): !find . -name "*.py" | xargs grep -l "\.[a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_]" | head -10 !python -c " import ast import os for root, dirs, files in os.walk('.'): for file in files: if file.endswith('.py'): filepath = os.path.join(root, file) try: with open(filepath, 'r') as f: content = f.read()
if content.count('.') > len(content.split('\n')) * 0.3: print(f'Potential feature envy in {filepath}') except: pass " 2>/dev/null
Detect coupling issues:
Think step by step about refactoring opportunities and provide:
1. **Code Smell Analysis**:
2. **Refactoring Strategy**:
3. **Implementation Plan**:
4. **Quality Improve
Transform Claude Code into a complete development platform with 45 AI-powered commands that automate your entire software development workflow. Now with improved git identity management!
Design, analyze, and evolve system architecture using Domain-Driven Design, 12-Factor App, and proven patterns
Manage project configuration files, environment variables, and application settings
Continue an execution plan from where it left off across sessions
Interactive debugging support with error analysis and fix suggestions - integrates with Debug Specialist sub-agent for complex…