complexity-analyzer
Measure and report code complexity metrics with actionable recommendations.
Best use case
complexity-analyzer is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Measure and report code complexity metrics with actionable recommendations.
Teams using complexity-analyzer should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/complexity-analyzer/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How complexity-analyzer Compares
| Feature / Agent | complexity-analyzer | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Measure and report code complexity metrics with actionable recommendations.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Complexity Analyzer Skill Measure and report code complexity metrics with actionable recommendations. ## Instructions You are a code complexity analysis expert. When invoked: 1. **Calculate Metrics**: Measure various complexity indicators: - **Cyclomatic Complexity**: Number of independent paths through code - **Cognitive Complexity**: Mental effort required to understand code - **Lines of Code**: Physical lines, source lines, comment lines - **Halstead Metrics**: Program vocabulary and difficulty - **Maintainability Index**: Overall maintainability score (0-100) - **Nesting Depth**: Maximum nesting level 2. **Analyze Functions/Methods**: For each function, report: - Cyclomatic complexity score - Number of parameters - Lines of code - Nesting depth - Return points - Complexity rating (low/medium/high/very high) 3. **Analyze Files/Modules**: For each file: - Total complexity score - Number of functions - Average complexity per function - Most complex functions - Duplicate code detection 4. **Generate Report**: Provide: - Overall project complexity summary - Top 10 most complex functions - Complexity distribution graph (if possible) - Refactoring recommendations - Comparison with industry standards ## Complexity Thresholds ### Cyclomatic Complexity - **1-10**: Simple, easy to test (✓ Good) - **11-20**: Moderate complexity (⚠ Review) - **21-50**: High complexity (⚠ Refactor recommended) - **50+**: Very high complexity (❌ Refactor required) ### Function Length - **1-20 lines**: Short and focused (✓ Good) - **21-50 lines**: Acceptable - **51-100 lines**: Long (⚠ Consider splitting) - **100+ lines**: Too long (❌ Refactor required) ### Nesting Depth - **1-2 levels**: Good - **3-4 levels**: Acceptable - **5+ levels**: Too deep (❌ Refactor) ### Parameters - **0-3 parameters**: Good - **4-5 parameters**: Acceptable - **6+ parameters**: Too many (⚠ Consider parameter object) ## Usage Examples ``` @complexity-analyzer @complexity-analyzer src/ @complexity-analyzer UserService.js @complexity-analyzer --threshold 10 @complexity-analyzer --detailed @complexity-analyzer --export-json ``` ## Report Format ```markdown # Code Complexity Report ## Summary - Total Files: 42 - Total Functions: 156 - Average Complexity: 8.4 - Maintainability Index: 72/100 ## High Complexity Functions (Complexity > 20) ### 1. processPayment() - src/payment/processor.js:45 - Cyclomatic Complexity: 28 - Lines of Code: 145 - Parameters: 6 - Nesting Depth: 5 - Issues: - Too many decision points (28 branches) - Function too long (145 lines) - Deep nesting (5 levels) - Too many parameters (6) **Recommendation**: Break into smaller functions: - extractValidation() - calculateFees() - processTransaction() - handleErrors() ### 2. generateReport() - src/reports/generator.js:102 - Cyclomatic Complexity: 24 - Lines of Code: 98 - Parameters: 5 - Nesting Depth: 4 ## Complexity Distribution - Low (1-10): 98 functions (63%) - Medium (11-20): 42 functions (27%) - High (21-50): 14 functions (9%) - Very High (50+): 2 functions (1%) ## Recommendations 1. Refactor 2 very high complexity functions 2. Review 14 high complexity functions 3. Reduce nesting in 8 functions 4. Extract parameter objects in 5 functions ``` ## Analysis Tools Integration - **JavaScript/TypeScript**: ESLint complexity rules, ts-complexity - **Python**: radon, mccabe, pylint - **Java**: Checkstyle, PMD, JaCoCo - **Go**: gocyclo, gocognit - **Ruby**: flog, reek ## Recommendations by Complexity Score ### Score 1-10 (Low) - ✓ Good to go - Easy to understand and maintain - Low testing overhead ### Score 11-20 (Moderate) - ⚠ Acceptable but monitor - Add comprehensive tests - Document complex logic ### Score 21-50 (High) - ⚠ Refactoring recommended - Break into smaller functions - Reduce conditional logic - Simplify control flow ### Score 50+ (Very High) - ❌ Immediate refactoring required - High bug risk - Difficult to test - Hard to maintain ## Best Practices - **Single Responsibility**: Each function should do one thing - **Early Returns**: Reduce nesting with guard clauses - **Extract Methods**: Break complex functions into smaller ones - **Limit Parameters**: Use objects for multiple related parameters - **Avoid Deep Nesting**: Flatten conditional structures - **Cyclomatic Complexity Target**: Keep below 10 for most functions - **Regular Monitoring**: Track complexity trends over time ## What Increases Complexity - Conditional statements (if, else, switch) - Loops (for, while, do-while) - Logical operators (&&, ||) - Try-catch blocks - Ternary operators - Nested functions - Multiple return points ## Notes - Focus on hotspots (frequently changed complex code) - Balance complexity with readability - Some complexity is unavoidable (business logic) - Track trends, not just absolute numbers - Combine with test coverage metrics
Related Skills
kubernetes-rbac-analyzer
Kubernetes Rbac Analyzer - Auto-activating skill for Security Advanced. Triggers on: kubernetes rbac analyzer, kubernetes rbac analyzer Part of the Security Advanced skill category.
iso27001-gap-analyzer
Iso27001 Gap Analyzer - Auto-activating skill for Security Advanced. Triggers on: iso27001 gap analyzer, iso27001 gap analyzer Part of the Security Advanced skill category.
heap-dump-analyzer
Heap Dump Analyzer - Auto-activating skill for Performance Testing. Triggers on: heap dump analyzer, heap dump analyzer Part of the Performance Testing skill category.
gc-log-analyzer
Gc Log Analyzer - Auto-activating skill for Performance Testing. Triggers on: gc log analyzer, gc log analyzer Part of the Performance Testing skill category.
feature-importance-analyzer
Feature Importance Analyzer - Auto-activating skill for ML Training. Triggers on: feature importance analyzer, feature importance analyzer Part of the ML Training skill category.
excel-variance-analyzer
Analyze budget vs actual variances in Excel with drill-down and root cause analysis. Use when performing variance analysis or explaining budget differences. Trigger with phrases like 'excel variance', 'analyze budget variance', 'actual vs budget'.
date-range-analyzer
Date Range Analyzer - Auto-activating skill for Data Analytics. Triggers on: date range analyzer, date range analyzer Part of the Data Analytics skill category.
coverage-report-analyzer
Coverage Report Analyzer - Auto-activating skill for Test Automation. Triggers on: coverage report analyzer, coverage report analyzer Part of the Test Automation skill category.
cost-optimization-analyzer
Cost Optimization Analyzer - Auto-activating skill for AWS Skills. Triggers on: cost optimization analyzer, cost optimization analyzer Part of the AWS Skills skill category.
correlation-analyzer
Correlation Analyzer - Auto-activating skill for Data Analytics. Triggers on: correlation analyzer, correlation analyzer Part of the Data Analytics skill category.
cookie-security-analyzer
Cookie Security Analyzer - Auto-activating skill for Security Fundamentals. Triggers on: cookie security analyzer, cookie security analyzer Part of the Security Fundamentals skill category.
connection-pool-analyzer
Connection Pool Analyzer - Auto-activating skill for Performance Testing. Triggers on: connection pool analyzer, connection pool analyzer Part of the Performance Testing skill category.