crap-analyzer

A risk check for recently changed code that combines code complexity with test coverage. It uses the CRAP score, a measure intended to highlight complex code that has little test protection.

In plain words
What is it for?
Use it on a diff, branch, or pull request across supported programming languages to plan focused refactoring and add missing test cases.
Why use it?
A code review can miss risky functions when attention is spread across a large change. This ranks the most exposed changed methods and links each one to a refactoring and testing idea.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/swingerman/engineer/crap-analyzer
Any agent
npx skills add swingerman/engineer --skill crap-analyzer
Clone the repo
git clone --depth 1 https://github.com/swingerman/engineer

Made for: Claude Code, Codex.

Per session 109 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,165 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00109 $0.01165
Opus 5 $0.00055 $0.00583
Sonnet 5 $0.00022 $0.00233
Haiku 4.5 $0.00011 $0.00117

Measured 2d ago against content hash 7ad02cce7eed, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

crap-analyzer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/compute_crap.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

crap-analyzer/skills/crap-analyzer/SKILL.md · 84 lines

How it starts

The opening of the file, as written. The whole thing — 84 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CRAP Analyzer

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.

Workflow

  1. 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.
    • Explicit file list if the user names files.

    Pipe the diff to scripts/compute_crap.py --diff -.

  2. 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.

  3. 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.

  4. 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.

  5. Propose fixes per finding, worst-first. For each function above threshold:

    • Read the function. Score alone is not enough — look at the code.
    • Refactor proposal. Extract-method diff or guard-clause rewrite. Patterns: references/refactor-patterns.md.
    • Test stubs. Cover each uncovered branch in the repo's test framework. Templates: references/test-stub-templates.md.
    • Respect codebase conventions. Read nearby code and match naming, error handling, DI, async patterns.

Read the full file on GitHub · 84 lines

Files

What ships with it

7 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 84 lines · 109 tokens per session scan A 7ad02cce7eed

Subscribe to this mod's changes

crap-analyzer is a skill published in the GitHub repository swingerman/engineer (144 stars, last pushed 6d ago), licensed MIT. It adds 109 tokens to every session and 1,165 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

writing-tests

Write unit tests, component tests, and integration tests for AiderDesk using Vitest and React Testing Library. Use when creating new tests, adding test coverage, configuring mocks, setting up test files, or debugging failing tests.

hotovo/aider-desk · 48 tokens

release

Cut a sim-use release end-to-end. Use when the user runs /release or asks to "ship a release", "publish a version", "cut a release", or "release to homebrew". Drives scripts/local-release.sh; never reimplement its build/sign/tarball logic.

lycorp-jp/sim-use · 61 tokens

work-summary

Generates a project dashboard from MCP work items. Default is a lean, attention-first view: what's in flight, what's blocked, what to do next, what's queued. Use when the user says: project status, what's active, show me the dashboard, work summary, what should I work on, project health, what's blocked, where did I…

jpicklyk/task-orchestrator · 110 tokens

manage-schemas

Creates, views, edits, deletes, and validates note schemas for the MCP Task Orchestrator in .taskorchestrator/config.yaml — the templates that define which notes agents must fill at each workflow phase. Also recommends schema designs from a library of workflow patterns (autonomous coding loops, spec-driven teams…

jpicklyk/task-orchestrator · 212 tokens

bmad-dev-story

Execute story implementation following a context filled story spec file. Use when the user says "dev this story [story file]" or "implement the next story in the sprint plan".

LarsCowe/bmalph · 40 tokens

bmad-editorial-review-structure

Structural editor that proposes cuts, reorganization, and simplification while preserving comprehension. Use when user requests structural review or editorial review of structure.

LarsCowe/bmalph · 35 tokens