cyclomatic-complexity

cyclomatic-complexity is a skill for Claude Code, Codex from saurabhkumar8112/cyclomatic-complexity-skill. It costs 103 tokens per session (727 once invoked), scanned A, original, Apache-2.0.

A guide for reducing cyclomatic complexity, which is a measure of how many decision paths a function has. It recommends ways to make code easier for people to read and maintain.

In plain words
What is it for?
Use it when refactoring, simplifying, or reviewing code quality. It covers complexity thresholds and techniques such as early returns, extracted functions, lookup tables, and named conditions.
Why use it?
Highly branched code is harder to understand, test, and change. Measuring complexity first helps focus refactoring on the functions most likely to cause problems.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/saurabhkumar8112/cyclomatic-complexity-skill/cyclomatic-complexity
Any agent
npx skills add saurabhkumar8112/cyclomatic-complexity-skill --skill cyclomatic-complexity
Clone the repo
git clone --depth 1 https://github.com/saurabhkumar8112/cyclomatic-complexity-skill

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cyclomatic-complexity

README.md
[![agentmods](https://agentmods.dev/badge/skills/saurabhkumar8112/cyclomatic-complexity-skill/cyclomatic-complexity.svg)](https://agentmods.dev/skills/saurabhkumar8112/cyclomatic-complexity-skill/cyclomatic-complexity)
Your own site
<a href="https://agentmods.dev/skills/saurabhkumar8112/cyclomatic-complexity-skill/cyclomatic-complexity"><img src="https://agentmods.dev/badge/skills/saurabhkumar8112/cyclomatic-complexity-skill/cyclomatic-complexity.svg" alt="Measured on agentmods" height="20"></a>
Per session 103 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 727 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00103 $0.00727
Opus 5 $0.00051 $0.00364
Sonnet 5 $0.00021 $0.00145
Haiku 4.5 $0.00010 $0.00073

Measured 5d ago against content hash 6e8edae7a225, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

cyclomatic-complexity scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/cyclomatic-complexity/SKILL.md · 70 lines

How it starts

The opening of the file, as written. The whole thing — 70 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Cyclomatic Complexity

Purpose: AI-written code often works but branches like a jungle. This skill: measure complexity, refactor hotspots, keep code human-maintainable.

Measure first

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:

  • 1-5: fine, leave alone
  • 6-10: watch, refactor if touching anyway
  • 11-15: refactor now
  • 15+: must split, no debate

Prefer real tools over eyeballing when environment allows:

  • Python: radon cc -s -a <path>
  • JS/TS: eslint complexity rule
  • Go: gocyclo
  • Polyglot: lizard <path>

No tool available: count manually, per function, show the count.

Refactor tactics, in order of preference

  1. Guard clauses. Invert conditions, return early, kill nesting.
  2. Extract function. Each extracted piece gets a name that says what, not how. Names are documentation.
  3. Lookup table / map instead of if-else or switch chains.
  4. Named predicates. if (isEligibleForRefund(order)) beats a 4-clause boolean soup.
  5. Polymorphism / strategy for switch-on-type. Only when the switch appears in 2+ places.
  6. Flatten loops. Extract loop body, use continue instead of nested if.

Hard rules

  • Preserve behavior. Run tests before and after. No tests: say so, suggest adding, refactor conservatively.
  • Don't game the metric. A dense one-liner hiding 6 branches is worse than the honest if-chain it replaced. Complexity should move into well-named units, not disappear into cleverness.
  • Don't break public APIs or exported signatures without asking.
  • Small functions with clear names > few functions with comments explaining sections.
  • One responsibility per function. If the name needs "and", split.

Workflow

  1. Measure all touched functions, rank by CC descending.
  2. Report hotspots with numbers before touching anything.
  3. Refactor worst first, one function at a time.
  4. Re-measure. Show before/after table: function, CC before, CC after.
  5. Verify: tests pass, behavior unchanged, diff reviewable.

Read the full file on GitHub · 70 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 70 lines · 103 tokens per session scan A 6e8edae7a225

Subscribe to this mod's changes

cyclomatic-complexity is a skill published in the GitHub repository saurabhkumar8112/cyclomatic-complexity-skill (346 stars, last pushed 9d ago), licensed Apache-2.0. It adds 103 tokens to every session and 727 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

software-code-refactoring

Improve production code quality while preserving all existing test behavior. Commonly used for the Refactor phase of TDD red-green-refactor, but applicable to any codebase with tests. Use when production code works but needs cleanup — reducing duplication, improving naming, simplifying complexity, aligning with…

stencila/stencila · 102 tokens

simplify-codebase

Simplification audit or authorized codebase simplification whose stated objective is to remove accidental complexity. Use for evidence-backed deletion or consolidation of dead code, duplicate state, redundant APIs or layers, ownerless abstractions, obsolete compatibility or design records, and over-engineering in any…

tt-a1i/simplify-codebase · 93 tokens

refactor

Refactor code to improve structure and maintainability.

vstorm-co/pydantic-deepagents · 12 tokens

absolute-simplify

Use when the user wants to simplify, clean up, refactor, tidy, or refine code — their staged/unstaged git changes or a target file/path. Reduces complexity, flattens nesting, removes redundancy and dead code, scores each change by value (holding low-value churn), then runs tests to prove nothing broke. Invoke on…

maddhruv/absolute · 178 tokens

techdebt

Find and fix technical debt including duplicated code, dead code, outdated patterns, and code smells. Run at the end of sessions to clean up.

brycewang-stanford/Auto-Empirical-Research-Skills · 33 tokens

code-quality-review

Run a maintainability and structure review focused on abstraction quality, branching complexity, file growth, canonical ownership, duplication, and refactoring opportunities. Use when the user asks for code quality review, maintainability review, 代码质量审查, 可维护性审查, or comments about whether the change stays easy to…

bahayonghang/my-ai-cli-toolkit · 149 tokens