Crap4clj logo

Crap4clj

Community
unclebob
crap4clj

Calculates cyclomatic complexity and CRAP scores for Clojure and Babashka functions by combining complexity analysis with test coverage data, generating sorted reports that identify high-risk under-tested code. Use when the user asks for a CRAP report, cyclomatic complexity analysis, or code quality metrics on a Clojure or Babashka project.

Overview

Publisherunclebob
Repositorycrap4clj
Skill namecrap4clj
Stars
62
Forks
4
Bundled files
19
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 19 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by unclebob on GitHub. Read the source before you install it.

Installation

Install the Crap4clj AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/unclebob/crap4clj/tree/master
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/unclebob/crap4clj.git \
  .claude/skills/crap4clj
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Crap4clj in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Crap4clj on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Crap4clj is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

crap4clj — CRAP Metric for Clojure

Computes the CRAP (Change Risk Anti-Pattern) score for every defn and defn- in a Clojure project. CRAP combines cyclomatic complexity with test coverage to identify functions that are both complex and under-tested.

Setup

Add both a :cov alias (Cloverage) and a :crap alias to the project's deps.edn:

clojure
:cov  {:extra-deps {cloverage/cloverage {:mvn/version "1.2.4"}}
       :main-opts ["-m" "speclj.cloverage" "--" "-p" "src" "-s" "spec"]}
:crap {:extra-deps {io.github.unclebob/crap4clj
                     {:git/url "https://github.com/unclebob/crap4clj"
                      :git/sha "<current-sha>"}}
       :main-opts ["-m" "crap4clj.core"]}

The example above uses speclj.cloverage as the runner. For clojure.test projects, use cloverage.coverage instead:

clojure
:cov  {:extra-deps {cloverage/cloverage {:mvn/version "1.2.4"}}
       :main-opts ["-m" "cloverage.coverage" "-p" "src" "-s" "test"]}

Adjust the -p (source path) and -s (test path) flags in :cov to match your project layout.

Usage

bash
# First verify Cloverage works on its own
clj -M:cov

# Analyze all source files under src/
clj -M:crap

# Filter to specific modules
clj -M:crap combat movement

# Analyze Babashka scripts using an existing LCOV report
bb crap --source-root scripts --use-existing-coverage

# Confirm Cloverage's doseq/for 50% form-count fingerprint and recount
clj -M:crap --doseq-double-count

crap4clj automatically deletes stale coverage reports, runs clj -M:cov, and then analyzes the results. It discovers .clj, .cljc, .cljs, and .bb source files. Cloverage instruments .cljs via crap4clj.cljs-coverage (JVM discovery); JS interop needs a #?(:clj …) branch because forms are read with :clj.

For .bb coverage, use Babashka 1.12.215 or newer and pin Cloverage commit 61e3cac426e9907a9dd01c37597f85c71a57ff90 with :deps/root "cloverage". Run Cloverage through crap4clj.bb-coverage/-main; this adapter enables .bb namespace discovery and resource loading. Pass that task to crap4clj with --coverage-command. The scripts must declare namespaces, and tests must call the instrumented functions in-process rather than launch separate bb processes. Executable scripts must guard their -main invocation with a babashka.file/*file* equality check so instrumentation can load them without running the CLI. See the README's "Coverage for .bb files" section for the complete bb.edn configuration.

Output

A table sorted by CRAP score (worst first):

CRAP Report
===========
Function                       Namespace                            CC   Cov%     CRAP
-------------------------------------------------------------------------------------
complex-fn                     my.namespace                         12   45.0%    130.2
simple-fn                      my.namespace                          1  100.0%      1.0

Interpreting Scores

CRAP ScoreMeaning
1-5Clean — low complexity, well tested
5-30Moderate — consider refactoring or adding tests
30+Crappy — high complexity with poor coverage

How It Works

  1. Deletes old coverage reports and runs Cloverage (clj -M:cov)
  2. Finds all .clj, .cljc, .cljs, and .bb files under the configured source roots
  3. Extracts defn/defn- functions with line ranges
  4. Computes cyclomatic complexity (if/when/cond/condp/case/cond->/cond->>/some->/some->>/and/or/loop/catch)
  5. Reads Cloverage HTML for per-line form coverage, including .bb.html reports
  6. Applies CRAP formula: CC² × (1 - cov)³ + CC
  7. Sorts by CRAP score descending and prints report

Troubleshooting

  • Cloverage fails to run: Verify :cov alias paths match your project layout — -p should point to your source root and -s to your test root.
  • All coverage shows 0%: Ensure clj -M:cov runs successfully on its own before running :crap. Check that test files are found under the specified test path.
  • Functions show N/A coverage: This occurs with split-file namespace patterns (in-ns + load). Add --lcov to your :cov alias main-opts for accurate per-file coverage.
  • A tested doseq/for body shows ~50% forms (N out of 2N in the HTML): Cloverage instrumented both copies of the body. That is a rewriter bug, not missing tests. Re-run with --doseq-double-count to confirm the fingerprint and recount. Do not leave that flag on by default; it needs HTML form counts, not LCOV-only.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Crap4clj AI skill do?

Calculates cyclomatic complexity and CRAP scores for Clojure and Babashka functions by combining complexity analysis with test coverage data, generating sorted reports that identify high-risk under-tested code. Use when the user asks for a CRAP report, cyclomatic complexity analysis, or code quality metrics on a Clojure or Babashka project.

Why use Crap4clj on TypingMind?

Because you install it once and use it with any model. Crap4clj is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Crap4clj in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/unclebob/crap4clj/tree/master. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Crap4clj?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Crap4clj?

As many as you like. As long as a model supports skills, you can use Crap4clj with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Crap4clj AI skill free?

It is published on GitHub by unclebob. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇