CO

complexity-audit

Analyzes Python code for complexity and maintainability, flagging areas that are hard to change or test.

Install

mkdir -p .claude/skills/complexity-audit && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/11632" && unzip -o skill.zip -d .claude/skills/complexity-audit && rm skill.zip

Installs to .claude/skills/complexity-audit

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

This Skill performs a **maintainability and complexity audit** of a single Python module and emits a structured Markdown report of complexity hotspots. Use it when you want to find the functions most likely to harbour bugs or resist change — those that are too long, too deeply ne
280 chars · catalog description✓ has a “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Intermediate

Key capabilities

  • Identify functions that are too long
  • Detect deeply nested code structures
  • Flag functions with too many parameters
  • Find single-responsibility violations
  • Report missing type hints on public functions

How it works

The skill audits a Python module for maintainability and complexity by analyzing function length, cyclomatic complexity, nesting depth, parameter count, and type hint adherence against project standards.

Inputs & outputs

You give it
A single Python module file path and project context (CLAUDE.md)
You get back
A Markdown report detailing complexity hotspots, standards violations, and dead/unused code

When to use complexity-audit

  • Identifying technical debt
  • Reviewing code for maintainability
  • Refactoring complex modules

About this skill

Skill: Complexity Audit

Version: 1.0.0

Status: draft

Owner: M. Williams / Security Engineering

Category: code-quality

Created: 2026-06-23


Purpose

This Skill performs a maintainability and complexity audit of a single Python module and emits a structured Markdown report of complexity hotspots. Use it when you want to find the functions most likely to harbour bugs or resist change — those that are too long, too deeply nested, take too many parameters, or carry too many responsibilities. It flags each hotspot with an approximate complexity signal, the standard it violates (e.g. CLAUDE.md's "functions ≤ 40 lines"), and a one-line refactor direction. It is a quality lens only: it does not assess security or correctness, and its metrics are heuristic estimates, not a substitute for a calibrated tool like radon or ruff.


Input

ParameterRequiredDescription
SCOPEYesModule or file path to audit (e.g. payments/processor.py). Exactly one file.
CONTEXTYesCLAUDE.md project context — its coding standards define the thresholds (line limits, type hints).
MAX_FUNCTION_LINESNoOverride the per-function line threshold. Defaults to the CLAUDE.md value (40).

Prompt

You are a senior engineer performing a code maintainability and complexity audit.
Your job is to identify the parts of the module most likely to be hard to test,
hard to change, or bug-prone, and to quantify why.

SCOPE: {{SCOPE}} only.

FOCUS ONLY ON:
- Function length vs the project limit (default {{MAX_FUNCTION_LINES}}=40 lines per
  CLAUDE.md; use {{CONTEXT}} to confirm the standard)
- Cyclomatic-complexity signals (branches, loops, try/except, boolean operators) —
  give an APPROXIMATE count and label it approximate
- Nesting depth, parameter count, and single-responsibility violations
- Missing type hints on public functions where the standard requires them
- Dead or unreachable code, unused imports/constants

DO NOT:
- Review security (no OWASP/CWE/vulnerabilities — a Security Skill owns that)
- Write or design tests
- Rewrite the module or deliver a refactored file (one-line refactor direction only)
- Report subjective style/naming preferences not backed by a CLAUDE.md standard
- Present heuristic metrics as exact tool output — always label them approximate

You will receive: CLAUDE.md ({{CONTEXT}}) + the source at {{SCOPE}}. Treat
CLAUDE.md coding standards as the rule set.

OUTPUT FORMAT:
A single Markdown document with EXACTLY these sections. No preamble.

## Complexity Hotspots
A table, sorted worst-first:
| Function | Lines | ~Cyclomatic | Nesting | Params | Standard Violated | Refactor Direction |

## Standards Violations
Bullet list of concrete CLAUDE.md standard breaches (e.g. "missing type hints on
all public functions", "module constant unused"), each with file:line.

## Dead / Unused Code
Bullet list of unused imports, constants, or unreachable branches with file:line,
or "none found".

## SUMMARY
Two sentences: the single worst hotspot and the module's overall maintainability
posture (low / medium / high risk to change).

All metrics are approximate heuristics. No security commentary. No tests. No full code.

Output Spec

Markdown with four sections. Concrete example (fake data):

## Complexity Hotspots
| Function | Lines | ~Cyclomatic | Nesting | Params | Standard Violated | Refactor Direction |
|---|---|---|---|---|---|---|
| `sync_orders` | 78 | ~12 | 4 | 6 | >40 lines; >5 params | Extract the retry block and the mapping block into helpers. |

## Standards Violations
- `billing/sync.py:1` — no type hints on any public function (CLAUDE.md requires them).

## Dead / Unused Code
- `billing/sync.py:9` — `import json` never used.

## SUMMARY
`sync_orders` is the worst hotspot at ~78 lines and 6 parameters. The module is
medium-to-high risk to change until that function is decomposed.

Limitations

  • Heuristic, not measured. Cyclomatic complexity and line counts are model estimates; for authoritative numbers run radon cc / ruff — this Skill points you at where to look, not exact scores.
  • Does NOT cover security (use Security OWASP Review) or correctness/tests (use the Unit Test Generator). A complex function is not necessarily insecure or wrong.
  • Single-file scope only; cannot see cross-module coupling or call-graph fan-out.
  • Dead-code detection is conservative and intra-file only — code reachable only via dynamic dispatch, reflection, or other modules may be wrongly flagged or missed.
  • Reliability degrades on files longer than ~500 lines — chunk and re-run.
  • On empty/minimal input it reports "no hotspots / no violations" rather than inventing complexity.

Tests

Test RunInputExpected OutputActual OutputPass?
1 — Typicalpayments/processor.py + CLAUDE.mdHotspot table; flags untyped public fns + unused Optional/STRIPE_API_KEY const; metrics labelled approximate; no security commentaryAll 4 sections present; worst-first hotspot table produced; flagged missing type hints on public fns and the unused Optional import + unused STRIPE_API_KEY constant as dead/unused code; metrics labelled approximate. The hardcoded key + SQL lines were treated strictly as maintainability/dead-code items — no vulnerability commentary. Output: test-runs/complexity_processor.md.
2 — Edge casepayments/webhook.py + CLAUDE.mdHotspot table for a differently-shaped module; standards violations with file:line; no security/test leakageAll 4 sections present for the differently-shaped module. The hardcoded secret and MD5 signature were treated strictly as coding-standard / config-hygiene deviations (maintainability), not vulnerabilities; metrics labelled approximate; no test commentary. Output: test-runs/complexity_webhook.md.
3 — Minimaltest-fixtures/empty_module.py + CLAUDE.mdAll four sections present; "no hotspots / none found"; no invented complexityAll 4 sections present; every section reports zero ("no hotspots — no functions defined", "none", "none found"). No complexity invented. Output: test-runs/complexity_empty.md.

Issues found / wording updates during testing: None. Scope discipline held even when the auditor encountered security-relevant lines (it reframed them as maintainability/dead-code, never as vulnerabilities). No prompt wording changes required for v1.0.0.


Changelog

v1.0.0 — 2026-06-23

  • Initial release.
  • Tested on: OrderFlow sample repo (payments/processor.py, payments/webhook.py, empty fixture).
  • Tested by: M. Williams.

When not to use it

  • When reviewing security vulnerabilities
  • When writing or designing tests
  • When rewriting the module or delivering a refactored file

Limitations

  • Metrics are heuristic estimates, not a substitute for a calibrated tool
  • Does NOT cover security or correctness/tests
  • Single-file scope only; cannot see cross-module coupling

How it compares

This skill provides a structured, heuristic-based audit of Python code complexity against defined project standards, offering refactoring directions without performing the refactoring itself, unlike a full code analysis tool.

Compared to similar skills

complexity-audit side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
complexity-audit (this skill)01moNo flagsIntermediate
python-design-patterns192moNo flagsIntermediate
python-patterns62moReviewBeginner
modular-code47moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry