Scans codebases for performance bottlenecks like O(n^2) loops, N+1 queries, sequential awaits, and render-path waste. Ranks slow functions, confirms with profilers, and optimizes safely.
Ships in complexity-optimizer. 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.
Read when SKILL.md points to them; scripts run unread.
Optimize only when the current behavior is understood and can be preserved. Prefer a small, proven improvement with tests over a broad rewrite with unclear correctness. Scanner output is a lead, never proof: a bottleneck is confirmed by input size, call frequency, and ideally a measurement.
An optimization improves the algorithm or the data structure, and the result reads at least as clearly as the original:
Set/Map/dict index instead of a nested scan, one bulk query instead of one per item, bounded concurrency instead of sequential awaits, one accumulator instead of copies, one sort instead of many, a vectorized column expression instead of a row loop.users_by_id, orders_by_customer); extract a small, well-named helper when it clarifies intent..length, bit tricks, replacing clear comprehensions or map/filter with index loops, inlining helpers, premature object pooling.| Request | Mode | Start with |
|---|---|---|
| "scan / audit / report / find bottlenecks" | Doctor report | Scanner on the repo, then triage |
| "X is slow" (endpoint, job, function, command) | Targeted diagnosis | Reproduce and profile X, then scan the files on its path |
| "review this PR / diff for performance" | Diff review | Baseline from main, then --changed main --baseline to list only the findings the branch adds |
| "CI / build / tests are slow" | Pipeline audit | references/domains/ci-pipelines.md |
| "ETL / data job / notebook is slow" | Pipeline audit | references/domains/data-pipelines.md, then scan |
| "optimize / fix / implement" | Optimize | A report first, then the optimize workflow |
Only edit files when the user asks to implement, fix, optimize, apply, change, or refactor. Analysis and reports never modify project files, and say so (verdicts go to ~/.complexity-optimizer/, outside the repo).
Baseline. Identify languages, frameworks, entry points, test/build/lint commands, and how the code runs in production (request handlers, workers, cron, UI).
Scan. Run the bundled scanner from this skill's directory:
python3 scripts/analyze_complexity.py <repo> --format json # or --format markdown
Read hotspots (functions ranked by their strongest finding) first, then the findings. Do not paste the raw list.
Triage every top hotspot with three questions, reading the surrounding code:
Drop leads whose n is small and bounded or whose path runs once, and say why in one line. A finding in a hot path with unbounded n stays, even if the fix is hard. Record a verdict for every hotspot you examine (see Verdicts below).
Apply the heuristics the scanner cannot prove. Open the matching references/languages/<language>.md and references/domains/<domain>.md and check the hot files for those patterns (ORM lazy loading, missing indexes, re-render churn, dtype and copy costs, blocking I/O on async paths, cross-function N+1 where the loop and the query live in different functions).
Confirm when the code can run. Profile a representative workload and cross the profile with the hotspots: a hotspot under ~5% of the total time drops in priority, and a profile hotspot with no finding is a blind spot of the scanner worth listing. Benchmark a suspect at growing sizes with scripts/measure_growth.py to show its real growth order (see references/measuring.md). A measurement beats any estimate; say which findings are measured and which are estimated.
Report with references/report-template.md: ranked findings table, evidence per finding, verdicts, and the measurements or checks still needed.
Every step is required. In agent studies, most of the possible gain was lost by editing the wrong function, and a mandatory profile and before/after benchmark were the changes that raised success the most.
py-spy record --native, perf, async-profiler, go tool pprof; see references/measuring.md) on a workload that goes through the hotspot, and write a summary of at most 40 lines: function, self %, total %, caller chain. Work only on functions with at least ~5% of the total. If the code can't run here, say so: every gain after this point is an estimate.git stash only when imports make inlining impractical.f() does X for each element of Y; do Z", plus the one before/after example for that pattern from references/optimization-playbook.md. Don't load generic strategy lists.python3 scripts/measure_growth.py "<command with {n}>" for both versions; compare the exponents and their confidence intervals.measure_growth.py prints the peak-memory exponent; in-process, Python tracemalloc, JS process.memoryUsage().heapUsed, others per references/measuring.md.tests/, fixtures/, __tests__/, test_data/, spec/), otherwise synthetic data large enough to show the difference (10,000+ elements for quadratic patterns).kind), and record fixed / confirmed / false_positive / wont_fix for each finding you examined.python3 scripts/analyze_complexity.py <repo> # markdown report
python3 scripts/analyze_complexity.py <repo> --format json # for tools and agents
python3 scripts/analyze_complexity.py <repo> --changed main # only files changed vs main
python3 scripts/analyze_complexity.py <repo> --write-baseline b.json # save today's findings
python3 scripts/analyze_complexity.py <repo> --baseline b.json --fail-on high # CI: fail only on new ones; new findings listed first
--changed selects whole files, so old findings in a touched file show up too. To see only what a branch introduces, write the baseline from main in a separate worktree and compare:
git worktree add /tmp/base main
python3 scripts/analyze_complexity.py /tmp/base --write-baseline /tmp/base.json
python3 scripts/analyze_complexity.py . --changed main --baseline /tmp/base.json # findings tagged NEW
git worktree remove /tmp/base
.gitignore; skips tests (--include-tests to add them), files marked @generated / Code generated ... DO NOT EDIT / <auto-generated, and minified files (mostly lines over 1,000 characters), listed in generated_files. Migrations, seeds, scripts and examples are reported but ranked lower (context: one-off).--changed, where a few files aren't comparable with the whole repo.high); other languages use line heuristics (low), so read their context before trusting them.complexity: ignore (reason).io-or-query-in-loop, await-in-loop, quadratic-accumulation, nested-loop, sort-in-loop, string-concat-in-loop, list-shift-in-loop, dataframe-row-loop, membership-in-loop, deep-copy-in-loop, repeated-scan, regex-compile-in-loop, render-derived-work.If the scanner reports nothing, still inspect the known hot paths manually.
Weights are judgment calls until verdicts measure each rule's precision. Record one per finding you triage or fix, in a file per repo outside the repo:
python3 scripts/verdicts.py add ~/.complexity-optimizer/verdicts/<repo>.jsonl "<path>::<function>::<kind>" confirmed # or fixed, false_positive, wont_fix
python3 scripts/verdicts.py report ~/.complexity-optimizer/verdicts/*.jsonl # precision per rule and language
confirmed and fixed count as useful; false_positive and wont_fix (real but not worth changing) don't. A finding that just disappeared from a later scan is not a verdict. With 10 or more verdicts, a rule whose not-useful rate is likely over 10% goes on probation and over 25% is flagged off.
Before editing:
After editing:
references/optimization-playbook.md: transformations per pattern, with correctness checks.references/measuring.md: profiling, benchmarking, growth tests, and how to read the results.references/languages/: good and bad practices per language (Python, JavaScript/TypeScript, React, Go, JVM, C#, Ruby, Rust).references/domains/: data access (SQL/ORM), data pipelines, CI pipelines.references/report-template.md: the report format.agents/openai.yaml (opens in a new tab)references/domains/ci-pipelines.md (opens in a new tab)references/domains/data-pipelines.md (opens in a new tab)references/domains/sql-and-orm.md (opens in a new tab)references/languages/csharp.md (opens in a new tab)references/languages/go.md (opens in a new tab)references/languages/javascript-typescript.md (opens in a new tab)references/languages/jvm.md (opens in a new tab)references/languages/python.md (opens in a new tab)references/languages/react.md (opens in a new tab)references/languages/ruby.md (opens in a new tab)references/languages/rust.md (opens in a new tab)references/measuring.md (opens in a new tab)references/optimization-playbook.md (opens in a new tab)references/report-template.md (opens in a new tab)scripts/analyze_complexity.py (opens in a new tab)scripts/complexity_scanner/__init__.py (opens in a new tab)scripts/complexity_scanner/baseline.py (opens in a new tab)scripts/complexity_scanner/cli.py (opens in a new tab)scripts/complexity_scanner/discovery.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
/complexity-optimizer:complexity-optimizerfrom complexity-optimizer
npx claudepluginhub sebastianbreguel/agent-complexity-optimizer --plugin complexity-optimizer