/crap-analyzer:crap-analyzerfrom crap-analyzer
Computes CRAP (complexity x untested) on changed code in a diff/branch/PR to identify high-risk functions, then generates refactor proposals and test stubs. Supports many languages.
Ships in crap-analyzer. 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.
CRAP (Change Risk Anti-Patterns) flags functions that are both complex and poorly tested — the worst-risk code to ship.
CRAP(m) = comp(m)² × (1 − cov(m))³ + comp(m)
This skill scopes analysis to a diff, ranks findings worst-first, and turns each finding into a concrete refactor + test-stub proposal.
Determine the diff. First that works:
gh pr diff / gh pr diff <number> if a GitHub PR is referenced.git diff --merge-base <main-branch> — detect the main branch with git remote show origin | grep 'HEAD branch'.git diff --cached for staged changes.git diff HEAD~N..HEAD for a named commit range.Pipe the diff to scripts/compute_crap.py --diff -.
Locate or generate coverage. Let the script auto-discover coverage files first (lcov, Cobertura, JaCoCo, Clover, Go coverage.out, coverage.py JSON). If nothing is found, follow references/coverage-discovery.md to detect the toolchain, then ask before running it. On decline, proceed with coverage=0% and flag it in the report header.
Run the analyzer.
python3 <skill-dir>/scripts/compute_crap.py --diff - --repo-root <repo> --threshold <N> --format both
Default threshold is 20. Read .crap-analyzer.json at repo root if present and pass its threshold through. Full flag list and output JSON shape: references/script-reference.md.
Present the report. Show the markdown table. For each finding, link file:start_line. If more than ~8 findings, surface the top 5 and mention the rest.
Propose fixes per finding, worst-first. For each function above threshold:
When len(findings) >= 3, dispatch one subagent per finding in a single message — per-finding work is independent so parallelizing drops wall-clock from O(n) to O(1). Prompt template + aggregation rules: references/subagent-prompt.md. After subagents return, sort by CRAP descending and sanity-check every "safe to auto-apply" claim against step 7.
Present the wrap-up menu. Dispatch refactor / test-stub work via AskUserQuestion. Menu structure and apply loop: references/wrap-up-menu.md. "Safe refactor" = pure extract-method with no behavior change (same inputs → same outputs, same side effects, same order). One Edit per action; confirm each before applying.
Never auto-apply:
await, .then, subscribe, promise chains, RxJS / coroutine / goroutine ordering).### 1. `file.py:42` — `do_thing` (CRAP 240)
**Why it's flagged:** complexity 15, coverage 0% (no tests touching body).
**Refactor proposal:**
<unified diff or code block>
**Test stubs to add:**
<framework-appropriate test block>
Keep each section tight — one paragraph of "why", diff, stubs. No preamble.
Optional .crap-analyzer.json at repo root:
{ "threshold": 20 }
Read if present, pass --threshold to the script. No other keys for now.
references/coverage-discovery.md (opens in a new tab)references/refactor-patterns.md (opens in a new tab)references/script-reference.md (opens in a new tab)references/subagent-prompt.md (opens in a new tab)references/test-stub-templates.md (opens in a new tab)references/wrap-up-menu.md (opens in a new tab)scripts/compute_crap.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
TypeScript, JavaScript, Python, Java, Go
crap-analysis, complexity, test-coverage, refactoring, risk-assessment
npx claudepluginhub swingerman/engineer --plugin crap-analyzerOther plugins' skills for the same job