.claude/skills/refacter/SKILL.md
Refacter code using complexity analysis and hotspot detection. Use when asked to refactor code, improve code quality, reduce complexity, or identify high-risk areas that need attention.
npx skillsauth add awannaphasch2016/jousef-landing refacterInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Tech Stack: Python 3.11+, radon (complexity analysis), git (code churn analysis)
Source: Extracted from CLAUDE.md global refactoring principles and industry best practices.
Use the refactor skill when:
DO NOT use this skill for:
just format instead)Is code complex/hard to understand?
├─ YES → Measure complexity (radon)
│ ├─ Cyclomatic > 10? → Extract methods, simplify conditionals
│ └─ Cognitive > 15? → Reduce nesting, early returns
│
└─ NO → Is code changing frequently (hotspot)?
├─ YES → Analyze code churn + complexity
│ └─ High churn + high complexity? → Priority refactor target
│
└─ NO → Is code tightly coupled (connascence)?
├─ YES → Analyze connascence strength
│ ├─ Dynamic connascence (CoE, CoV)? → Critical, refactor to static
│ ├─ Strong static (CoP, CoM, CoA)? → Refactor to weaker forms
│ └─ Weak static (CoN, CoT)? → Acceptable
│
└─ NO → Is code duplicated?
├─ YES → Extract common patterns
└─ NO → Code is fine, no refactor needed
Escalation Trigger:
/compare needed to evaluate trade-offs/impact assessment for each approachTools Used:
/compare - Compare refactoring strategies (extract method vs extract class vs redesign)/impact - Assess blast radius of each approach (files affected, test changes, deployment risk)/validate - Verify refactoring preserves behavior (run tests)/reflect - Synthesize which approach worked bestWhy This Works: Refactoring naturally involves branching—choosing between different improvement paths based on complexity analysis.
See Thinking Process Architecture - Feedback Loops for structural overview.
# Analyze code complexity
python .claude/skills/refacter/scripts/analyze_complexity.py src/
# Identify hotspots (high churn + high complexity)
python .claude/skills/refacter/scripts/analyze_hotspots.py src/
Priority Matrix:
| Code Churn | Complexity | Priority | Action | |------------|------------|----------|--------| | High | High | P0 - Critical | Refactor immediately | | High | Low | P1 - Monitor | Add tests, watch for complexity | | Low | High | P2 - Technical Debt | Refactor when touching code | | Low | Low | P3 - Ignore | No action needed |
See REFACTORING-PATTERNS.md for specific techniques:
Complexity-Based:
Connascence-Based:
# Run complexity analysis again
python .claude/skills/refacter/scripts/analyze_complexity.py src/
# Ensure complexity decreased
# Run tests to ensure behavior unchanged
pytest tests/
| Metric | Good | Warning | Critical | Refactor Action | |--------|------|---------|----------|-----------------| | Cyclomatic Complexity | 1-10 | 11-20 | 21+ | Extract methods, simplify conditionals | | Cognitive Complexity | 1-15 | 16-25 | 26+ | Reduce nesting, early returns | | Lines of Code (LOC) | 1-50 | 51-100 | 101+ | Extract methods, split responsibilities | | Function Parameters | 1-4 | 5-6 | 7+ | Introduce parameter object |
Source: Based on industry standards (SonarQube, Code Climate, radon)
Symptom: Deeply nested if/else, multiple conditions Metric: High cyclomatic complexity (> 10) Solution: See REFACTORING-PATTERNS.md#simplify-conditionals
Symptom: Function > 50 lines, does many things Metric: High LOC, high cyclomatic complexity Solution: Extract Method pattern
Symptom: File changed in 20+ commits, cyclomatic > 15 Metric: Hotspot analysis shows P0 priority Solution: Add tests first, then refactor incrementally
Symptom: Same logic in multiple places Metric: No specific metric (manual detection) Solution: Extract common patterns, DRY principle
# Analyze specific directory
python .claude/skills/refacter/scripts/analyze_complexity.py src/agent/
# Analyze with thresholds
python .claude/skills/refacter/scripts/analyze_complexity.py src/ --max-cc 10 --max-cognitive 15
# Output to JSON for further processing
python .claude/skills/refacter/scripts/analyze_complexity.py src/ --json > complexity.json
# Analyze git hotspots (last 6 months)
python .claude/skills/refacter/scripts/analyze_hotspots.py src/
# Custom time range
python .claude/skills/refacter/scripts/analyze_hotspots.py src/ --since "3 months ago"
# Show top 10 hotspots
python .claude/skills/refacter/scripts/analyze_hotspots.py src/ --top 10
From CLAUDE.md global instructions:
"when ask to refactor, use code complexity analysis, and hotspot analysis to profile codebase."
Pattern: Only extract abstraction when you see the same pattern THREE times.
# ❌ BAD: Premature abstraction (seen once)
def process_single_case():
return generic_abstraction(params)
# ✅ GOOD: Wait for third occurrence
# First time: Write inline
# Second time: Note similarity
# Third time: Extract pattern
Connascence = Two components are connascent if changing one requires changing the other.
STATIC (Weakest - detectable at compile time)
├─ Connascence of Name (CoN) ← WEAKEST (acceptable)
├─ Connascence of Type (CoT) ← Weak (acceptable)
├─ Connascence of Meaning (CoM) ← Medium (should improve)
├─ Connascence of Position (CoP) ← Medium (should improve)
└─ Connascence of Algorithm (CoA) ← Strong (document clearly)
DYNAMIC (Strongest - only runtime detection)
├─ Connascence of Execution (CoE) ← Very Strong (refactor!)
├─ Connascence of Timing (CoT) ← Very Strong (refactor!)
├─ Connascence of Values (CoV) ← Strongest (critical!)
└─ Connascence of Identity (CoI) ← Strongest (critical!)
Always refactor from stronger → weaker forms:
| Current | Problem | Refactor To | Benefit | |---------|---------|-------------|---------| | CoV (Values) | Distributed transaction | Event-driven | No shared state | | CoE (Execution) | Must call in order | Encapsulate order | Hide complexity | | CoP (Position) | Positional params | Named params (CoN) | Self-documenting | | CoM (Meaning) | Magic numbers | Named constants (CoN) | Clear intent |
Rule: As distance increases, use weaker forms
See REFACTORING-PATTERNS.md for connascence-based refactoring examples.
.claude/skills/refacter/
├── SKILL.md # This file (entry point)
├── CODE-COMPLEXITY.md # Complexity metrics guide
├── HOTSPOT-ANALYSIS.md # Code churn + complexity
├── REFACTORING-PATTERNS.md # Common refactoring techniques
└── scripts/
├── analyze_complexity.py # Complexity analysis tool
└── analyze_hotspots.py # Hotspot detection tool
docs/CODE_STYLE.mdtools
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
testing
Write comprehensive tests following project conventions (tiers, patterns, anti-patterns). Use when writing tests, improving test coverage, fixing failing tests, or reviewing test quality.
content-media
Clone and customize existing templates (landing pages, dashboards, admin panels) with style extraction, config-driven content, and theme customization
development
Create high-converting B2B landing pages using psychological section sequencing. Use when building landing pages for services, agencies, consultants, or B2B products. Provides 14-section framework optimized for conversion psychology.