Skip to content
Flows
Harness Engineering Intermediate · 60-100 minutes

Verification Loops: Never Trust an Unrun Edit

Wire verification into your agent so every edit is checked by machines - syntax, tests, behavior - before it counts as done.

Start Route · 4 steps

The route

4 steps to Done

  1. 01

    Verify at the write boundary

    The cheapest catch-point is the moment of the edit.

    Preview prompt + verify gate ▾

    Implement write-time verification. On every file write or edit: run the appropriate fast check for the file type (python: compile/ruff; js/ts: esbuild parse or tsc; json/yaml: parse) within a second-scale budget; on failure, revert the write (or never apply it - validate a staged copy) and return the exact error with line numbers to the model as the tool result; on success, return a confirmation including the check that ran. Wire this into the edit tool itself so no write path skips it. Test with a deliberately broken edit and confirm the revert-and-teach cycle produces a corrected second attempt.

    • Checks are file-type appropriate and fast
    • Failed writes never persist on disk
    • Errors return with line numbers
  2. 02

    Add the post-change verify step

    Syntax says it parses; only execution says it works.

    Preview prompt + verify gate ▾

    Implement behavioral verification after each logical change. Mechanics: after the model completes a coherent unit of work (an edit batch, a todo item), the harness runs the verify step - the project's relevant tests (targeted by changed paths where a mapping exists, full quick suite otherwise), or for untested projects a smoke script (start the service, hit the key endpoint, check the response). The verdict plus the failing output (bounded, tail-biased) goes back to the model. The loop treats a red verify as the task NOT advancing: the todo item stays open. Configure per-project verify commands in the harness config rather than hardcoding.

    • Verify triggers per logical unit, not per keystroke
    • Red verify keeps the todo item open
    • Verify commands configurable per project
  3. 03

    Gate completion on evidence

    Done is a property of the evidence, not the prose.

    Preview prompt + verify gate ▾

    Implement evidence-based completion. Build the evidence record as the task runs: every verification event appends {check, command, verdict, output-digest, timestamp}. At completion time, the harness gates: all todo items closed, latest verify green, and every requirement in the task mapped to at least one piece of passing evidence (the model produces the mapping; the harness checks the referenced evidence exists and passed). If gating fails, completion is refused with the gaps listed. The final output to the user includes the evidence table. Test with a multi-requirement task and confirm an unverified requirement blocks completion.

    • Evidence record built automatically
    • Requirement-to-evidence mapping checked
    • Final output shows the table
  4. 04

    Red-team your own verification

    Verification you have not tried to fool is decoration.

    Preview prompt + verify gate ▾

    Attack the pipeline. Attempt the classic evasions: (1) an edit that parses but breaks behavior - the write check should pass and the verify step must catch it; (2) a 'fix' that makes the failing test pass by weakening the assertion - review the diff-of-tests in verify output and add a harness rule flagging test-file modifications during fix tasks for explicit approval; (3) completion claimed with a stale green from before the last edit - the gate must require evidence newer than the newest change; (4) verify command sabotage (echo passing) - verify commands come from config, not model output. Fix every hole found and document the pipeline's guarantees honestly, including what it still cannot catch.

    • All four evasions attempted
    • Test-weakening flagged for approval
    • Evidence freshness enforced

Research-backed

Sources behind this flow

Tier 1 · claude-code-internals

claudecode-source (annotated bundle)

Packages a deep source-level analysis of a Claude Code snapshot (~1,900 files) with HTML reports, architecture visuals, and walkthrough guides, plus an independently written source-analysis report in Chinese and English. One of the most complete single bundles for studying the tool definitions, main agent loop, and edit-validation path.

Tier 2 · harness-engineering

Harness Engineering: from CC to AI coding

A full book on harness engineering ('from Claude Code source code to AI coding') with Chinese and English editions in book/ and book-en/. The single best conceptual source in this corpus: chapters on prompt assembly, tool design, context management, verification loops, and sub-agent patterns.

Tier 2 · harness-engineering

agentic-harness-patterns-skill

A distilled 'skill' file of agentic harness patterns - short, dense, and directly reusable as workflow steps. The compressed counterpart to the harness-engineering book.

Tier 1 · claude-code-internals

Deep Dive: Agent Orchestration Patterns

Follows a dispatched agent through its full lifecycle - foreground vs background execution, auto-backgrounding of long tasks, sidechain transcripts for resume, layered tool filtering, and result handoff - then catalogs six reusable orchestration patterns: worker pool, pipeline, supervisor-worker, adversarial verification, fork-join, and resume chain. The adversarial verification agent, which must run real commands and issue a PASS/FAIL verdict while being forbidden from editing the project, gets special attention as a defense against LLM self-verification failure modes.