complexity
Analyze code complexity and find refactor targets using radon/gocyclo. Triggers: "complexity", "analyze complexity", "find complex code", "refactor targets", "cyclomatic complexity", "code metrics".
Best use case
complexity is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Analyze code complexity and find refactor targets using radon/gocyclo. Triggers: "complexity", "analyze complexity", "find complex code", "refactor targets", "cyclomatic complexity", "code metrics".
Teams using complexity 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/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How complexity Compares
| Feature / Agent | complexity | 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?
Analyze code complexity and find refactor targets using radon/gocyclo. Triggers: "complexity", "analyze complexity", "find complex code", "refactor targets", "cyclomatic complexity", "code metrics".
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.
Related Guides
SKILL.md Source
# Complexity Skill **YOU MUST EXECUTE THIS WORKFLOW. Do not just describe it.** Analyze code complexity to identify refactoring targets. ## Execution Steps Given `$complexity [path]`: ### Step 1: Determine Target **If path provided:** Use it directly. **If no path:** Use current directory or recent changes: ```bash git diff --name-only HEAD~5 2>/dev/null | grep -E '\.(py|go)$' | head -10 ``` ### Step 2: Detect Language ```bash # Check for Python files ls *.py **/*.py 2>/dev/null | head -1 && echo "Python detected" # Check for Go files ls *.go **/*.go 2>/dev/null | head -1 && echo "Go detected" ``` ### Step 3: Run Complexity Analysis **For Python (using radon):** ```bash # Check if radon is installed which radon || pip install radon # Run cyclomatic complexity radon cc <path> -a -s # Run maintainability index radon mi <path> -s ``` **For Go (using gocyclo):** ```bash # Check if gocyclo is installed which gocyclo || go install github.com/fzipp/gocyclo/cmd/gocyclo@latest # Run complexity analysis gocyclo -over 10 <path> ``` ### Step 4: Interpret Results **Cyclomatic Complexity Grades:** | Grade | CC Score | Meaning | |-------|----------|---------| | A | 1-5 | Low risk, simple | | B | 6-10 | Moderate, manageable | | C | 11-20 | High risk, complex | | D | 21-30 | Very high risk | | F | 31+ | Untestable, refactor now | ### Step 5: Identify Refactor Targets List functions/methods that need attention: - CC > 10: Should refactor - CC > 20: Must refactor - CC > 30: Critical, immediate action ### Step 6: Write Complexity Report **Write to:** `.agents/complexity/YYYY-MM-DD-<target>.md` ```markdown # Complexity Report: <Target> **Date:** YYYY-MM-DD **Language:** <Python/Go> **Files Analyzed:** <count> ## Summary - Average CC: <score> - Highest CC: <score> in <function> - Functions over threshold: <count> ## Refactor Targets ### Critical (CC > 20) | Function | File | CC | Recommendation | |----------|------|-----|----------------| | <name> | <file:line> | <score> | <how to simplify> | ### High (CC 11-20) | Function | File | CC | Recommendation | |----------|------|-----|----------------| | <name> | <file:line> | <score> | <how to simplify> | ## Refactoring Recommendations 1. **<Function>**: <specific suggestion> - Extract: <what to extract> - Simplify: <how to simplify> ## Next Steps - [ ] Address critical complexity first - [ ] Create issues for high complexity - [ ] Consider refactoring sprint ``` ### Step 7: Report to User Tell the user: 1. Overall complexity summary 2. Number of functions over threshold 3. Top 3 refactoring targets 4. Location of full report 5. Run `$refactor <function>` to address critical complexity targets ## See Also - [refactor](../refactor/SKILL.md) — Safe, verified refactoring for complexity targets ## Key Rules - **Use the right tool** - radon for Python, gocyclo for Go - **Focus on high CC** - prioritize 10+ - **Provide specific fixes** - not just "refactor this" - **Write the report** - always produce artifact ## Quick Reference **Simplifying High Complexity:** - Extract helper functions - Replace conditionals with polymorphism - Use early returns - Break up long functions - Simplify nested loops ## Examples ### Analyzing Python Project **User says:** `$complexity src/` **What happens:** 1. Agent detects Python files in `src/` directory 2. Agent checks for radon installation, installs if missing 3. Agent runs `radon cc src/ -a -s` for cyclomatic complexity 4. Agent runs `radon mi src/ -s` for maintainability index 5. Agent identifies 3 functions with CC > 20, 7 functions with CC 11-20 6. Agent writes detailed report to `.agents/complexity/2026-02-13-src.md` 7. Agent recommends extracting nested conditionals in `process_request()` function **Result:** Complexity report identifies `process_request()` (CC: 28) as critical refactor target with specific extraction recommendations. ### Finding Refactor Targets in Go Module **User says:** `$complexity` **What happens:** 1. Agent checks recent changes with `git diff --name-only HEAD~5` 2. Agent detects Go files, verifies gocyclo installation 3. Agent runs `gocyclo -over 10 ./...` on project 4. Agent finds `HandleWebhook()` function with complexity 34 5. Agent writes report with recommendation to extract validation logic 6. Agent reports top 3 targets: HandleWebhook (34), ProcessBatch (22), ValidateInput (15) **Result:** Critical function identified for immediate refactoring with actionable extraction plan. ## Troubleshooting | Problem | Cause | Solution | |---------|-------|----------| | Tool not installed (radon/gocyclo) | Missing dependency | Agent auto-installs: `pip install radon` for Python or `go install github.com/fzipp/gocyclo/cmd/gocyclo@latest` for Go. Verify install path in $PATH. | | No complexity issues found | Threshold too high or genuinely simple code | Lower threshold: try `gocyclo -over 5` or check if path includes actual implementation files vs tests. | | Report shows functions without recommendations | Generic analysis without codebase context | Read the high-CC functions to understand structure, then provide specific refactoring suggestions based on actual code patterns. | | Mixed language project | Multiple languages in target path | Run analysis separately per language: `$complexity src/python/` then `$complexity src/go/`, combine reports manually. | ## Local Resources ### scripts/ - `scripts/validate.sh`
Related Skills
vibe
Comprehensive code validation. Runs complexity analysis then multi-model council. Answer: Is this code ready to ship? Triggers: "vibe", "validate code", "check code", "review code", "code quality", "is this ready".
validation
Full validation phase orchestrator. Vibe + post-mortem + retro + forge. Reviews implementation quality, extracts learnings, feeds the knowledge flywheel. Triggers: "validation", "validate", "validate work", "review and learn", "validation phase", "post-implementation review".
update
Reinstall all AgentOps skills globally from the latest source. Triggers: "update skills", "reinstall skills", "sync skills".
trace
Trace design decisions and concepts through session history, handoffs, and git. Triggers: "trace decision", "how did we decide", "where did this come from", "design provenance", "decision history".
test
Test generation, coverage analysis, and TDD workflow. Triggers: "test", "generate tests", "test coverage", "write tests", "tdd", "add tests", "test strategy", "missing tests", "coverage gaps".
status
Single-screen dashboard showing current work, recent validations, flywheel health, and suggested next action. Triggers: "status", "dashboard", "what am I working on", "where was I".
standards
Language-specific coding standards and validation rules. Provides Python, Go, Rust, TypeScript, Shell, YAML, JSON, and Markdown standards. Auto-loaded by $vibe, $implement, $doc, $bug-hunt, $complexity based on file types.
shared
Shared reference documents for multi-agent skills (not directly invocable)
security
Continuous repository security scanning and release gating. Triggers: "security scan", "security audit", "pre-release security", "run scanners", "check vulnerabilities".
security-suite
Composable security suite for binary and prompt-surface assurance, static analysis, dynamic tracing, repo-native redteam scans, contract capture, baseline drift, and policy gating. Triggers: "binary security", "reverse engineer binary", "black-box binary test", "behavioral trace", "baseline diff", "prompt redteam", "security suite".
scenario
Author and manage holdout scenarios for behavioral validation. Scenarios are stored in .agents/holdout/ where implementing agents cannot see them. Triggers: "$scenario", "holdout", "behavioral scenario", "create scenario", "list scenarios".
scaffold
Project scaffolding, component generation, and boilerplate setup. Triggers: "scaffold", "new project", "init project", "create project", "generate component", "setup project", "starter", "boilerplate".