Level 4: You Write the Specs
PLLevel 4 of the autonomy ladder is the stage where a developer writes the specification, a machine-checkable stop condition and the tests that decide it, and the agent then runs unattended for hours. The human judges the result by its evidence, not by reading every diff. Level 4 holds only while the agent cannot edit the checks that define done.
This page is for developers who already run agents in parallel at Level 3 and want runs they can leave, and for tech leads who decide which work may run that way. You start a large migration at six in the evening. At eight the next morning the agent reports “all tests pass” — and one of the passing tests is the one it rewrote at 3 a.m. Level 4 is the set of habits that makes that morning impossible. CTOs and executives can go straight to the measures section.
What you get from this Level 4 guide
Section titled “What you get from this Level 4 guide”- A four-point test that tells you whether you are at Level 4 or at Level 3 with the check removed.
- The four artefacts that exist before a long run starts, and the order to write them in.
- How to start a goal-directed run in Claude Code, Codex and Cursor, with the commands.
- A Stop hook that refuses to finish while the tests are red or the test files have changed.
- Two copy-paste prompts: draft and attack a stop condition, and produce the morning evidence report.
- The morning review: how to accept or reject a twelve-hour run without reading its whole diff.
Are you at Level 4? The four-point test
Section titled “Are you at Level 4? The four-point test”Dan Shapiro’s ladder (The Five Levels: from Spicy Autocomplete to the Dark Factory, 23 January 2026) describes this rung plainly: you “write a spec”, then “leave for 12 hours, and check to see if the tests pass”. You are at Level 4 when all four statements are true:
- You write the spec and the finish line, not the code. Your working output is a spec and a condition.
- Runs last longer than you watch them. An hour or more passes without a prompt from you.
- A check you trust decides done. Tests, types and scripts decide, not the agent’s own summary.
- The run cannot rewrite that check. Test files, CI config and the hook scripts are out of its reach.
If statement 4 is false, the run grades its own homework. That is Level 3 without the reviewer, the most common way this rung fails. The one map shows how the ladder relates to the lifecycle stages and factory stations.
What four artefacts exist before a Level 4 run starts?
Section titled “What four artefacts exist before a Level 4 run starts?”None of them is code. Write them in this order, because each one is checked against the previous one.
- The spec. The outcome, the constraints and what is out of scope, in a file the run reads (
spec.md, an issue, a PRD). Spec-driven development covers keeping it authoritative, and acceptance criteria covers turning each requirement into a check. - The plan. The agent writes it in plan mode, and you read it. A plan is a page of text, not a 3,000-line diff: the cheapest review of the whole run. See plan mode across tools and Cursor’s PRD workflow. AI-DLC formalises this step: the AI drafts a plan and implements only after the team validates it.
- The oracle. The tests, types and scripts that decide whether the spec holds, written or reviewed by you before the run. Tests written first are the only part of the oracle the agent did not author, which is the Level 4 case for test-driven development: not purity, provenance. Oracle strength covers whether those checks can catch a wrong answer at all.
- The stop condition. One finish line stated as commands that must exit 0, plus a round or turn budget. The prompt below drafts it and then attacks it.
Stripe’s in-house agents show what a bounded condition looks like at scale: “at most two rounds of CI”, after which the branch goes back to a human (Stripe engineering blog, 9 February 2026). A budget is part of the condition, not an afterthought.
How do you start a goal-directed run in Claude Code, Codex and Cursor?
Section titled “How do you start a goal-directed run in Claude Code, Codex and Cursor?”All three tools have a /goal command. They differ in who checks the condition and what else you can attach to it.
Checked against Claude Code 2.1.283 (latest channel) and its /goal documentation on 26 September 2026.
# In the session: plan first, approve the plan, leave plan mode (Shift+Tab to auto mode)/plan# then set the goal; it starts a turn at once/goal all tests in test/billing pass, `npm run typecheck` exits 0, no file under test/ is modified, or stop after 30 turns/goal # status: condition, turns, token spend, last verdict/goal clear # stop earlyAfter each turn, a small, fast model (Haiku by default on the Claude API) judges whether the condition holds. It returns “not yet met”, “met” or “impossible”. The condition can be up to 4,000 characters, and one goal is active per session. A goal does not change your permission mode, so a goal set while plan mode is still on cannot edit anything. Switch to auto mode first to let turns continue unattended.
The evaluator “doesn’t run commands or read files independently”. It reads the transcript. That is why the condition above names the commands, and why the Stop hook in the next section runs them itself.
For a run from a script or CI, headless mode runs the whole loop in one call. A claude -p session starts in Manual mode, not auto (v2.1.283), so pass the permission mode explicitly or the run stalls on its first unapproved tool call:
# Terminal: auto mode for unattended turns; stream each turn so a long goal does not look stuckclaude -p "/goal CHANGELOG.md has an entry for every PR merged this week" \ --permission-mode auto --output-format stream-json --verboseFor a tighter run, replace --permission-mode auto with --allowedTools and list only the commands the goal needs.
Checked against codex-cli 0.157.1 on 26 September 2026: goals is a stable feature and on by default, and /goal sets or views “the goal for a long-running task”. Since 0.151.0, tokens spent by nested subagents count toward the goal’s budget.
# In the Codex TUI: plan first, approve the plan, then set the goal/plan/goal all tests in test/billing pass, `npm run typecheck` exits 0, no file under test/ is modified, or stop after 30 turns and report what is leftCodex’s own guidance on writing the objective (Long-running work page, checked 28 August 2026) asks for three parts: “Outcome, Constraints, Verification”. Codex also has a Stop hook event among its 12 hook events; hooks need persisted trust before they run. Codex has no /loop command (checked 28 August 2026 in the developer-commands list, and absent from the 0.157.1 binary on 26 September 2026).
Cursor announced /goal in its 19 August 2026 changelog: “Use /goal to give the agent a long-lived objective to work towards until it’s fully complete.” Its CLI slash-commands reference still marked the command “Rolling out” when checked on 28 August 2026. Plan Mode “creates detailed implementation plans before writing any code”, and Cursor hooks run “before or after defined stages of the agent loop and can observe, block, or modify behavior” (all checked 28 August 2026; cursor.com was unreachable from the writing environment on 26 September 2026). Check Cursor’s hooks documentation for the current event names before you script a stop gate.
/loop (a bundled skill since 3.5, 20 May 2026) re-runs a prompt on a local schedule until an outcome is reached or you stop it; /goal works toward one finish line without a schedule.
The /goal command walks through each tool in depth, and the /loop command covers cadence-driven runs.
How do you stop a run from finishing while the tests are red?
Section titled “How do you stop a run from finishing while the tests are red?”Use a hook: a script the tool runs at a fixed point in the loop, whatever the model decides. In Claude Code, a Stop hook runs when the agent tries to end its turn. Exit code 2 blocks the stop and sends your stderr text back to the agent as the reason to continue. Unlike the /goal evaluator, the hook runs the commands itself.
Before the run starts, record the commit it starts from, so the hook can compare against it however many times the agent commits:
git rev-parse HEAD > .claude/run-base#!/usr/bin/env bash# .claude/hooks/require-green.sh — Stop hook: no finishing while the oracle is redcd "${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel)}" || exit 0[ -f .claude/run-base ] || exit 0 # armed only during a recorded run
# 1. The oracle must be untouched: the run may not edit the tests it is graded by.# Diff against the commit recorded before the run, not HEAD, so a committed# test edit still counts, and list new untracked test files too.base=$(cat .claude/run-base)changed=$( { git diff --name-only "$base" -- test/; git ls-files --others --exclude-standard -- test/; } )if [ -n "$changed" ]; then printf 'Revert your edits to the test files and fix the code instead:\n%s\n' "$changed" >&2 exit 2fi
# 2. The oracle must be green.if ! out=$(npm test --silent 2>&1); then printf 'Tests are failing. Fix the code, not the tests:\n%s\n' "$(printf '%s' "$out" | tail -n 40)" >&2 exit 2fiexit 0Register it in .claude/settings.json (make the script executable with chmod +x):
{ "hooks": { "Stop": [ { "hooks": [ { "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/require-green.sh", "timeout": 600 } ] } ] }}The hook arms itself only during a recorded run: without .claude/run-base it exits 0 silently, so ordinary sessions in the same repository see no hook errors. Delete the file when the run is reviewed. Three limits to know before you rely on it. Claude Code applies an eight-consecutive-continuation cap: after stop hooks have continued the turn eight times in a row, the next block is overridden and the turn ends (CLAUDE_CODE_STOP_HOOK_BLOCK_CAP raises it). The settings file lives in the repository, so the run can edit it too; list it under “Never touch” and check it in CI. And /goal is itself a Stop hook, so it is unavailable when disableAllHooks is true. The command tells you so instead of failing silently.
The same gate in the other tools:
-
Codex runs the same script from its
Stophook, but do not copy the Claude Code registration. Codex 0.157.1 does not setCLAUDE_PROJECT_DIR, so${CLAUDE_PROJECT_DIR}/.claude/hooks/require-green.shexpands to/.claude/hooks/require-green.sh, the shell exits 127 with “not found”, and the gate never runs. Codex runs the command through a shell in the session’s working directory, so resolve the repository root with git in.codex/hooks.json:{"hooks": {"Stop": [{"hooks": [{ "type": "command", "command": "\"$(git rev-parse --show-toplevel)/.claude/hooks/require-green.sh\"", "timeout": 600 }]}]}}Then open
/hooksand trust it: project hooks do not run until trust is persisted, and again after anyone changes the file (Codex 0.157.1). Agent hooks across tools covers the rest of the Codex registration. -
Cursor hooks can block the agent loop, but its event names were not verifiable from the writing environment on 26 September 2026. Check them in Cursor’s hooks documentation before you port the script.
Hooks in Claude Code and agent hooks across tools cover the other events. Protecting the oracle goes further: locked test paths, CODEOWNERS, and holdout checks kept out of the repository.
How do you check a twelve-hour run without reading every line?
Section titled “How do you check a twelve-hour run without reading every line?”You read evidence, in a fixed order, and read code only where evidence is not enough. The agent assembles the evidence; you decide.
- Re-run the oracle yourself, or read the CI result on the pushed branch. Never accept the run’s own report of green.
- Check that the oracle is intact.
git diff --stat $(cat .claude/run-base) -- test/ .github/ .claude/must be empty unless the spec asked for test changes. - Read the spec delta. Which acceptance criteria are met, and which ones the agent says it could not meet.
- Read
RUN_LOG.md. Look for the round where progress stalled or the approach changed. Long runs degrade: SlopCodeBench (arXiv, 25 March 2026) had 15 coding agents extend their own code over 196 checkpoints, found that “no agent fully solves any problem end-to-end, and the best agent passes 14.8% of checkpoints”, and measured the decay as structural erosion and verbosity. - Read code only for the escalation classes. Schema and migrations, auth, money, and anything a customer sees. Reading evidence instead of code defines these classes.
- Sign off or return. The developer who wrote the spec signs off on the evidence. A change in an escalation class also needs its code owner.
The same EVIDENCE.md, attached to a pull request, is the evidence bundle that reviewers read instead of the diff.
What should tech leads, CTOs and executives measure at Level 4?
Section titled “What should tech leads, CTOs and executives measure at Level 4?”Four measures, per repository or per change class, show whether Level 4 is working or whether runs only look finished. Adopt the definitions as written and set thresholds from your own baseline.
| Measure | Definition | Warning signal |
|---|---|---|
| Run acceptance rate | Unattended runs whose output merged without rework, divided by all runs started | Falls as runs get longer |
| Oracle-edit rate | Runs whose diff touched test, CI or hook files without the spec asking for it | Any rise |
| Escaped defects per class | Production incidents traced to changes approved on evidence, per change class | A class that keeps escaping goes back to Level 3 |
| Budget overrun | Runs stopped by the turn or token budget rather than by the condition | Conditions that are unreachable or vague |
The oracle-edit rate is the one to watch. A run that edits its own checks has not reached Level 4, whatever the acceptance rate says.
What breaks when a twelve-hour run comes back green?
Section titled “What breaks when a twelve-hour run comes back green?”When is a change class ready for Level 5?
Section titled “When is a change class ready for Level 5?”Level 5 removes the human from the loop for whole stations, not single runs. A change class is ready when unattended runs in that class keep a high acceptance rate, the oracle-edit rate is zero, escaped defects stay flat, and the specs, not the prompts, are what your team reviews. Everything a stop condition cannot decide (intent, taste, the escalation classes) stays with people; the human’s job lists it.
Compound engineering keeps each run from starting at zero: every finished run leaves a rule, a check or a skill behind. See compound engineering, the packaged discipline in Superpowers, and grill me as the alignment pass to run before a long job.
Where to go next from Level 4
Section titled “Where to go next from Level 4”Frequently asked questions
What is Level 4 on the autonomy ladder?
Level 4 is the stage where a developer writes the spec and a machine-checkable stop condition, the agent runs unattended for hours, and the human judges the result by its evidence (tests, types, checks) rather than by reading every diff. Dan Shapiro describes it as writing a spec, leaving "for 12 hours", and checking whether the tests pass.
Which tools support goal-directed runs for Level 4?
Claude Code, Codex and Cursor all have a /goal command. Claude Code checks the condition after every turn with a small, fast model and also lets you write your own Stop hook. Codex has /goal as a stable feature that is on by default. Cursor announced /goal in its 19 August 2026 changelog; its CLI slash-commands reference still listed it as rolling out on 28 August 2026.
Why is a /goal condition not enough on its own?
In Claude Code the /goal evaluator does not run commands or read files; it judges what the agent has shown in the conversation. A deterministic Stop hook that runs the test suite, and a CI check the run cannot edit, decide the result independently of what the agent reports.
What goes wrong most often in a long agent run?
The agent satisfies the stop condition by editing the oracle: weakening a test, deleting a case or skipping a suite. Name the test files as untouchable, block edits to them with a hook, and keep the decisive check in CI, outside the diff.