/corgi:complexityfrom corgi
Measures cyclomatic and cognitive complexity of changed code, refactors the worst function first, and verifies behavior is preserved. Use when code needs simplification.
Ships in corgi. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Done when: in refactor mode, the worst touched function is under the repo's bar, re-measured, and its tests pass; in report and gate mode, the table or the verdict line is printed.
Generated code branches like a jungle: it works, then every later edit walks the whole jungle again. This skill keeps changed code readable by measuring per-function complexity against the repo's own bar, refactoring the worst function first, and proving behaviour did not move. Three modes:
review runs on a PR.stories runs before its per-service gate./corgi-complexity.Scope is the diff, not the repo: touched functions versus <base>. A whole-repo
scan ("where are the hotspots") is a separate ask and stays read-only unless the user
picks a target.
if,
else if, case, every loop, catch, the ternary, and each && / || inside a
condition. Per function, never per file.switch scores lower than a nested if ladder with the
same CC. A refactor that lowers CC and raises cognitive complexity made the code
harder to read - revert it.Read the repo's own threshold before applying a default, and use it verbatim:
| Where | Key |
|---|---|
.golangci.yml | gocyclo.min-complexity, gocognit.min-complexity |
| eslint config | complexity: [.., N], sonarjs/cognitive-complexity |
setup.cfg / pyproject.toml / radon.cfg | radon / xenon max-absolute, max-average |
.rubocop.yml | Metrics/CyclomaticComplexity: Max, Metrics/PerceivedComplexity |
sonar-project.properties + the Sonar quality gate | sonar.*.complexity conditions |
No config → 10 is the threshold, with these bands: 1-5 fine, 6-10 refactor only if
you are in the function anyway, 11-15 refactor now, over 15 split. When a stack picks a
default and .corgi/memory/ exists, record it as a decision fact (confirm first - the
memory skill) so the next run does not re-derive it.
Touched files: git -C <dir> diff <base>...HEAD --name-only. The service's runtime
is the one that owns the tool, so run it through corgi and the right toolchain
resolves: corgi exec <svc> -- <tool> <files> (--service-dir when the code lives
in a worktree - stories Phase 3). Outside a compose service, run the tool directly.
Before numbers come from the base version of the same file, not from memory:
git -C <dir> show <base>:<path> > /tmp/cc-base-<name> and measure that too.
Tools, by language - pick the first that is installed; install only with the user's OK:
| Language | Measure | Install |
|---|---|---|
| Go | gocyclo -over 0 <files> · gocognit -over 0 <files> | go install github.com/fzipp/gocyclo/cmd/gocyclo@latest · .../uudashr/gocognit/cmd/gocognit@latest |
| JS / TS | npx eslint --no-eslintrc --parser-options=ecmaVersion:latest --rule 'complexity: [error, 0]' <files> (each report line carries the count) | already in most repos |
| Python | radon cc -s -a <files> · xenon --max-absolute B <files> | pipx install radon xenon |
| Ruby | rubocop --only Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity <files> | in the repo's bundle |
| Anything else (Swift, Kotlin, Rust, PHP, C) | lizard -C 0 <files> (-w warns over the threshold) | pipx install lizard |
No tool and no install → count by hand, per function, and say the count is manual.
Rank touched functions by CC descending. Report the ranking with numbers before touching anything - the user may stop you at "just these two".
On a diff, for every touched function:
Net: the highest CC among touched functions after the change is not higher than before.
gate prints one line - complexity gate: pass or
complexity gate: fail - <n> function(s) over <t>: <name> <before>→<after>, … - then
the report table. review turns a fail into a finding: nit by default, blocking
over 15 or on a hot path (its cost rule), naming the number and the tactic that fixes it.
stories/references/ smallest-change.md). The only refactor with a CC of zero.resolveDiscount(order)
carries meaning; handlePart2 moves the branches and loses it.if / else if or switch chain that maps a value to a
value. Pure data only - a table whose entries run side effects hides control flow.if isEligibleForRefund(order) replaces a four-clause boolean
and the name is the documentation.continue instead of a nested if.Small functions with clear names beat one function with comments explaining sections. A name that needs "and" is two functions.
The number is a proxy for a reader's effort; anything that lowers the number and raises the effort is a regression, whatever the table says:
?..doThingPart1 / doThingPart2 - complexity moved, meaning lost.check1 or isValid with no noun.//nolint:gocyclo, eslint-disable complexity, # noqa) without a
reason a reviewer would accept on the same line.The cognitive-complexity check (above) catches most of these mechanically; a name that got vaguer catches the rest.
corgi test --changed --base <base> (each changed repo's whole suite); corgi test --service <svc> only
when --changed finds nothing, else the discovered runner. Green both times, same count.report mode; in gate mode print
the gate line and stop.End every run with:
## Complexity report
threshold: 10 (.golangci.yml gocyclo.min-complexity)
| Function | CC before | CC after | cognitive before → after |
|-----------------|-----------|----------|--------------------------|
| parseOrder | 14 | 4 | 21 → 5 |
| applyDiscounts | 9 | 9 | 11 → 11 (untouched body) |
extracted: validateHeader, resolveDiscount
behaviour verified: corgi test --changed --base main - api: 212 passed before and after
Numbers and the diff do the talking; keep prose to what the table cannot say.
report and gate never edit.../_shared/conventions.md first (attribution, manualRun).nolint / eslint-disable added to pass the gate → remove it, refactor or report.review - runs this in report mode on every PR diff (Phase 3 hunt list).stories - runs this in gate mode before the per-service gate (Phase 3).memory - where a stack's chosen threshold is recorded as a decision.What SKILL.md sets; muted values are Claude Code's defaults
33 skills in this plugin
/agentUse for corgi agent mode: Remote Control from a phone, the session board ("who is waiting on me"), watching trackers and PRs ("tell me when someone comments"), why a watch fired, and handoffs ("leave a handoff for ABC-7"). NOT compose authoring (corgi), starting a stack (run), debugging (debug)./alignUse when the user says "align", "let's agree first", or a request can be read two ways before any code. Reaches a shared understanding cheaply, then codes. NOT a plan gate or a long interview./autopilotUse for a SUPERVISED loop that drains the ticket queue into draft PRs: "autopilot", "keep shipping the queue", "drain the backlog overnight". One spec gate per batch, never merges. NOT a single batch (/corgi-queue).npx claudepluginhub andriiklymiuk/corgi --plugin corgiOther plugins' skills for the same job