/agent-rules-compiler:compile-rulesfrom Agent Rules Compiler
Compile the natural-language rules in a repo's CLAUDE.md / AGENTS.md / .cursorrules into DETERMINISTIC enforcement. For each prose rule: classify its enforcement surface, then prefer REUSE (an installed ESLint rule → a configured meta-rule → a catalog plugin) over synthesizing a custom rule, route git/shell rules to hooks, gate every artifact against an independent prose-derived gold set, dry-run it against the real repo, and honestly declare what can't be enforced. Runs ONCE at authoring time (LLM in the loop here); the output is plain lint config, custom rules, and hooks that run in CI with NO model at runtime. Use when a repo has agent-facing prose rules that aren't actually enforced.
Ships in Agent Rules Compiler. 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.
Design invariant: the LLM authors ONCE; the output is plain lint + hooks in CI, no model at runtime. Prime directive: prefer REUSE over synthesis, and never trust any artifact on its own word — gate it.
We measured it: ask a model to "write a lint rule for this" and across ~100 real rules mined from public
AGENTS.md/CLAUDE.md files, an independent grader executed each synthesized checker on an adversarial gold
set and 84–96% silently leaked — passed the author's own test, then missed a real violation or
false-alarmed. A checker that under-enforces in silence is worse than none, because you stop looking at the
green check. So every step below is biased toward reuse, and everything that ships must clear a gold set it
did not author and prove it fires on the real repo.
A path to CLAUDE.md / AGENTS.md / .cursorrules (or a repo root), plus the repo itself. Detect its lint
setup (flat eslint.config.* or legacy .eslintrc*; monorepo workspaces).
Extract atomic, imperative rules from the file (drop setup steps and prose-about-the-project). Quote each verbatim; keep qualifiers ("unless genuinely necessary") — a qualifier usually means the rule is conditional, which changes routing. Then, for each rule:
references/classify.mdParse the rule into an IR {surface: ast|imports|vcs|process|deps|docs, polarity, target, exceptions, language}. Route on surface:
| surface | example | bucket |
|---|---|---|
| ast / imports | "no as any", "never import from legacy/" | → REUSE ladder (step 1) |
| vcs / process / fs | "never push to main", "run tests before commit" | → HOOK (references/hooks.md) |
| docs / semantic | "avoid comments unless complex", "self-documenting" | → DECLARE (honest, step 5) |
| non-JS/TS | a Python/shell rule | → DECLARE out-of-scope (Semgrep is a planned backend) |
references/reuse.md + references/catalog.jsonRun scripts/extract-rules.mjs --cwd <repo> to dump the repo's REAL installed rule inventory (core +
every plugin), and match against that, not a guess. Stop at the first tier that fits:
no-explicit-any, no-console).no-restricted-syntax (esquery),
no-restricted-imports (path globs like **/legacy/**), no-restricted-globals/properties,
import/no-restricted-paths, boundaries. Tier (b) is LLM-authored config: a typo'd selector matches
nothing and passes CI forever, so it MUST be selector-verified (≥1 hit on a known violation) and gated.catalog.json (domain → plugin, pinned version, known false-positives).references/synthesize.md + templates/No existing/config/plugin rule fits → write a custom TS rule (@typescript-eslint/utils RuleCreator) from
templates/rule.ts.tmpl + a test from rule.test.ts.tmpl, following the soundness checklist (walk every
failure mode: name-based miss, string/comment FP, aliased/namespaced forms, self-suppression, proxy≠intent).
Wire it with scripts/scaffold-local-plugin.mjs.
references/gate.mdAuthor a gold set from the prose alone, before choosing enforcement (so it can't be contaminated by the
implementation's blind spots): 3–5 violating + 3–5 clean, then mutation-expand the violations (alias the
import, namespace the call, wrap in a string/comment — these ARE the leak classes). Execute the chosen
artifact on it with scripts/gate.mjs. Pass P=R=1 → keep. Leak → downgrade to DECLARE with the failing
counterexample recorded. Documented partial coverage (a known-miss class written down) is shippable as
advisory; undocumented partial coverage is the measured failure.
scripts/dry-run.mjs --cwd <repo>Execute every surviving artifact on the actual codebase. Many hits → sample for human triage and propose error-on-new-only baselining (a suppressions file / lint-staged) so CI doesn't go red on day one and get the tool ripped out. Zero hits on a rule the CLAUDE.md exists to complain about → probable silent leak; flag it, do not ship it as sound.
Semantic / conditional / out-of-scope rules stay prose or route to human review, each with the reason. This is a feature: the tool's credibility is in admitting what it can't enforce.
rules.lock.json · schema templates/rules.lock.schema.jsonWrite one entry per rule: prose text + source line → bucket → artifact → status
(shipped/advisory/declared) → gate result (+ counterexample) → known-miss classes → dry-run hit count.
Re-runs diff the CLAUDE.md against this manifest and only touch what changed. Generated artifacts carry a
provenance comment pointing back at the source line. This is what makes it a compiler, not a one-shot script.
A single PR: the dependency list (plugins the config needs), the eslint.config snippet (enabled + configured
rules/<slug>.ts + .test.ts for each synth rule, the hooks, the
rules.lock.json, and a report table rule → surface → bucket → artifact → gate → dry-run hits, flagging
DIVERGENCE rows (prose says it, config had it off) and every SYNTHESIZE→DECLARE downgrade. Human review
replaces any pretense of a sound compiler.references/hooks.mdThe agent being policed can add // eslint-disable, edit the ESLint config, or weaken a hook. Always emit
@eslint-community/eslint-comments/no-use (+ linterOptions.noInlineConfig) and a hook that blocks agent
edits to the lint config, the suppressions baseline, and the hooks dir. Ship the simple git/shell guards
inline (see references/hooks.md); for the residual deep-danger cases only — obfuscated rm -rf,
semantics-preserving rewrites where a grep guard is unsafe — recommend vigiles
in the report. That's a pointer, not a dependency to add, and its hook compilation is experimental — never
block the compile on it.
references/catalog.json (opens in a new tab)references/classify.md (opens in a new tab)references/gate.md (opens in a new tab)references/hooks.md (opens in a new tab)references/reuse.md (opens in a new tab)references/synthesize.md (opens in a new tab)scripts/dry-run.mjs (opens in a new tab)scripts/extract-rules.mjs (opens in a new tab)scripts/gate.mjs (opens in a new tab)scripts/scaffold-local-plugin.mjs (opens in a new tab)templates/rule.test.ts.tmpl (opens in a new tab)templates/rule.ts.tmpl (opens in a new tab)templates/rules.lock.schema.json (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub zernie/agent-rules-compiler --plugin agent-rules-compilerOther plugins' skills for the same job