Code Complexity Analyzer
by @charlie-morrison
Measure cyclomatic complexity, cognitive complexity, and structural metrics for Python, JavaScript/TypeScript, and Go code. Use when analyzing code quality,...
clawhub install code-complexity-analyzerπ About This Skill
name: code-complexity-analyzer description: Measure cyclomatic complexity, cognitive complexity, and structural metrics for Python, JavaScript/TypeScript, and Go code. Use when analyzing code quality, finding complex functions, setting CI quality gates, reviewing code for refactoring candidates, or generating complexity reports. Supports per-function metrics, configurable thresholds, risk levels, and multiple output formats (text, JSON, markdown).
Code Complexity Analyzer
Measure cyclomatic, cognitive, and structural complexity per function. Pure Python, no dependencies.
Quick Start
# Analyze a directory
python3 scripts/analyze_complexity.py src/Analyze specific files
python3 scripts/analyze_complexity.py app.py utils.pyShow all functions (not just violations)
python3 scripts/analyze_complexity.py src/ --verboseCustom thresholds
python3 scripts/analyze_complexity.py src/ --cc 15 --cog 20 --max-lines 80
Output Formats
python3 scripts/analyze_complexity.py src/ --format text # human-readable (default)
python3 scripts/analyze_complexity.py src/ --format json # CI/tooling
python3 scripts/analyze_complexity.py src/ --format markdown # reports
Supported Languages
.py).js, .jsx, .mjs, .cjs).ts, .tsx).go)Metrics
| Metric | Description | Default Threshold | |--------|-------------|-------------------| | Cyclomatic (CC) | Independent execution paths | β€10 | | Cognitive (COG) | Perceived difficulty to understand (nesting-weighted) | β€15 | | Lines | Function length | β€50 | | Params | Parameter count | β€5 | | Nesting | Max nesting depth | β€4 |
Risk Levels
Options
--cc N Cyclomatic threshold (default: 10)
--cog N Cognitive threshold (default: 15)
--max-lines N Function length threshold (default: 50)
--max-params N Parameter count threshold (default: 5)
--max-nesting N Nesting depth threshold (default: 4)
--exclude DIR Additional directories to exclude
--verbose, -v Show all functions, not just violations
Auto-excluded: node_modules, .git, __pycache__, venv, dist, build.
Exit Codes
0 β no violations1 β violations found (functions exceed CC or COG thresholds)2 β no analyzable files foundπ‘ Examples
# Analyze a directory
python3 scripts/analyze_complexity.py src/Analyze specific files
python3 scripts/analyze_complexity.py app.py utils.pyShow all functions (not just violations)
python3 scripts/analyze_complexity.py src/ --verboseCustom thresholds
python3 scripts/analyze_complexity.py src/ --cc 15 --cog 20 --max-lines 80
βοΈ Configuration
--cc N Cyclomatic threshold (default: 10)
--cog N Cognitive threshold (default: 15)
--max-lines N Function length threshold (default: 50)
--max-params N Parameter count threshold (default: 5)
--max-nesting N Nesting depth threshold (default: 4)
--exclude DIR Additional directories to exclude
--verbose, -v Show all functions, not just violations
Auto-excluded: node_modules, .git, __pycache__, venv, dist, build.