Refactor code to reduce cyclomatic complexity so it stays readable, maintainable, and aligned with the long-term vision of the codebase, not just optimized for AI comprehension. Use whenever the user asks to refactor, simplify, clean up, or review code quality; mentions complexity, maintainability, readability, spaghetti code, deeply nested logic, or god functions; or asks to check AI-generated code before merging. Also use proactively after writing any nontrivial function with heavy branching.
npx skills add https://github.com/saurabhkumar8112/cyclomatic-complexity-skill --skill cyclomatic-complexity
Purpose: AI-written code often works but branches like a jungle. This skill: measure complexity, refactor hotspots, keep code human-maintainable.
CC = decision points + 1. Decision points: if, else if, case, loops, catch, ternary, &&, || in conditions.
Project linter config wins. If eslintrc, radon config, sonar config, or similar sets a complexity threshold, use that. No config: use defaults below.
Thresholds:
Prefer real tools over eyeballing when environment allows:
radon cc -s -a <path>complexity rulegocyclolizard <path>No tool available: count manually, per function, show the count.
if (isEligibleForRefund(order)) beats a 4-clause boolean soup.End every refactor with:
## Complexity report
| Function | Before | After |
|----------|--------|-------|
| parseOrder | 14 | 4 |
Extracted: validateHeader, resolveDiscount
Behavior verified: <how>
Keep prose minimal. Numbers and diffs do the talking.
Take saurabhkumar8112/cyclomatic-complexity from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.