R424 · Agent principles and patterns › Formal constraints on agent actions

Splitting the instruction file: which rules a binary can enforce

Read the original

agent-harness, hooks, governance, code-review, open-source, developer-infrastructure

Source: Ratchet (github.com/itsthecsguy/ratchet, MIT, Rust; repository created 28 Nov 2026, last push 30 Nov 2026, 159 stars, 5 forks and 3 open issues as of 30 November 2026). Written for engineers who maintain an agent instruction file and have noticed it does not always hold.

The observation the tool is built on

An agent instruction file is two documents pretending to be one. Some of what it contains is mechanically checkable — use pnpm, never npm; do not write to this directory; run the tests before you finish. The rest is judgment — keep error messages clear, prefer small functions. Both are written as prose, in the same voice, at the same bullet level, and both are handed to a model as advice it may or may not follow.

Ratchet's premise is that the first kind should not be advice at all. It should be a check that runs before the tool call, and the model should receive the correction rather than the instruction. The tool's own framing is typecheck your skills, and the useful part of the design is the split, not the enforcement.

Architecture

Three pieces, and the ordering matters.

1. A linter over the instruction files. ratchet lint reads CLAUDE.md, AGENTS.md and SKILL.md and classifies what it finds. Its output is a claim split: how many statements are enforceable as deterministic rules, and how many are prose or judgment that should stay prose. It also flags a set of defects that have nothing to do with enforcement and are arguably the more immediately valuable output:

The reported lint time is about 36 ms on a 35,000-file repository, and the lint output also reports the always-loaded token cost of the guidance.

2. A rule format that carries its own tests. A rule is a fenced block inside the markdown or in a compiled .ratchet/checks.yaml, declaring when it applies (run, write, commit, finish), its level, what it denies, a rewrite, a message, and — this is the part worth stealing — an ok: example and a bad: example. The fixtures ship with the rule, so a rule that no longer does what it claims fails its own test. Setup reports how many fixtures passed.

3. A hook that runs at tool-call time. The binary wires itself into each harness's native lifecycle hooks (PreToolUse, PostToolUse, Stop), so the harness pauses before execution and pipes the proposed call as JSON. The binary lexes the shell command deterministically — explicitly including inside sh -c, pipes and environment prefixes — matches it against the rules, and returns a denial plus a concrete fix: command. The reported hook latency is about 1.8 ms, and the README is emphatic that no model is involved in enforcement: a single ~5 MB Rust binary, offline, no API keys.

Nine harnesses are supported, each through its own hook or plugin file: Claude Code, Antigravity, Codex CLI, Cursor, Gemini CLI, Amp, GitHub Copilot CLI, OpenCode and Windsurf. The table is honest about where capability differs — two of the nine enforce pre- and post-tool calls natively but have no finish hook, so finish-time rules run through an explicit check command and CI instead. Hook files it creates are added to .git/info/exclude and removed by an uninstall command.

The four levels, which are the real design

Rules carry one of four escalating levels: shadow < warn < ask < enforce.

Enforce is the default, with one deliberate exception: hedged sentences — prefer pnpm rather than always use pnpm — are capped at warn. That is a small piece of linguistic judgment doing real work. A tool that enforced every imperative-looking line in a guidance file would be unusable within a day.

The escape hatches are specified in matching detail, and this is where the design shows experience. A one-time exception for exactly one command, with a time-to-live and a use count, rather than disabling the rule. A demote command that requires a reason. A local mute for a rule you think is wrong. An environment variable and an off switch to pause enforcement wholesale. And an anti-weakening check for CI, so that loosening a rule is visible in a pull request rather than silent.

One detail is specific enough to be worth copying on its own: when a model retries the same denied action in the same session, the denial escalates, telling it the attempt number and not to retry. Anyone who has watched an agent loop against a guard knows exactly which failure that addresses.

What the agent sees

The denial is a structured message capped at 600 bytes containing the blocked command or path, the rule id, a verbatim quote from the guidance file, and the fix command.

That shape is the transferable idea, independent of this tool. A blocked action is a teaching moment with a tiny budget, and three things have to be in it: what was blocked, why in the project's own words, and what to do instead. Quoting the guidance file rather than paraphrasing it means the model is corrected by the document it was given, which keeps one source of truth. And returning an executable fix rather than a prohibition is what lets the model self-correct in the same turn instead of asking.

Rule authoring, and the line it holds

A model may draft rules. The documented path pipes a generated prompt out to any agent CLI and the candidates back into the tool, where they are verified against their own fixtures deterministically before installation. There are also curated starter packs for common cases — package manager, git hygiene, secrets, TypeScript hygiene.

The discipline here is the point: the model writes the candidate, a deterministic verifier decides whether it is kept. That is the same division as in the enforcement path, applied one level up. A tool that let a model both write and approve its own guardrails would have no guarantee at all.

Separately, prose rules — the ones that cannot be made deterministic — are not abandoned. A test command benchmarks real models against prose scenarios, so judgment rules get an eval rather than a check. Whether that eval is any good is not something the README establishes, and it is the part a reader should be most sceptical of.

Tradeoffs

For: determinism where determinism is possible. No model in the enforcement path means no latency worth measuring, no token cost, no API key, no nondeterminism, and no prompt to be injected. A ~5 MB static binary is also a far smaller supply-chain surface than a plugin that calls out.

Against: a second configuration surface. The compiled rules, the per-harness hook files and the markdown can disagree, which is why a linter for internal contradiction is not a nicety but a requirement of the design. Nine harnesses means nine hook formats to keep working as each vendor changes its lifecycle, and the capability table already shows two of them lacking a finish hook.

The real cost: enforce-by-default on a repository whose guidance file has accumulated for a year will block things people did not know it said. The tool's answer is the shadow level and a historical audit at setup time, and the right rollout is shadow, measure, then promote — not the default.

What it cannot do: everything interesting about a code change is in the judgment half. This moves the mechanical half out of the prompt; it does not make the prompt reliable.

What is not established

The project is two days old, with 159 stars and 5 forks. Every performance figure — 36 ms lint, 1.8 ms hook, 5 MB binary, 529 unit and integration tests, 548 end-to-end checks across the nine harnesses — is self-reported in the README, measured by its own authors on unnamed hardware. There is no independent benchmark, no adoption evidence, no published false-positive rate for the lint rules, and nothing at all on how often a denial actually produces a correct self-correction rather than a different wrong action. That last number is the one that would decide whether this works, and no one has it.

The cross-file contradiction detection is also a fixed list of known tool pairs, not general reasoning, so it catches the contradictions someone thought of.

Failure modes to design against

Review checklist for enforcing an instruction file

  1. Have you split your guidance into mechanically checkable and judgment, and do you know the ratio?

  2. Does every enforced rule carry a passing and a failing example that run in CI?

  3. Did you run in shadow mode first, and do you know each rule's hit rate before enforcing it?

  4. Does each denial return an executable fix, quoted from your own guidance?

  5. Is there a one-command, time-limited exception, so the alternative to being blocked is not switching the rule off?

  6. Does weakening a rule require a reason and show up in review?

  7. What happens on the harnesses that lack the lifecycle hook your rule needs?

  8. Do you measure whether a block leads to a correct next action, or only that it blocked?

  9. Does anything detect contradictions between your guidance, your lockfiles and your configuration?

  10. What is your rollback — can you pause all enforcement in one step?

Scope limits

The linked guide, rule-format specification and architecture documents are not covered here, so rule-key semantics, lint-code definitions and the latency methodology are taken from the README's summaries of them. No figure here has been independently measured, nothing was installed or run, and the project is two days old, so anything about stability is unknown.

Connections

See R424 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.