Lawcheck

Write your architecture rules once, and stop reading your agent's code to enforce them. Lawcheck holds your coding agent to your rules while it writes, before it ends its turn, and in CI. The structure stays as you agreed, so what is left for you to check is behaviour, and your tests do that. I work this way: the less of the agent's code I read, the sooner I deliver to my clients. One law reads imports and other uses in twelve languages. It is free and open source under the MIT license, and it runs on your machine. It calls an AI model only for a rule written in prose, and only when you run lawcheck check --review. You pick the provider and pay for it yourself, or run a local Ollama.
Why not CLAUDE.md or your linter
You can write a rule such as "the business logic must not import the HTTP layer" in three places:
CLAUDE.md or AGENTS.md. The agent reads the rule. Nothing checks the code against it, so you do, by reading the code.
- Your linter. eslint-plugin-boundaries, import-linter or ArchUnit hold the rule for one language, in CI. Inside the agent's turn they run only through a hook you write yourself.
- The law of Lawcheck. One file holds the rule for TypeScript, JavaScript, Python, Go, Rust, Java, Kotlin, C#, C, C++, PHP and Ruby. The plugin checks each file the agent edits and hands it the file and line. Before the turn ends it checks again, and sends the agent back, up to three times, until the code keeps the law. CI checks the same law, with no key and no network.
A law, a rule and a finding
The law is a file in the repository. It names the kinds of files, which kind may use which, and the rules each kind keeps:
lawcheck: 0.1.0
rules:
no-clock:
why: The core takes the time as an argument.
types:
api:
about: The HTTP handlers.
paths: ["src/api/**"]
core:
about: The business logic.
paths: ["src/core/**"]
may_use: [core]
rules: [no-clock]
A script rule is a JavaScript file in .lawcheck/rules/. This one, no-clock.mjs, returns a finding for each line that reads the clock:
export function check({ files: [file] }) {
const findings = [];
file.lines.forEach((text, i) => {
if (/\bDate\.now\(|\bnew Date\(\)/.test(text)) {
findings.push({ line: i + 1, message: 'reads the clock' });
}
});
return findings;
}
An import of a handler into the business logic fails the check, and so does a read of the clock:
$ lawcheck check src/core/discount.ts
lawcheck: FAIL 2 errors in 1 named file
src/core/discount.ts:1 error[forbidden-use] core may not use api (src/api/orders.ts); its may_use is [core]
why: a type's may_use names every type its files may use
src/core/discount.ts:4 error[no-clock] reads the clock
why: The core takes the time as an argument.
next: fix src/core/discount.ts:1
How I work
I build software with coding agents, and I read their code only where a mistake costs a lot or cannot be undone. In the rest of the code the rules hold the structure, and the tests check the behaviour. I have worked this way in real client work for many months, with Yggdrasil, an older tool of mine.
Without a rule that is checked, an agent breaks it quietly. In a small pilot, 8 of 20 Claude Code sessions with no rule written down made the business logic import the HTTP handlers, and all 10 tests still passed (one of the changes).
Try it
Lawcheck needs Node 24 or later and git 2.34 or later.