Autonomy ladder: a run card per task

Map nine task profiles to a rung of the permission ladder and read the run card each one gets: the cap that binds, the exact command line, the settings rules, the turn and dollar caps and the checkpoints. Then promote or demote task types from a run history, the way trust calibration says to.

  • Python 3.9+
  • standard library only
  • offline: ladder/tasks.json and ladder/run_history.jsonl
  • no claude binary

Each task profile says whether it writes (nothing, the repo, or something external), whether that's reversible, how it's verified, whether someone is watching, where it runs, and its track record. The script works out two numbers: the rung the job needs (who is watching, does it write) and the rung its risk may use. If the risk allows what the job needs, the task gets it. If not, the task is NOT READY to run that way and falls back to the rung it would get with someone watching, and the reason is the "binding cap". tasks.json and the outer wrapper of each history line are lab formats; each history line's result object uses the documented result-event fields.

python3 autonomy-1/autonomy_ladder.py
┌────────────────────────────────────────────────────┐
│ Autonomy ladder: task -> mode, budget, checkpoints │
└────────────────────────────────────────────────────┘
[1] The ladder (how much Claude may do before a human approves)
rung  name                              --permission-mode  runs without asking                                                                          use when                                                                          
────  ────────────────────────────────  ─────────────────  ───────────────────────────────────────────────────────────────────────────────────────────  ──────────────────────────────────────────────────────────────────────────────────
0     Look, don't touch                 plan               reads (plus classifier-approved commands when auto mode is available)                        exploring, planning, or any read-only job                                         
1     Approve edits and commands        default            reads and built-in read-only commands (UI label: Manual)                                     irreversible or external side effects; first runs of a new kind of task           
2     Edits flow, commands ask          acceptEdits        reads, edits, and mkdir/touch/rm/rmdir/mv/cp/sed in scope                                    attended feature work in a worktree                                               
3     Classifier-reviewed               auto               everything, with background safety checks                                                    attended or loosely attended work with deny rules and a check to run              
4     Unattended, pre-approved scope    dontAsk            working-dir reads, read-only Bash, pre-approved tools; anything that would prompt is denied  headless runs in CI or a worktree, with exact --allowedTools and caps             
5     Bypass in a disposable container  bypassPermissions  everything (deny rules still apply)                                                          isolated containers and VMs only, non-root, no secrets; the labs never generate it
  Deny rules block in every mode, bypassPermissions included; hooks and the classifier are layers, not the boundary.
[2] Decisions
task                    needs  may  rung  mode         turns  budget  status     binding cap                                               
──────────────────────  ─────  ───  ────  ───────────  ─────  ──────  ─────────  ──────────────────────────────────────────────────────────
map-discounts           0      4    0     plan         5      $0.20   ready      none: the task needs only rung 0                          
nightly-audit           4      4    4     dontAsk      5      $0.20   ready      none: the task needs only rung 4                          
case-insensitive-codes  2      3    2     acceptEdits  10     $0.40   ready      none: the task needs only rung 2                          
refactor-receipt        3      4    3     auto         25     $1.00   ready      none: the task needs only rung 3                          
dependency-bumps        4      4    4     dontAsk      25     $1.00   ready      none: the task needs only rung 4                          
unattended-new-feature  4      3    2     acceptEdits  40     $1.60   NOT READY  track record 0 < 3 clean runs: earn unattended runs first 
copy-tweak              4      2    2     acceptEdits  10     $0.40   NOT READY  verification=manual: no check a machine can run, so a huma
rotate-tax-table        4      1    1     default      25     $1.00   NOT READY  irreversible external write: a human approves each irrever
sandbox-fuzz            4      5    4     dontAsk      25     $1.00   ready      none: the task needs only rung 4                          
…
nightly-audit: Nightly: list TODOs and functions without tests, post a summary
  rung: 4 Unattended, pre-approved scope (mode dontAsk)  status ready
    - unattended: nobody answers prompts, so every action must be pre-approved (rung 4)
    - cap 4: not an isolated container, so never bypassPermissions
    - budget: 5 turns x $0.0265/turn (claude-sonnet-5-5: 40,000 cached-read + 3,000 cache-write + 1,500 output tokens) x 1.5 headroom = $0.20
  command: claude -p '<task: Nightly: list TODOs and functions without tests, post a summary>' --output-format json --max-turns 5 --max-budget-usd 0.2 --permission-mode dontAsk --tools Read,Grep,Glob --allowedTools Read,Grep,Glob --disallowedTools 'mcp__*' --strict-mcp-config --settings '{"disableAllHooks":true}'
  settings: {"permissions": {"deny": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)"]}}
    * cap: --max-turns and --max-budget-usd; read stop_reason, then terminal_reason, then subtype and permission_denials, from the result event
    * escalate: on stop_reason refusal, error_max_turns, error_max_budget_usd, a failed gate or any permission denial, a human looks
…
rotate-tax-table: Apply the new tax table to the production pricing database
  rung: 1 Approve edits and commands (mode default)  status NOT READY
    - unattended: nobody answers prompts, so every action must be pre-approved (rung 4)
    - cap 1: irreversible external write: a human approves each irreversible step
    - cap 2: verification=manual: no check a machine can run, so a human reviews the result
    - cap 3: track record 2 < 3 clean runs: earn unattended runs first
    - cap 3: secrets or production within reach: sandbox + deny rules, and someone watching
    - cap 4: not an isolated container, so never bypassPermissions
    - wants rung 4 (unattended) but the ceiling is 1: run it attended at rung 1 (what it gets with someone watching) first, or split it
    - budget: 25 turns x $0.0265/turn (claude-sonnet-5-5: 40,000 cached-read + 3,000 cache-write + 1,500 output tokens) x 1.5 headroom = $1.00
  command: claude --worktree rotate-tax-table --permission-mode default
  settings: {"permissions": {"deny": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)", "Read(~/.ssh/**)", "Read(~/.aws/**)", "Read(~/.config/gh/**)"], "ask": ["Bash(psql *)", "Bash(git push *)", "Bash(terraform apply *)"]}, "sandbox": {"enabled": true, "failIfUnavailable": true, "filesystem": {"denyRead": ["~/.ssh", "~/.aws", "~/.config/gh"]}}}
    * before: plan first (/plan or --permission-mode plan) and approve the plan
    * isolate: claude --worktree <name> (or a CI checkout); Claude's edits never land on your main checkout
    * approve irreversible commands one by one: put them in permissions.ask (no mode auto-approves an explicit ask rule)
    * contain: sandbox.enabled + failIfUnavailable, and Read deny rules for secret paths
    * cap: --max-turns and --max-budget-usd; read stop_reason, then terminal_reason, then subtype and permission_denials, from the result event
    * escalate: on stop_reason refusal, error_max_turns, error_max_budget_usd, a failed gate or any permission denial, a human looks
    * after: a human reviews the diff or PR before merge (/rewind restores edits, not Bash side effects)
    split: an unattended run (rung 4, repo writes only) prepares the change as a reviewed PR with a dry-run report; a human applies it at rung 1
    note: the config value is `default`; every UI calls it Manual (CLI alias `manual`)
…
[4] Trust calibration from past runs (ladder/run_history.jsonl)
task type               runs  rung  clean streak  spend  advice                                                                                                                                                         
──────────────────────  ────  ────  ────────────  ─────  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
case-insensitive-codes  1     2     1             $0.09  stay at rung 2 (1/3 clean in a row)                                                                                                                            
copy-tweak              3     2     3             $0.18  stay at rung 2: 3 clean runs, but capped at 2 (verification=manual)                                                                                            
dependency-bumps        3     4     3             $1.24  stay at rung 4 (3 clean in a row; rung 4 is the top outside a disposable container)                                                                            
docs-sync               3     4     0             $1.20  demote to rung 3 (terminal_reason=max_turns, subtype=error_max_turns, 1 permission denial(s); review the transcript before retrying)                           
refactor-receipt        4     2     4             $1.05  promote to rung 3 (4 clean runs in a row)                                                                                                                      
weekly-digest           2     4     1             $0.09  stay at rung 4 (1 clean in a row; rung 4 is the top outside a disposable container) [1 inconclusive run(s) ignored: an API failure says nothing about the task]
  A run is clean when stop_reason isn't refusal, terminal_reason is completed and subtype is success (checked in that order), permission_denials is empty, the gate verified it and nobody had to step in.

wrote autonomy-1/out/autonomy_ladder/run_cards.json and autonomy-1/out/autonomy_ladder/run_cards.md
6/9 tasks ready at their requested level of supervision
  1. The floor under every rung. Deny rules hold even in bypassPermissions; hooks and the auto-mode classifier are layers on top, not the boundary.
  2. Three tasks want rung 4 (unattended) and are refused it. Each falls back to the rung it would get with someone watching, and the binding cap gives the one reason to tell a teammate.
  3. The container task may go to rung 5 but needs only rung 4, so it gets dontAsk. No card ever prints a bypass command.
  4. An unattended read-only job: dontAsk with the same three tools in --tools and --allowedTools, MCP blocked, repo hooks off, and both caps on the command line.
  5. The production task puts psql, git push and terraform apply in permissions.ask, which no mode auto-approves, and denies reads of the credential folders.
  6. Calibration from the history: docs-sync is demoted after a max-turns stop with a permission denial, refactor-receipt is promoted after four clean runs, and weekly-digest's API-error run is ignored as inconclusive.

Run your own task through the same rules. The flags describe its profile:

python3 autonomy-1/autonomy_ladder.py --task "Fix flaky test" --writes repo --verification tests \
    --unattended --environment ci --track-record 3 --size S
[2] Decisions
task    needs  may  rung  mode     turns  budget  status  binding cap                     
──────  ─────  ───  ────  ───────  ─────  ──────  ──────  ────────────────────────────────
ad-hoc  4      4    4     dontAsk  10     $0.40   ready   none: the task needs only rung 4
[3] Run cards

ad-hoc: Fix flaky test
  rung: 4 Unattended, pre-approved scope (mode dontAsk)  status ready
    - unattended: nobody answers prompts, so every action must be pre-approved (rung 4)
    - cap 4: not an isolated container, so never bypassPermissions
    - budget: 10 turns x $0.0265/turn (claude-sonnet-5-5: 40,000 cached-read + 3,000 cache-write + 1,500 output tokens) x 1.5 headroom = $0.40
  command: claude -p '<task: Fix flaky test>' --output-format json --max-turns 10 --max-budget-usd 0.4 --permission-mode dontAsk --tools Read,Grep,Glob,Edit,Write,Bash --allowedTools 'Read,Grep,Glob,Edit,Write,Bash(python3 -m unittest *)' --disallowedTools 'mcp__*' --strict-mcp-config
  settings: {"permissions": {"deny": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)"], "allow": ["Bash(python3 -m unittest *)"]}, "sandbox": {"enabled": true, "failIfUnavailable": true}}
    * isolate: claude --worktree <name> (or a CI checkout); Claude's edits never land on your main checkout
    * gate the stop: the goal_gate Stop hook runs the tests itself and writes evidence (see goal_loop.py)
    * hand off: Claude can't push or open a PR with these tools; the pipeline does that after the tests pass (autonomy-4 gha_pipeline: verify, then open_pr)
    * cap: --max-turns and --max-budget-usd; read stop_reason, then terminal_reason, then subtype and permission_denials, from the result event
    * escalate: on stop_reason refusal, error_max_turns, error_max_budget_usd, a failed gate or any permission denial, a human looks
    * after: a human reviews the diff or PR before merge (/rewind restores edits, not Bash side effects)
    note: hooks stay on in this command because the Stop gate is a hook; only do that in a repo you trust
  1. Three clean runs meet the lab's promotion bar, so nothing caps this task below the rung 4 it needs: ready to run unattended.
  2. Size S means 10 turns, priced with 1.5× headroom at $0.40. The only command Claude may run is Bash(python3 -m unittest *); it can edit, but it can't push.
  3. The Stop gate from the next lab decides when the run may end, and the pipeline, not Claude, opens the PR once the tests pass.
  4. Unlike the read-only job, this command leaves hooks on, because the gate is a hook. That's only safe in a repo whose committed hooks you trust.
  • Rerun the ad-hoc task with --track-record 0. It turns NOT READY with "track record 0 < 3 clean runs", drops to acceptEdits in a worktree, and the card loses its -p command.
  • Swap in --environment container. The "may" column reads 5, the rung stays 4 (dontAsk), and the card still has no bypass command.
  • Add --writes external --irreversible. The cap drops to 1 (mode default), and the settings gain the three permissions.ask rules.
  • Exercise 1 from the docstring: copy ladder/tasks.json, set copy-tweak's verification to tests, and pass the copy with --tasks my-tasks.json --only copy-tweak. It goes from rung 2 NOT READY to rung 4 ready, and its history advice changes from "capped at 2" to "promote to rung 3".
  • Break it: append a refusal to a copy of the history and pass it with --history. weekly-digest goes from "stay at rung 4" to "demote to rung 3 (stop_reason=refusal …)", even though the line says subtype: "success" and terminal_reason: "api_error". A gate that checked terminal_reason first would have ignored it as an API failure.
    cp autonomy-1/ladder/run_history.jsonl /tmp/my-history.jsonl
    echo '{"task_type": "weekly-digest", "rung": 4, "verified": false, "escalated": false, "result": {"type": "result", "subtype": "success", "stop_reason": "refusal", "terminal_reason": "api_error"}}' >> /tmp/my-history.jsonl
    python3 autonomy-1/autonomy_ladder.py --history /tmp/my-history.jsonl
  • Read the binding-cap column first. It's the sentence that explains to a teammate why a task doesn't get more autonomy.
  • Irreversible external work is split, not promoted: an unattended run prepares a reviewed PR with a dry-run report, and a human applies it at rung 1.
  • The credential-folder Read denies are there because built-in read-only commands such as cat run without a prompt.
  • Calibration reads stop_reason, then terminal_reason, then subtype, the documented order. An API error is inconclusive; a refusal never is.
  • The budgets are illustrative: they price the lab's per-turn token guess at common/llm.py's list prices with 1.5× headroom. Calibrate yours from real total_cost_usd values.

Goal gate: a Stop hook that runs the check

Drive a real Stop hook, goal_gate.py, through nine scripted scenarios against a temp copy of the sample repo, where the tests really run. See why a pipeline should trust the gate's evidence file and not the run's exit status, and how the loop's budgets end it. Session background: /goal conditions, escalation and the unattended-run recipe.

  • Python 3.9+
  • standard library only
  • offline: scripted turns, the real hook, real python3 -m unittest
  • a temp copy of common/samples/tiny-app

"Claude" here is a fixed list of turns: it edits files and claims it's done. Everything after that is real. common/hooks.run_hook runs the kit's hook command as a subprocess with a documented Stop input, the hook runs the test suite, and its JSON output is interpreted the way Claude Code would: block and continue, or let Claude stop.

python3 autonomy-1/goal_loop.py
┌───────────────────────────────────────────────────┐
│ Goal loop: a Stop hook that gates on a real check │
└───────────────────────────────────────────────────┘
[1] Validate the kit (goal_gate/kit/.claude)
  Stop hook: python3 "$CLAUDE_PROJECT_DIR"/.claude/hooks/goal_gate.py
  goal.json: {"goal": "The test suite passes: python3 -m unittest exits 0", "checks": [{"name": "python3 -m unittest -q", "argv": ["python3", "-m", "unittest", "-q"], "timeout_s": 240}], "max_check_seconds": 240, "max_continuations": 3, "max_wall_minutes": 60, "max_deferrals": 3}
  /goal does the same job with a model that reads the conversation and runs no commands; this gate runs the check itself.
…
[A] converges: "Make discount codes case-insensitive and add a test"
  turn 1  tests/test_pricing.py: + test_lowercase_code               tools=2 $0.042  says: Done: discount codes are case-insensitive and there's a tes…
          Stop -> BLOCK (gate continuation 1, in a row: 1)
          Claude reads: FAIL: test_lowercase_code (tests.test_pricing.DiscountTest); AssertionError: 0 != 200; Continuation 1 of 3
  turn 2  tinyapp/pricing.py: apply_discount upper-cases the code    tools=2 $0.051  says: Fixed apply_discount to upper-case the code; the suite pass…
          Stop -> allowed
  outcome: stopped
  pipeline: naive (exit code only) PASS, evidence-based PASS (verified); tests actually pass
…
[C] typo in goal.json, naive gate (fails open): "Make discount codes case-insensitive and add a test"
    setup: goal.json says "chekcs" instead of "checks"
    Stop hook: naive crash (not the kit's gate)
  turn 1  tests/test_pricing.py: + test_lowercase_code               tools=2 $0.042  says: Done: discount codes are case-insensitive and there's a tes…
          Stop -> allowed: the hook failed (Failed with non-blocking status code: Traceback (most recent call last):)
  outcome: stopped
  pipeline: naive (exit code only) PASS, evidence-based FAIL (no evidence file); tests actually FAIL

[D] same typo, the kit's gate (fails closed): "Make discount codes case-insensitive and add a test"
    setup: goal.json says "chekcs" instead of "checks"
  turn 1  tests/test_pricing.py: + test_lowercase_code               tools=2 $0.042  says: Done: discount codes are case-insensitive and there's a tes…
          Stop -> allowed, user sees: goal gate error: goal.json needs a non-empty "checks" list. The run is NOT verified; fix …
  outcome: stopped
  pipeline: naive (exit code only) PASS, evidence-based FAIL (state=gate_error); tests actually FAIL
…
[G] a hook that always blocks: "Polish the README"
    setup: Claude answers without calling a tool, so the in-a-row count never resets
    Stop hook: always block (not the kit's gate)
  turn 1  no edits                                                   tools=0 $0.006  says: I believe the work is complete.
          Stop -> BLOCK (in a row: 1/8)
          Claude reads: Keep going until it is perfect.
  turn 2  no edits                                                   tools=0 $0.006  says: I believe the work is complete.
          Stop -> BLOCK (in a row: 2/8)
          Claude reads: Keep going until it is perfect.
          ... the same block, turn after turn ...
          Stop -> BLOCK (in a row: 8/8)
          Claude reads: Keep going until it is perfect.
  turn 9  Stop -> hook blocks again -> OVERRIDDEN by the 8-continuation cap
  outcome: Claude Code overrode the hook after 8 consecutive continuations and ended the turn
  pipeline: naive (exit code only) PASS, evidence-based FAIL (no evidence file); tests actually pass
…
[3] Summary
   scenario                                    turns  blocks  spend  result subtype        gate state  escalations  naive  evidence  tests
─  ──────────────────────────────────────────  ─────  ──────  ─────  ────────────────────  ──────────  ───────────  ─────  ────────  ─────
A  converges                                   2      1       $0.09  success               verified    0            PASS   PASS      pass 
B  conflicting requirement -> escalates        4      3       $0.20  success               escalated   1            PASS   FAIL      FAIL 
C  typo in goal.json, naive gate (fails open)  1      0       $0.04  success               -           0            PASS   FAIL      FAIL 
D  same typo, the kit's gate (fails closed)    1      0       $0.04  success               gate_error  1            PASS   FAIL      FAIL 
E  dollar cap trips first                      3      2       $1.65  error_max_budget_usd  not_met     0            FAIL   FAIL      FAIL 
F  background work defers the check            2      0       $0.04  success               verified    0            PASS   PASS      pass 
G  a hook that always blocks                   9      8       $0.05  success               -           0            PASS   FAIL      pass 
H  Claude works in a worktree                  2      1       $0.09  success               verified    0            PASS   PASS      pass 
I  stale evidence from an earlier turn         2      0       $0.05  success               gate_error  1            PASS   FAIL      FAIL 
  The naive pipeline passed failing code in scenario B, C, D, I; the evidence check didn't.

evidence and traces: autonomy-1/out/goal_loop/<scenario>/
install: cp -r autonomy-1/goal_gate/kit/.claude <repo>/  (then require status-<session_id>.json verified=true)
  1. The first stop is blocked. The reason Claude reads next is the failing assertion from a real test run, plus the gate's own continuation count.
  2. A hook that crashes is a non-blocking error, so Claude simply stops. onFailure: "block" can't change that: it has no effect on Stop hooks.
  3. Same typo, the kit's gate. It still lets Claude stop, because blocking on its own broken config would only loop, but it tells the user and writes gate_error evidence instead of nothing.
  4. Claude Code's own loop guard: after eight blocks in a row by default (CLAUDE_CODE_STOP_HOOK_BLOCK_CAP changes it), it overrides the hook. It fires here only because Claude called no tool between stops.
  5. --max-budget-usd 1.50 ended the run at $1.65 with error_max_budget_usd. Spend can pass the cap by up to one response, so leave headroom.
  6. The point of the lab: trusting the exit status passed failing code four times. Requiring the gate's "verified": true evidence didn't.

The evidence the pipeline reads is one small JSON file per session. Read scenario A's right after the default run, before any --scenario run: those replace out/goal_loop/ with only their own scenarios.

cat autonomy-1/out/goal_loop/A/gate/status-goal-lab-A.json
{
  "session_id": "goal-lab-A",
  "goal": "The test suite passes: python3 -m unittest exits 0",
  "state": "verified",
  "verified": true,
  "continuations": 1,
  "stops": 2,
  "checks": [
    {
      "name": "python3 -m unittest -q",
      "exit": 0,
      "passed": true,
      "tail": "----------------------------------------------------------------------\nRan 14 tests\n\nOK"
    }
  ],
  "workdir": "<tiny-app copy>",
  "updated_at": "2026-10-20T09:04:00Z"
}
  1. The two fields a pipeline gates on. Every stop first overwrites them with "checking" and false, so a crash mid-check can't leave an old true standing.
  2. One block, two stops: the same story as scenario A's trace.
  3. The tail of the test run that justified verified, kept as evidence.
  4. Where the checks ran: the git toplevel of the hook input's cwd, which follows Claude into a worktree (here the cwd itself: the sample repo isn't a git repo). The lab replaces the temp path so out/ is the same on every run.

Scenario B shows a goal Claude can't and shouldn't win: an existing test encodes the old tax rate. --verbose prints each block reason in full, which is exactly what Claude reads before its next turn:

python3 autonomy-1/goal_loop.py --scenario B --verbose
[B] conflicting requirement -> escalates: "Set NY sales tax to 4.5%"
  turn 1  tinyapp/pricing.py: NY 400 -> 450 bps                      tools=2 $0.048  says: NY tax is now 4.5%.
          Stop -> BLOCK (gate continuation 1, in a row: 1)
          Claude reads:
            Goal not met: The test suite passes: python3 -m unittest exits 0
            Check `python3 -m unittest -q` exited 1. Last lines:
            ======================================================================
            FAIL: test_region_is_case_insensitive (tests.test_pricing.TaxTest)
            ----------------------------------------------------------------------
            Traceback (most recent call last):
              File "tests/test_pricing.py", line 22, in test_region_is_case_insensitive
                self.assertEqual(tax_for(1000, "ny"), 40)
            AssertionError: 45 != 40
            
            ----------------------------------------------------------------------
            Ran 13 tests
            
            FAILED (failures=1)
            Continuation 1 of 3: fix the cause, not the check, and stop again when you believe it passes. If the goal conflicts with a requirement, say so plainly.
…
  turn 3  tinyapp/pricing.py: tax_for back to half up                tools=3 $0.057  says: Reverted the rounding change; the NY test still expects the…
          Stop -> BLOCK (gate continuation 3, in a row: 1)
          Claude reads:
            Goal not met: The test suite passes: python3 -m unittest exits 0
            Check `python3 -m unittest -q` exited 1. Last lines:
            ======================================================================
            FAIL: test_region_is_case_insensitive (tests.test_pricing.TaxTest)
            ----------------------------------------------------------------------
            Traceback (most recent call last):
              File "tests/test_pricing.py", line 22, in test_region_is_case_insensitive
                self.assertEqual(tax_for(1000, "ny"), 40)
            AssertionError: 45 != 40
            
            ----------------------------------------------------------------------
            Ran 13 tests
            
            FAILED (failures=1)
            Continuation 3 of 3: fix the cause, not the check, and stop again when you believe it passes. If the goal conflicts with a requirement, say so plainly.
  turn 4  no edits                                                   tools=1 $0.033  says: test_region_is_case_insensitive encodes the 4% NY rate. CLA…
          Stop -> allowed, user sees: Goal not met (3 continuation(s) used of 3): The test suite passes: python3 -m unittest ex…
  outcome: stopped
  pipeline: naive (exit code only) PASS, evidence-based FAIL (state=escalated); tests actually FAIL
  1. The block reason opens with the goal and the check's exit code, so Claude knows what "done" means and that it isn't there.
  2. The real assertion: tax_for(1000, "ny") returns 45 and the test expects 40. No code change can satisfy both the goal and this test.
  3. The reason tells Claude to fix the cause, not the check, and to say so when the goal conflicts with a requirement. Pair that with a deny rule on test edits.
  4. The gate's own budget, 3 continuations from goal.json. Claude Code's default cap of eight wouldn't help here: it resets every time Claude calls a tool.
  5. Escalation: the gate lets Claude stop, tells the user through systemMessage, and appends a line to escalations.jsonl.
  6. The run "succeeded" by exit status. The evidence says escalated, so an evidence-based pipeline fails it.

Install the gate in a repo you trust. It's a real hook that runs commands with your permissions. From labs/:

cp -r autonomy-1/goal_gate/kit/.claude <your-repo>/   # merge settings.json by hand if you already have one
FileWhat it is
.claude/settings.jsonOne Stop command hook: python3 "$CLAUDE_PROJECT_DIR"/.claude/hooks/goal_gate.py, timeout 300, a statusMessage. No matcher: Stop doesn't support one.
.claude/hooks/goal_gate.pyThe gate. Runs the checks, blocks with the failure as the reason, escalates when its budget is used, writes evidence. Python 3.9+, stdlib only.
.claude/goal.jsonLab format. The goal text, the checks as argv lists (no shell strings), max_check_seconds, max_continuations, max_wall_minutes and max_deferrals.
.claude/goal-gate/Written at run time: state-<session>.json, status-<session>.json (the evidence) and escalations.jsonl.

The script's docstring shows a real run against the installed gate. It isn't part of this lab: it edits files and costs money.

cd <repo> && claude -p "Make discount codes case-insensitive and add a test" --output-format json \
    --permission-mode acceptEdits --allowedTools "Bash(python3 -m unittest *)" --max-turns 30 --max-budget-usd 2
# then require <repo>/.claude/goal-gate/status-<session_id>.json to say "verified": true
  • Set max_wall_minutes to 3 in goal_gate/kit/.claude/goal.json and rerun --scenario B. Each scripted turn takes 2 minutes, so the wall clock trips on the third stop ("Goal not met (4 of 3 minutes used)") after two blocks, not three. Put the file back afterwards.
  • Set max_continuations to 1 and run --scenario A --scenario B. A still verifies, since it needed only one block; B escalates after one.
  • Break it: lower the hook's timeout in the kit's settings.json from 300 to 60. The kit check refuses to run ("max_check_seconds (240) must stay well under the hook's timeout (60s), or Claude Code cancels the gate mid-check") and exits 1.
  • Break it: add "matcher": "*" to the Stop group. The kit check reports "Stop has no matcher support; a matcher there is silently ignored" and exits 1.
  • The naive and evidence columns of the summary. A pipeline passes a run only if status-<session_id>.json says "verified": true.
  • Stop hooks fail open, so the gate fails closed in its own code (C versus D) and the pipeline treats a missing record as a failure.
  • The gate counts its own continuations and minutes. Claude Code's eight-in-a-row cap (the default) resets on every tool call, so it bounds only a loop where Claude does nothing (G).
  • Checks run in the hook input's cwd. CLAUDE_PROJECT_DIR stays at the project root when Claude enters a worktree, so the gate uses it only to find goal.json (scenario H).
  • The gate decides when a run may stop, not what Claude may do while it works. Permission deny rules and the sandbox do that.