Measuring and graduating
This is the part that makes the rest defensible. Every rule's stance is a claim about your own behaviour, and the claim is checked against your own transcripts rather than asserted.
The loop is: mine → backtest → explain → review → compliance → graduate.
0. Mine — what is going wrong that no rule names?
Every step below prices a rule somebody already thought of. mine is the
step before that: it groups the transcripts by command shape and ranks the
shapes that went wrong.
greenbelay mine --since 2026-08-15
greenbelay mine --min-support 10 --min-rate 0.4
greenbelay mine --format cases >> crates/greenbelay-guard/tests/corpus/<new-rule>.cases
A shape is the parsed command with its literals masked — the branch, the path, the line number and the commit message taken out, the program, the verbs and the flag set kept:
git push origin feat/mine 2>&1 | tail -5 ─┐
git push origin fix/lint 2>&1 | tail -20 ─┴→ git push origin <word> 2>&1 | tail -5
A call counts as gone wrong when either of two things the transcript records is true:
- failed — the tool result carried
is_error: a non-zero exit, a refused permission, a run the harness killed; - corrected — a near-identical command followed within a few tool calls. A model that re-issues the same shape is a model whose first attempt did not land, and that is the interesting half: the mistakes worth a rule are the ones nothing reports.
Only the HEAD of a run of near-identical calls counts as a correction. A
polling loop is one decision repeated twenty times, not nineteen mistakes —
before that rule existed, the top line of the real report was echo waiting.
bad and rate are suspicion, not verdict. A shape re-run for good
reasons carries a high rate and names no mistake at all. That is why every
row prints its samples and why the next step is a person reading them.
Shapes an existing rule already fires on are listed apart, covered by <rule>, rather than proposed — and a covered shape that is still going wrong
is a rule that is observing when it should be advising.
What mine does not do is write the rule. Nothing learned here reaches
the hook: the path is mine → write the rule by hand → cases → corpus check → graduate, and what ships is the hand-written rule with its reason, its
remedy and its reviewed corpus. A guard that refused a command because a
clustering run found it suspicious could not explain itself to the person
whose work it just refused.
1. Backtest — what would this have cost me?
backtest replays your Claude Code transcripts through the rules and reports
firings per 1,000 tool calls per week, so a rule's cost is a number rather
than an impression.
greenbelay backtest --since 2026-07-06
greenbelay backtest --rule pipe-to-tail --json
greenbelay backtest --transcripts ~/.claude/projects # where they live
The roll-up: firings the journal no longer holds
The journal keeps about three days. greenbelay rollup prints what survived
rotation: one row per week and rule, week rule firings calls rate/1000, for
the current week and the last closed one; --weeks <n> widens it and --json
prints every week (format greenbelay-rollup-v1; retro reads it for the rules
whose replay is none).
greenbelay rollup
greenbelay rollup --weeks 4 --json
greenbelay rollup --transcripts ~/.claude/projects -q
calls is the week's count of the tool the rule fires on (Bash, Read, or all
tools for a rule that fires on several), counted from the transcripts,
subagents included. A closed week's calls are stored the first time they are
computed, within a week of closing, and never rescanned, because Claude Code
prunes old transcripts. A rule with no honest tool (a Stop event, an
assertion) and a week not stored print -: unknown is not zero. Counts start
at the first fold; nothing before it comes back, so the first week may be
marked (partial).
A weekly series is the thing to read, not a total. A habit that is halving on
its own does not need a deny; the model is already correcting. A flat line
over weeks is a habit that will not correct itself, and that is what promotion
is for.
A replay counts what a rule's examine matches in Bash calls, and that is a
rule's live count only for some rules. --json labels each rule:
"replay": "exact": the replay counts what the hook would have counted;"replay": "none", withreplay_why:not-shell: the rule fires on another tool or event, which the replay does not read, so it shows 0;live: only the live session decides, so it shows 0;confirmorverify: the hook checks the world at the time, so the replay counts every shape match, confirmed or not.
Only an exact row is a weekly count. To recount one week of one rule, give
the week's Monday (UTC):
greenbelay backtest --rule pipe-to-tail --since 2026-11-09 --json \
| jq -r '.version as $v | .rules[] | select(.replay=="exact") | .id as $r
| .weeks[] | select(.week=="2026-11-09")
| "\(.week) \($r) \(.fires) \(.calls) \(.per_1000) v\($v)"'
The matchers are today's (version): the same week recounted after a
release may differ.
2. Explain — look at the actual matches
A rate is only trustworthy if the matches behind it are real. explain prints
every match for one rule so you can read them.
greenbelay explain pipe-to-tail
greenbelay explain pipe-to-tail --sample 20
greenbelay explain pipe-to-tail --sample 20 --rank novelty
--rank novelty changes WHICH twenty. The default is the first twenty the
walk met — the oldest project, the oldest session, and, because a habit
repeats, very often twenty spellings of one command. Novelty picks the
twenty least like each other and least like the cases already in
crates/greenbelay-guard/tests/corpus/<rule>.cases, by greedy max-min over the shape distance, so
an hour of labelling buys as much of the precision estimate as an hour can.
It is deterministic: the same transcripts and the same corpus pick the same
cases, and a second pass does not hand back the first pass's.
3. Review — turn matches into reviewed judgements
Precision is kept as a corpus of judgements, not as a metric, because a metric charts a regression and a test prevents one.
greenbelay explain pipe-to-tail --format cases >> crates/greenbelay-guard/tests/corpus/pipe-to-tail.cases
$EDITOR crates/greenbelay-guard/tests/corpus/pipe-to-tail.cases # each `?` becomes match or nomatch
greenbelay corpus check # and this runs in the test suite
Include the cases that should not match. A corpus of positives alone measures recall and says nothing about how often the rule is wrong, which is the number that decides whether it can be allowed to refuse anything.
A rule answered from the Read tool's payload, not a command, never fires on a command line, so its file can only hold negatives that way. Its cases are Read calls instead, one per line:
match Read full 18425 relais:relais-worker-sonnet-medium src/graph.rs
nomatch Read full 20480 implementation-review src/graph.rs
The fields are the window (full, or <offset>:<limit> as the hook records
it), the file's size in bytes, the agent (main, - for a subagent of
unknown type, or its agent_type) and the path, to the end of the line. The
corpus judges each one with the decision the hook makes, on a regular file of
that size. Only read-unbounded-large has a Read judge today; a Read case in
any other rule's file, or a malformed one, counts as a disagreement.
4. Compliance — is the advice worth its tokens?
advise buys its place in the model's context with tokens, every session,
forever. The backtest says what that costs. This says what it buys.
greenbelay backtest --compliance
greenbelay backtest --compliance --rule glob-in-flag-value --json
greenbelay backtest --compliance --window 40
For every firing it looks at what the model did next. If the next
equivalent command — same shape, within the window — no longer matches the
rule, the habit changed (complied). If it matches again, the advice was
read and ignored, or never reached the model (ignored). If nothing
equivalent followed, the firing is unanswered and counts towards neither.
Three things make the number readable:
- Per model. Models differ, and a pooled figure hides which one is
listening.
claude-opus-5andclaude-fable-5do not answer the same way to the same sentence. observerules are the control. They said nothing, so their share is the rate the habit corrects on its own. Advice is worth its tokens only where the advised share beats the silent one — the same argument the stance ladder rests on, measured instead of assumed.denyrules are left out. A refused command never ran, so there is no next command to compare it against.
What it cannot see: a transcript records what the model ran, not whether the hook spoke. A firing here means "the rule as it stands today would fire on this command", replayed. Where a rule has been widened since, or was observing then and advises now, the number is a reconstruction — and it is still the only evidence there is.
The Read tier from transcripts
The Read tool never reaches the backtester, so read-unbounded-large is
measured from the transcripts directly:
tools/read-rate.py
tools/read-rate.py --weeks 8
For each ISO week it prints the tool calls, the Reads over 16 KB with no
offset/limit after the same exemptions the rule makes (plans, diffs,
media, tool-results/), that count per 1000 calls, and the characters. Run
it to recount the rule's per_1000 and again two weeks after a release, to
compare against the weeks before.
The write tier from transcripts
lint-suppression-added never reaches the backtester either: an Edit or Write
is not a command. It is measured from the transcripts with
tools/suppression-rate.py:
tools/suppression-rate.py
tools/suppression-rate.py --weeks 8
tools/suppression-rate.py --until 2026-10-06
For each ISO week it prints the tool calls, the Edit, MultiEdit and Write calls
that add a suppression or loosen a lint setting, and that count per 1000 calls.
Run it to recount the rule's per_1000 and again two weeks after a release.
The script sees fragments only: a transcript holds what the model sent,
never the file, so it compares old_string with new_string, as the hook's
fragment fallback does. With no section around the text it undercounts the
config rows that need one ([tool.pyright], [tool.ruff*], [lints.*],
.golangci.yml disable: and exclude*), unless the edit carries the header
itself. --self-test classifies tests/fixtures/suppressions.txt, which a
Rust unit test classifies too; tests/suppression_rate.rs runs it.
Guidance writes from transcripts
agent-guidance-written and agent-guidance-shape are write-tier rules too.
tools/agent-guidance-rate.py counts the Edit, MultiEdit and Write calls to
SKILL.md, CLAUDE.md, CLAUDE.md.tmpl, AGENTS.md, MEMORY.md and agent
definitions per 1000 tool calls, per kind of file:
tools/agent-guidance-rate.py
tools/agent-guidance-rate.py --weeks 8
It counts writes to the paths. A transcript never holds the file, so it cannot
size it. Run it to recount the rules' per_1000 and again two weeks after a
release.
What came before a publish, from transcripts
publish-without-skill asks a question the backtester cannot: whether the
tag-release or merge-when-green skill was called in this turn or the one
before. Its confirm reads the transcript, and the backtester never runs
confirm. It is measured with tools/skill-rate.py:
tools/skill-rate.py
tools/skill-rate.py --since 2026-10-07 --list
It prints the publishing Bash calls per 1000 (a v* tag pushed, gh pr merge, a merge sent to /pulls/<n>/merge), split by what preceded them:
no-skill, stale (called two or more prompts back), allowance (covered only
by the one prompt the window allows) and covered. It prints the same counts per
unique command per session, since a refused command is retried. Then it prints
how old the covering call was, and the uncovered rate by week. The matcher is a
regular expression. Against the Rust lexer it overcounts by about 6% (1,551
against 1,461 on 2026-10-07), so backtest --rule publish-without-skill remains
the count of matches. Run it again two weeks after a release.
Fingerprinting a dated measure
A count that is re-run over weeks and compared to an earlier number is only
comparable if the recipe is the same. tools/measure_fingerprint.py hashes
the recipe, never the data: the script's git blob id, the tool version, the
source, the schema marker, the filters and the window rule. Coverage (files
seen, files unreadable, weeks printed) is stored beside the fingerprint, not
in it.
tools/read-rate.py --fingerprint ~/.local/state/read-rate.fp.json
The first run writes the sidecar file as the baseline; later runs with the
same recipe append a run. A different recipe is refused before the table is
printed (exit 3), naming the changed keys with old and new values and the
exact command to accept it. --rebaseline accepts it and records both
recipes in the sidecar's rebaselines. A sidecar whose stored fingerprint
does not match its recipe is corrupt: exit 1, even with --rebaseline.
A measure captured in pieces (a day each) writes one stamp per piece with
stamp(); measure_fingerprint.py compare FILE... [--rebaseline] refuses
mixed recipes when the pieces are summed. A relais ticket's front matter
refuses a fingerprint key, so the ticket body names the sidecar file.
4b. Harness review - which part still earns its place on this model?
greenbelay harness-review (ADR-0042, harness.retire-on-evidence) prints
one row per rule and assertion: its id, the failure it prevents, its stance,
whether it is irreversible, and from the journal its per_1000 (live rows
over the transcripts' Bash calls) and the date it last fired. Shadow rows
(arm=shadow) are the experiment, not the part, and are never counted as live.
Each row adds the compliance replay of section 4, grouped by message.model.
Where any journal row for the part has arm=shadow, it also gives the
ignored share per arm. A transcript does not record whether the hook spoke,
so each session's arm comes from the journal row's arm field, joined to the
transcript session id by the journal's eight-character session prefix. A part
guarding an irreversible action is never dropped live; its row carries a
replay count instead: how many of the reviewed model's Bash calls its
examine matches.
A deny rule has no live compliance (its refused command never ran); when it
is shadowed, its shadow rows are replayed as observe and give the shadow arm a
share, with the live share left empty.
--json emits the same rows. Each run also writes <YYYY-MM-DD>.json into
--out <dir>, by default <journal dir>/harness-review, with the date, the model
the review is for, the newest_model and the rows. --model <id> names the
reviewed model; without it the review is for the model with the most Bash
calls in the transcripts (not the newest, which may have barely started), and
the output says which. Compliance rows, the shadow arm shares and the replay
count cover that model's calls only (a session that also holds another
model's calls is left out of the arm shares). The newest model is the one
first seen on the latest day in the transcripts' Bash calls.
greenbelay harness-review [--json] [--model <id>] [--transcripts <dir>] [--since <date>] [--out <dir>]
greenbelay harness-review --check
--check reads the newest review file and takes the default model (most
Bash calls) of the transcripts. It prints one line and exits 1 in three cases:
that model is not the review's model, no review exists, or the newest review file cannot be read
or parsed (the line names the file). Otherwise it prints nothing and exits 0. The weekly retro runs it (harness.revisit-on-a-new-model): a new model
starts a harness review, and running harness-review records it. Keeping or
retiring a part stays the person's decision.
5. Graduate — promote on the evidence
greenbelay graduate bare-stash-pop --to advise
greenbelay graduate bare-stash-pop --to deny
Promotion is gated on the corpus: a rule cannot be promoted past a corpus that does not support it.
Demotion is not gated at all
greenbelay demote bare-stash-pop
No questions, no evidence required, effective on the next command. This asymmetry is deliberate. A guard that is hard to back out of is one people uninstall instead of demoting — and uninstalling takes every rule with it, including the ones that were working.