Directory Compare FCRS-1.0 /llms.txt
← Back to Directory

Coccinelle

$ spatch Community Low Risk
Inria · Files & Search · GPL-2.0 · macos / linux

Coccinelle (spatch) matches and transforms C code using Semantic Patch Language (SmPL) rules rather than fragile text regexes, widely used in the Linux kernel. By default spatch performs a safe dry-run printing unified diffs to stdout unless --in-place is explicitly passed.

FCRS-1.0 Score
80 /100
Good
Medium Confidence
Zero-Friction Install
brew install coccinelle
CLI vs MCP Decision CLI Only

spatch parses and diffs large C trees locally; there is no reason to wrap SmPL execution in an MCP server.

Agent-Readiness Checklist

— JSON Output
— Field Filtering
✓ Non-Interactive
✓ Dry-Run
✓ Read-Only Mode
— NO_COLOR Clean
— Self-Describing
— Official SKILL.md

Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.

FCRS-1.0 6-Dimension Breakdown

Agent-Readiness 18 / 25

Non-interactive, defaults to dry-run unified diffs, and supports --very-quiet and --mode report, though it lacks --json output.

  • Defaults to read-only diff stdout; --very-quiet suppresses progress noise
  • Outputs unified diff or text reports, not JSON
Trust & Safety 23 / 25

Safe by default: never touches files on disk unless --in-place is explicitly supplied.

  • Read-only dry-run is the default behavior
Setup & Portability 10 / 15

Available via brew install coccinelle, Linux distro packages, and opam, though Windows requires WSL/Cygwin and OCaml toolchain builds are heavy.

  • Primarily macOS and Linux; limited native Windows support
Utility & Efficiency 13 / 15

Gold-standard C AST/control-flow refactoring engine capable of transformations impossible with regex.

  • Battle-tested across Linux kernel coccicheck rules
Maintenance & Lineage 8 / 10

Maintained by the Inria research team and Linux kernel contributors under GPL-2.0.

  • Long-term academic and kernel maintenance
Docs & Verifiability 8 / 10

Detailed SmPL grammar docs, tutorials, and spatch(1) man page.

  • Official documentation and kernel scripts/coccinelle examples

Security, Auth & Guardrails

Auth Modes
No Auth
Credential Storage

None required; operates strictly on local C source files and .cocci scripts.

Side Effects
Read-Only Local Write
Cost & Quotas

100% free, offline, and open-source (GPL-2.0).

Copyable Guardrail for CLAUDE.md / AGENTS.md
# Coccinelle (spatch) Agent Rules
- `spatch` defaults to read-only diff output; pass `--very-quiet` to suppress banner noise.
- Only add `--in-place` after inspecting the unified diff output on target `.c`/`.h` files.

Agent-Ready Command Recipes

Safe Read-Only Queries

Dry-run a semantic patch and output unified diff
spatch --very-quiet --sp-file rule.cocci --dir src/

Evaluates rule.cocci across src/ and prints unified diffs to stdout without modifying files.

Run a SmPL rule in report mode
spatch --very-quiet -D report --sp-file check.cocci --dir src/

Emits file:line:col diagnostic findings using the virtual report rule.

Controlled Writes & Previews

Apply a semantic patch in-place
spatch --very-quiet --in-place --sp-file rule.cocci --dir src/

Writes the reviewed SmPL transformation directly to matched C files (--in-place).

Strengths for Agents

  • + Safe read-only unified diff output by default (--in-place required to mutate files).
  • + Understands C control flow, types, and macros far better than text-based tools.

Caveats & Pitfalls

  • ! Only targets C code and requires writing .cocci SmPL semantic patch scripts.
  • ! Lacks --json output and native Windows support.

Tested Agent Hosts

Claude Code Codex CLI Gemini CLI