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.zipInstalls 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 neKey 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
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
| Parameter | Required | Description |
|---|---|---|
SCOPE | Yes | Module or file path to audit (e.g. payments/processor.py). Exactly one file. |
CONTEXT | Yes | CLAUDE.md project context — its coding standards define the thresholds (line limits, type hints). |
MAX_FUNCTION_LINES | No | Override 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 Run | Input | Expected Output | Actual Output | Pass? |
|---|---|---|---|---|
| 1 — Typical | payments/processor.py + CLAUDE.md | Hotspot table; flags untyped public fns + unused Optional/STRIPE_API_KEY const; metrics labelled approximate; no security commentary | All 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 case | payments/webhook.py + CLAUDE.md | Hotspot table for a differently-shaped module; standards violations with file:line; no security/test leakage | All 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 — Minimal | test-fixtures/empty_module.py + CLAUDE.md | All four sections present; "no hotspots / none found"; no invented complexity | All 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.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| complexity-audit (this skill) | 0 | 1mo | No flags | Intermediate |
| python-design-patterns | 19 | 2mo | No flags | Intermediate |
| python-patterns | 6 | 2mo | Review | Beginner |
| modular-code | 4 | 7mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
python-design-patterns
wshobson
Python design patterns including KISS, Separation of Concerns, Single Responsibility, and composition over inheritance. Use when making architecture decisions, refactoring code structure, or evaluating when abstractions are appropriate.
python-patterns
affaan-m
Pythonic 惯用法、PEP 8 标准、类型提示以及构建健壮、高效、可维护的 Python 应用程序的最佳实践。
modular-code
parcadei
Modular Code Organization
ast-grep-find
parcadei
AST-based code search and refactoring via ast-grep MCP
pyrefly-type-coverage
pytorch
Migrate a file to use stricter Pyrefly type checking with annotations required for all functions, classes, and attributes.
naming-analyzer
davila7
Suggest better variable, function, and class names based on context and conventions.