Getting started
Install lawbook, write a first lawbook.yaml, and run it in CI.
Lawbook needs Node.js 22.12 or newer.
npm install --global lawbook
Write the first rules
From the directory you want to check, create a starter config:
lawbook init
This writes lawbook.yaml with two rules that pass in an empty directory, plus
commented examples of the other rule kinds. init never overwrites an existing
lawbook.yaml, lawbook.yml, or lawbook.json.
Open the file and describe your standards. Each rule has an id, an optional
description, and exactly one of the rule kinds from
Configuration:
version: 1
rules:
- id: no-console
description: Production code logs through the logger
files: ["src/**/*.ts"]
forbid: 'console\.(log|debug)\('
- id: has-readme
exists: README.md
Run the check
lawbook check
FAIL no-console
src/cli.ts:12: console.log("starting");
PASS has-readme
1 passed, 1 failed, 0 warned, 0 errored, 0 skipped
check exits 0 when every rule passes, 1 when any rule fails, and 2 when
it could not run at all, so it works as a CI step without extra scripting:
- run: npx lawbook check
A config with standard rules needs the provider’s CLI installed and signed
in on that runner, or --no-llm to report those rules as skipped; see
Providers.
On a pull request, check only the files the branch changed with
--since origin/main, and in a pre-commit hook pass the staged files with
--files; see Commands. Both keep a
standard rule’s model requests to the files that moved.
Point it at another directory, or at a config kept elsewhere:
lawbook check path/to/project
lawbook check --config standards/lawbook.yaml
Pass --format json to feed the results to another tool, or --only to run a
subset of rules while you write them:
lawbook check --only no-console
A rule you are not yet sure of can run with level: warn. Its findings print
under WARN and the exit code ignores them, so CI stays green while you tune
the rule. Drop the level once it is right. On a codebase with many existing
findings, record them in a baseline so that only new ones fail.