Criteria to evidence, from the transcript

Grade each acceptance criterion against what the tool calls in a stream-json transcript prove. Did a check run? Did it run after the last edit it depends on? Did an edit contradict it, or did the agent only say so? Then turn the gaps into an evidence request and a /goal line. Session: Completion Evidence and Requirements Coverage.

  • Python 3.9+
  • standard library only
  • offline: samples/edit_session.jsonl and samples/criteria.json
python3 delivery-4/acceptance_gate.py

The transcript is lab-made, built from real edits and real test runs on a temp copy of tiny-app (see samples/README.md); its token counts, durations and cost are illustrative. The session edits pricing.py and its tests, runs the suite, edits pricing.py again to add a SPRING15 code, runs the receipt CLI, and ends: "All acceptance criteria are met."

┌───────────────────────────────────────┐
│ Acceptance gate · criteria → evidence │
└───────────────────────────────────────┘
  transcript: delivery-4/samples/edit_session.jsonl
  run: success · 8 turns · tool calls {'Bash': 2, 'Edit': 3, 'Read': 2} · denials 0

[1] Timeline: when each check ran and each file changed (step = event index)
step  tool  target                                              result  added   
────  ────  ──────────────────────────────────────────────────  ──────  ────────
8     Edit  tinyapp/pricing.py                                  ok      +2 lines
10    Edit  tests/test_pricing.py                               ok      +4 lines
12    Bash  python3 -m unittest                                 ok              
15    Edit  tinyapp/pricing.py                                  ok      +1 lines
17    Bash  python3 -m tinyapp.cli --code welcome10 apple:1000  ok              

[2] Criteria → evidence
id   level   verdict       criterion                                                     
───  ──────  ────────────  ──────────────────────────────────────────────────────────────
AC1  MUST    VERIFIED      A unit test covers a lower-case discount code                 
AC2  MUST    STALE         The full test suite passes after the last code change         
AC3  MUST    CONTRADICTED  Discount codes and their percentages are unchanged (no new co…
AC4  MUST    VERIFIED      TAX_BPS values are unchanged (CLAUDE.md: don't change them wi…
AC5  SHOULD  VERIFIED      The receipt CLI applies a lower-case code                     
AC6  SHOULD  CLAIMED       Codes with surrounding whitespace are accepted                
AC7  MUST    MISSING       Unknown codes still get no discount                           

  AC2: stale: `python3 -m unittest` passed at step 12, then tinyapp/pricing.py changed at step 15
  AC3: contradicted: step 15 Edit added `DISCOUNTS: Dict[str, int] = {"WELCOME10": 10, "VIP25": 25, "SPRING15": 15}`
  AC6: missing: no edit to tests/*.py adds /apply_discount\([^)]*"\s+\w+|\w+\s+"\)/
  AC6: claim: "Done: discount codes are now case-insensitive and trimmed, so `welcome10`, `Vip25` and ` WELCOME10 ` all work."
  AC7: missing: `python3 -m unittest .*-v|python3 -m unittest -v|pytest .*-v` never ran

[3] Gate
  FAIL: 2/5 MUST criteria verified; not verified: AC2, AC3, AC7
  the agent's last sentence: All acceptance criteria are met.

[4] Evidence request to paste back into the session
  Before you call this done, show evidence for these acceptance criteria:
  - AC2 (The full test suite passes after the last code change): the passing run is older than your last edit. Re-run it now: `python3 -m unittest` exits 0 and prints OK. Paste the output.
  - AC3 (Discount codes and their percentages are unchanged (no new codes)): this is currently broken (step 15 Edit added `DISCOUNTS: Dict[str, int] = {"WELCOME10": 10, "VIP25": 25, "SPRING15": 15}`). Fix it, then show it: `git diff tinyapp/pricing.py` shows the DISCOUNTS line unchanged.
  - AC6 (Codes with surrounding whitespace are accepted): you said "Done: discount codes are now case-insensitive and trimmed, so `welcome10`, `Vip25` and ` WELCOME10 ` all work." but no tool call shows it. Prove it: a test calls apply_discount with " WELCOME10 " and `python3 -m unittest` passes.
  - AC7 (Unknown codes still get no discount): no evidence yet. `python3 -m unittest -v` lists `test_unknown_code ... ok`; show the output.
  Don't summarize: paste the command output for each item, and list any criterion you couldn't meet.

[5] /goal for the gaps (414 of 4000 characters; the evaluator only reads the conversation)
  /goal All of these hold in output you show after your last edit: `python3 -m unittest` exits 0 and prints OK; a test calls apply_discount with " WELCOME10 " and `python3 -m unittest` passes; `python3 -m unittest -v` lists `test_unknown_code ... ok`. Constraints: `git diff tinyapp/pricing.py` shows the DISCOUNTS line unchanged; `git diff tinyapp/pricing.py` shows the TAX_BPS line unchanged; or stop after 8 turns

  wrote: delivery-4/out/acceptance_report.md, delivery-4/out/acceptance_report.json
  1. The timeline is the whole method: every check and every edit, in order. The suite ran at step 12, and pricing.py changed again at step 15.
  2. STALE: the tests passed, but before the last edit in their scope. A green run from before the last edit isn't evidence.
  3. CONTRADICTED: a negative criterion is checked against the lines each edit added, and step 15 added the code AC3 rules out.
  4. CLAIMED: the final message says whitespace works, but no tool call shows it.
  5. The gate verifies only 2 of 5 MUST criteria (AC2, AC3 and AC7 fail) while the agent's last sentence says all acceptance criteria are met. "Done" is a claim; the gate reads the evidence.
  6. The gaps as a /goal condition: checks Claude must show after its last edit, the constraints, and a turn bound, in 414 of the 4,000 characters allowed.
  • --strict exits 1 unless every MUST is VERIFIED: the CI form of this gate.
  • --transcript common/fixtures/stream/permission_denied.jsonl grades a run where Bash was denied in dontAsk mode. AC2 comes out MISSING ("1 attempt(s) denied by permissions"), not CONTRADICTED: a denial isn't a failing test. AC3 and AC4 come out VERIFIED, because a run that edits nothing breaks no negative criterion.
  • Break it: in a copy of samples/criteria.json, make AC5 a MUST and change its match to "tinyapp\\.cli .*--json", then pass the copy with --criteria. The receipt run no longer counts, so AC5 drops to CLAIMED (the final message still says the CLI works), and the gate reads FAIL: 2/6 MUST criteria verified.
  • Grade a real run of your own, recorded in a scratch copy with claude -p … --output-format stream-json --verbose --permission-mode acceptEdits --allowedTools "Bash(python3 -m unittest *)" --max-turns 12 --max-budget-usd 1 > my_run.jsonl (the full command is in the docstring). Without the allow rule, a -p run can't prompt, so the test run is denied. Did Claude rerun the tests after its last edit?
  • The five verdicts: VERIFIED, STALE, CONTRADICTED, CLAIMED, MISSING. Only the first one is evidence.
  • Negative criteria need their own checks, and this gate sees only Edit and Write calls. A change made through Bash (sed -i, a redirect) doesn't show up as an edit, and the report warns when such commands ran.
  • The evidence request asks for output, not reassurance: run this, paste the output, list what you couldn't meet.
  • The /goal evaluator reads only the conversation and doesn't run commands or read files, so every clause names output Claude must show (/goal).

Which reviewer covers which concern

Cross a change's concerns with what each Claude Code reviewer is documented to look at, and pick the fewest reviewers that cover every high and medium concern. The reviewers include /code-review, /security-review, /simplify, /verify, ultrareview, managed Code Review, the GitHub Action, subagents, deterministic checks and people. Where nothing built in covers a concern as its main job, the lab writes a review subagent for it. Session: Review Commands, Managed Code Review and Review Subagents.

  • Python 3.9+
  • standard library only
  • offline: samples/change_profile.json (a Pro plan, with an origin remote)
python3 delivery-4/review_matrix.py
┌──────────────────────────────────────────────────┐
│ Review matrix · concerns × Claude Code reviewers │
└──────────────────────────────────────────────────┘
  change: Case-insensitive discount codes in tiny-app (apply_discount normalizes codes; new test; receipt CLI)
  environment: ci_api_key=True, claude_ai_login=True, github=True, origin_remote=True, plan=pro, runnable_app=True, zero_data_retention=False

[1] Matrix (● primary  ◐ partial  × covers it but unavailable here  + generated subagent  · no)
concern           risk    DET  SIMP  CR  SEC  VER  ULTRA  GHA  MCR  AGENT  HUM
────────────────  ──────  ───  ────  ──  ───  ───  ─────  ───  ───  ─────  ───
correctness       high    ·    ·     ●   ·    ·    ●      ◐    ×    ·      ◐  
regression        high    ●    ·     ◐   ·    ·    ◐      ·    ×    ·      ·  
spec_coverage     high    ●    ·     ·   ·    ◐    ·      ·    ·    ·      ·  
security          medium  ·    ·     ·   ●    ·    ·      ·    ×    ·      ◐  
api_compat        medium  ·    ·     ·   ·    ·    ·      ·    ·    +      ◐  
test_adequacy     medium  ◐    ·     ·   ·    ·    ·      ·    ·    +      ◐  
runtime_behavior  medium  ·    ·     ·   ·    ●    ·      ·    ·    ·      ·  
product_judgment  medium  ·    ·     ·   ·    ·    ·      ·    ·    ·      ●  
secrets           low     ◐    ·     ·   ◐    ·    ·      ·    ·    ·      ·  
cleanup           low     ·    ●     ◐   ·    ·    ·      ·    ·    ·      ·  
conventions       low     ◐    ◐     ·   ·    ·    ·      ◐    ×    ·      ·  
ui_visual         none    ·    ·     ·   ·    ◐    ·      ·    ·    ·      ◐  
performance       none    ·    ◐     ·   ·    ·    ·      ·    ·    ·      ·  
data_migration    none    ·    ·     ·   ·    ·    ·      ·    ·    ·      ◐  

  DET   deterministic checks (tests, linters, this lab's ci_gate hooks + CI job)
  SIMP  /simplify [target]
  CR    /code-review [low|medium|high|xhigh|max] (alias /review)
  SEC   /security-review
  VER   /verify
  ULTRA /code-review ultra (alias /ultrareview)
  GHA   Claude in your CI (anthropics/claude-code-action@v1)
  MCR   Code Review (managed, GitHub App)  [unavailable: plan in team/enterprise (have pro)]
  AGENT your own review subagent (.claude/agents/<name>.md)
  HUM   a human reviewer (CODEOWNERS / required reviewers)

[2] Route: the fewest reviewers that cover every high/medium concern as their documented job, in run order
  1. python3 -m unittest; python3 .claude/hooks/gate.py ci (delivery-4/ci_gate) [blocking]  covers regression, spec_coverage
     hooks give deterministic control; the only reviewer here that can be a required, blocking check (https://code.claude.com/docs/en/hooks-guide)
  2. /code-review high  covers correctness
     correctness bugs in the current diff, a PR number, branch or path; cleanup depending on model and effort; --fix applies findings, --comment posts them (https://code.claude.com/docs/en/commands)
  3. /security-review  covers security
     the diff between your branch and origin's default branch: injection, auth issues, data exposure; needs an origin remote (https://code.claude.com/docs/en/commands)
  4. /verify  covers runtime_behavior
     builds the app, runs it and observes the result rather than relying on tests; /run-skill-generator teaches it how to launch your app (https://code.claude.com/docs/en/commands)
  5. @agent-api-compat-reviewer  covers api_compat (generated: delivery-4/out/agents/api-compat-reviewer.md)
  6. @agent-test-adequacy-reviewer  covers test_adequacy (generated: delivery-4/out/agents/test-adequacy-reviewer.md)
  7. human reviewer [blocking]  product_judgment; final approval (a high-risk concern is present)

  optional: /code-review ultra (alias /ultrareview) also covers correctness (a cloud sandbox; costs more)

[3] Gaps and partial coverage
  api_compat (medium): no built-in primary reviewer; partial: none → generated subagent
  product_judgment (medium): no built-in primary reviewer; partial: none → human
  test_adequacy (medium): no built-in primary reviewer; partial: DET → generated subagent

[4] Generated review subagents (validated against the documented frontmatter)
  delivery-4/out/agents/api-compat-reviewer.md: valid
  delivery-4/out/agents/test-adequacy-reviewer.md: valid
  install: cp delivery-4/out/agents/*.md <repo>/.claude/agents/   then: @agent-<name> or "use the <name> subagent on this diff"

  wrote: delivery-4/out/review_matrix.md, delivery-4/out/agents/
  1. Correctness has two primary reviewers, /code-review and /code-review ultra. Managed Code Review would cover it too (×), but it isn't available on this plan.
  2. No built-in reviewer has API compatibility or test adequacy as its main job. + marks the review subagents the lab generates for them.
  3. Availability is part of the matrix: managed Code Review needs a Team or Enterprise plan, and /security-review needs an origin remote.
  4. The deterministic checks come first, and they're the only reviewer here that can be a required, blocking check.
  5. A person makes the product call and gives final approval, because a high-risk concern is present. No reviewer command covers product_judgment.
  6. The generated subagents pass the frontmatter check: name and description, read-only tools, a model alias. Install them into .claude/agents/.
  • --plan team: managed Code Review joins the route and covers correctness and security, so /code-review high and /security-review drop to optional passes you run before the PR exists. The deterministic gate stays the blocker.
  • Break it: --no-origin. /security-review needs an origin remote, so it leaves the route, security shows up under gaps ("no built-in primary reviewer"), and the human reviewer picks it up. How would you fix that in the repo rather than in the matrix?
  • --strict exits 1, because api_compat, test_adequacy and product_judgment have no built-in primary reviewer.
  • Open out/agents/api-compat-reviewer.md: an objective, a check list, a one-line-per-finding output format ending in VERDICT: ok | problems | unsure, and read-only boundaries. Copy it into a scratch repo's .claude/agents/ and ask Claude to "use the api-compat-reviewer subagent on the diff".
  • "It passed review" means little until you say which review. /simplify looks for cleanup and explicitly not for correctness bugs, and /verify runs the app instead of relying on tests (commands).
  • Managed Code Review advises: "A review never approves or blocks the pull request" (code review). Blocking belongs to required checks and to people.
  • The route is a greedy set cover. It takes the reviewer that covers the most uncovered risk, prefers the cheaper one on a tie, and orders the route so that anything that edits runs before the checks that must see the final diff.

One gate at stop, at ship and in CI

Validate a kit you copy into a repo, then run it. The kit runs one set of deterministic checks at three points: as a Stop hook when Claude tries to end its turn, as a PreToolUse hook on git commit, git push, gh pr create and gh pr merge, and as a required GitHub Actions job. The lab feeds the registered hook commands documented payloads in temp copies of tiny-app across 25 scenarios. Session: Hooks as Gates and CI Gates.

  • Python 3.9+
  • standard library only
  • git, for 3 of the 25 scenarios
  • the kit: ci_gate/kit/
python3 delivery-4/ci_gate/ci_gate.py

The kit is .claude/settings.json (it registers the two hooks), .claude/gate.json (the checks), .claude/hooks/gate.py (stop, pretool and ci modes) and .github/workflows/claude-gate.yml. In the "red" scenarios, tax rounding is broken in the temp copy only, so test_known_region_rounds_half_up fails. The hooks run through common/hooks.run_hook, which reads exit codes and JSON the way Claude Code does.

┌─────────────────────────────────────────────────────┐
│ ci_gate kit · Stop + PreToolUse gate and a CI check │
└─────────────────────────────────────────────────────┘
[1] Validate the kit against the documented formats
    file              finding                                                                 
──  ────────────────  ────────────────────────────────────────────────────────────────────────
ok  PreToolUse[Bash]  onFailure "block" (requires Claude Code v2.1.295+)                      
ok  settings.json     Stop → python3 "$CLAUDE_PROJECT_DIR/.claude/hooks/gate.py" stop         
ok  settings.json     PreToolUse → python3 "$CLAUDE_PROJECT_DIR/.claude/hooks/gate.py" pretool
ok  gate.json         1 check(s): unit tests                                                  
ok  gate.json         max_stop_blocks 3 (Claude Code's default cap is 8 consecutive blocks)   
ok  workflow          claude-code-action@v1                                                   
ok  workflow          gate job runs the same checks as the hooks (gate.py ci)                 
ok  workflow          claude_args caps --max-turns                                            
ok  workflow          the Claude review runs only after the gate passes (needs: gate)         

  install: cp -r delivery-4/ci_gate/kit/.claude <repo>/ && cp -r delivery-4/ci_gate/kit/.github <repo>/
  then: echo '.claude/gate/' >> <repo>/.gitignore; edit .claude/gate.json; make the `gate` job a required check
  careful: copying .claude/ overwrites an existing settings.json: merge the `hooks` block instead

[2] Scenarios: the registered hook commands, fed documented payloads in a temp copy of tiny-app
#   scenario                                               expected                        got                                 check
──  ─────────────────────────────────────────────────────  ──────────────────────────────  ──────────────────────────────────  ─────
1   Stop, tests green                                      proceeds, silent                proceeds                            ok   
2   PreToolUse `ls tinyapp`                                proceeds, checks not run        proceeds                            ok   
3   PreToolUse `echo "... git push"`                       proceeds (not a ship command)   proceeds                            ok   
4   PreToolUse `git commit`, green                         proceeds                        proceeds                            ok   
5   CI mode, green                                         exit 0                          exit 0                              ok   
6   Stop, red (first stop)                                 BLOCKED, reason names the test  BLOCKED (block)                     ok   
7   Stop, red, continuation 2                              BLOCKED (2 of 3)                BLOCKED (block)                     ok   
8   Stop, red, continuation 3                              BLOCKED (3 of 3)                BLOCKED (block)                     ok   
9   Stop, red, budget spent                                proceeds + systemMessage        proceeds + systemMessage            ok   
10  Stop, red, background task running                     proceeds (session is paused)    proceeds                            ok   
11  PreToolUse `git commit`, red                           BLOCKED (deny)                  BLOCKED (deny)                      ok   
12  PreToolUse `unittest && git push`, red                 BLOCKED (deny)                  BLOCKED (deny)                      ok   
13  PreToolUse `git -C . push`, red                        BLOCKED (deny)                  BLOCKED (deny)                      ok   
14  PreToolUse `gh pr create`, red                         BLOCKED (deny)                  BLOCKED (deny)                      ok   
15  PreToolUse `(cd tinyapp && git push)`, red             BLOCKED (deny)                  BLOCKED (deny)                      ok   
16  PreToolUse `env GIT_TRACE=1 git push`, red             BLOCKED (deny)                  BLOCKED (deny)                      ok   
17  CI mode, red                                           exit 1 + step summary           exit 1                              ok   
18  broken gate.json, `git commit`, onFailure continue     BLOCKED (deny from gate.py)     BLOCKED (deny)                      ok   
19  broken gate.json, `ls`                                 proceeds, no failure            proceeds                            ok   
20  broken gate.json, Stop, onFailure block                proceeds (no effect on Stop)    proceeds (hook failed, fail open)   ok   
21  hook timeout, `git push`, onFailure continue           proceeds (fail open)            proceeds (hook failed, fail open)   ok   
22  hook timeout, `git push`, onFailure block (kit)        BLOCKED (fail closed)           BLOCKED (hook failed, fail closed)  ok   
23  worktree red, main green: Stop (cwd = worktree)        BLOCKED (checks the worktree)   BLOCKED (block)                     ok   
24  worktree red, main green: `git push` (cwd = worktree)  BLOCKED (deny)                  BLOCKED (deny)                      ok   
25  same repo: `git push` from the main checkout           proceeds (main is green)        proceeds                            ok   

[3] What Claude and the user see
  Stop, red (first stop):
    Quality gate failed (continuation 1 of 3): unit tests.
    ✗ unit tests (`python3 -m unittest -q`, exit 1):
    ======================================================================
    FAIL: test_known_region_rounds_half_up (tests.test_pricing.TaxTest)
    …
  Stop, red, budget spent:
    Quality gate still red after 3 continuations (unit tests). Claude stopped so a human can look; commits and pushes stay blocked.
  PreToolUse `git commit`, red:
    `git commit` is blocked: the quality gate is red (unit tests).
    ✗ unit tests (`python3 -m unittest -q`, exit 1):
    ======================================================================
    FAIL: test_known_region_rounds_half_up (tests.test_pricing.TaxTest)
    …
  CI mode, red:
    ## Quality gate: FAILED
    
    | check | command | result |
    |---|---|---|
    …
  broken gate.json, `git commit`, onFailure continue:
    `git commit` is blocked: the quality gate can't read its config (.claude/gate.json is not valid JSON: Expecting property name enclosed in double quotes (line 1)). Ask the user to fix .claude/gate.json; don't work around the gate.

25/25 scenarios behaved as expected
  1. The gate has its own loop budget of 3, below Claude Code's cap of 8 consecutive Stop blocks (the default). A gate that runs tests would otherwise keep Claude "fixing" for as long as it's red.
  2. Red at stop: three blocks, each with the failing test in the reason, then it lets Claude stop and sends a systemMessage so a person looks.
  3. Two kinds of failure. A gate that can still answer (bad gate.json) denies the ship command itself, which works on every version. A Stop hook that fails lets Claude stop whatever onFailure says.
  4. A hook that times out lets the push through, unless it's registered with "onFailure": "block", as the kit does (v2.1.295+).
  5. The gate checks the git top level of the payload's cwd, which follows Claude into a worktree. $CLAUDE_PROJECT_DIR stays at the main checkout, so testing it would pass while the worktree is red.
  6. What Claude sees when it's blocked: which check failed, with its command, exit code and output tail. The panel cuts it short; -v prints the whole reason, which ends by telling Claude to fix the cause and not weaken or skip the check.

Install the kit into a repo, then make the gate job a required status check in branch protection:

cp -r delivery-4/ci_gate/kit/.claude <repo>/   # overwrites an existing settings.json: merge `hooks` instead
cp -r delivery-4/ci_gate/kit/.github <repo>/
echo ".claude/gate/" >> <repo>/.gitignore      # the Stop gate's per-session counter
  • -v prints the full reason texts, including the unittest traceback Claude receives. --validate-only checks the kit files and skips the scenarios.
  • Break it: in a scratch copy of labs/, set max_stop_blocks to 1 in kit/.claude/gate.json and rerun. Scenario 7 now lets Claude stop with the systemMessage, and the run ends 23/25 scenarios behaved as expected with exit 1: the scenario table expects the kit's budget of 3.
  • Add a second check to gate.json, for example {python} -m compileall -q tinyapp, and rerun in your scratch copy. Validation now reports 2 check(s): unit tests, compile, and all 25 scenarios still behave.
  • Write a scenario for bash -c "git push" and confirm the gate misses it. The gate matches command text, so an alias, eval or a Makefile target that pushes gets past it too. What catches it instead?

The workflow's second job, claude-review, is advisory and costs money. It runs anthropics/claude-code-action@v1 with the code-review plugin only after gate passes, and it needs the Claude GitHub App and an ANTHROPIC_API_KEY secret. The lab only validates that job's shape; it never runs it. The action is built on the Agent SDK (GitHub Actions), and Agent SDK sessions load a repo's project-scoped MCP servers without asking (MCP), so a committed .mcp.json starts in that job too: review it like code.

  • Same checks, same file, three points. "Green locally" and "green in CI" mean the same thing.
  • By default, Claude Code ends a turn after Stop hooks have continued it 8 times in a row (CLAUDE_CODE_STOP_HOOK_BLOCK_CAP changes it), and the count resets each time Claude calls a tool (hooks). A gate needs its own budget and a hand-off to a person.
  • onFailure has no effect on Stop hooks, so a crashing Stop gate always fails open (block the action when a hook fails). The required CI check is the backstop.
  • The hooks are defense in depth and early feedback. The release blocker is the required check plus branch protection, and the boundary for what Claude may run is permission deny rules plus the sandbox.