agentleFS
Smaui94Smaui94/ClaudeSkillCollection/complexity-check/SKILL.md

complexity-check

Skill0 starsChanged 9 days agoMITView on GitHub

Find overly complex code - long functions, deep nesting, many parameters, high cyclomatic complexity, large classes and files, duplicated code blocks - using documented, user-overridable thresholds, in any language. Reports hotspots and refactoring directions without rewriting code. Use when asked to check/review/analyze complexity, code smells, maintainability, long functions, duplication or "where is my code too complicated".

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Check the files/directories the user names, otherwise the whole repo.

    line 11
  2. Distinctive:

    Prefer a metrics tool if installed (never install it.

    line 31
  3. Distinctive:

    Every finding has a concrete location and measured value.

    line 56
  4. Distinctive:

    Do not change code. Refactor only when the user explicitly asks for it.

    line 59

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Complexity check

Review only: report hotspots and name a refactoring direction, never rewrite code unless the user explicitly asks.

Scope

Check the files/directories the user names, otherwise the whole repo. Skip .git/, build output, vendor/, node_modules/, .venv/, generated code, minified files, migrations and test fixtures/data files.

Thresholds

Defaults below. The user can override any of them ("max function length 30", "nesting 2"); state the thresholds used at the top of the report.

IDMetricwarningerror
CX1function length (lines without blank lines and comments)> 50> 100
CX2nesting depth (blocks inside a function)> 3> 5
CX3parameters per function> 5> 7
CX4cyclomatic complexity per function> 10> 20
CX5file length (lines)> 500> 1000
CX6class size: methods / lines> 20 / > 500> 40 / > 1000
CX7duplicated block (≥ 10 similar lines)2 copies≥ 3 copies
CX8boolean condition with many operators (&&, ||, and, or)> 3> 5
CX9if/else if chain or switch cases> 7> 15

Cyclomatic complexity, when counted by hand: 1 + one for each if, elif/else if, for, while, case, catch/except, &&/and, ||/or, ?:, and each comprehension condition.

Steps

  1. Prefer a metrics tool if installed (never install it; say which one would help if none is found):
    • lizard (many languages): lizard -C 10 -L 50 -a 5 -w <dirs> (excludes: -x "./node_modules/*")
    • Python: radon cc -s -n C <dir>, radon raw; JS/TS: ESLint complexity, max-depth, max-params, max-lines-per-function
    • Duplication: jscpd --min-lines 10 <dir>, PMD CPD
  2. Without tools: find the longest files (wc -l), then the longest functions in them, and measure CX1-CX4, CX8, CX9 by reading the code. Look for repeated blocks in files of the same kind for CX7.
  3. Rank hotspots: functions that exceed several thresholds first, then by how central they are (many callers, often changed: git log --format= --name-only | sort | uniq -c | sort -rn | head when git is available).
  4. Report (format below).

Refactoring directions (name, don't implement)

  • Long function → extract well-named steps; separate I/O from logic
  • Deep nesting → guard clauses / early return, extract inner loop body
  • Many parameters → parameter object, builder, or the function does too much
  • High complexity / long if chains → lookup table, polymorphism, strategy, splitting by case
  • Large class → split by responsibility (look at which fields each method uses)
  • Duplication → shared function; only when the copies really change together
  • Complex condition → named boolean variables or predicate functions

False positives to drop

Generated code, data tables and long-but-flat configuration code (e.g. a switch mapping enum values to strings, CX9 info at most) · test files with many similar cases (CX7) · parsers/state machines where one big switch is the clearest form (report as info with a note).

Report

In the user's language. First the thresholds used, then hotspots ranked worst-first:

path/to/file:line - error|warning|info - <ID> <metric> - `functionName`: <value> (threshold <limit>) - <why it hurts here> - direction: <refactoring direction>
  • Every finding has a concrete location and measured value. Mark estimated values (counted by hand) as "approx.".
  • Group several metrics of one function into one finding.
  • End with a summary: findings per severity, top 5 hotspots, then the 3 most important things to tackle first.
  • Do not change code. Refactor only when the user explicitly asks for it.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.