Srevil Blog
agentsClaude Codenotes 29min read

Loops & Graphs: Approve Only the Last Hard Step

Notes from reading Hanako's “Loops and Graphs,” down to the checks, the graph, and the approval point.

You don’t need to watch every step an agent takes. The useful place for a human is the step that's hard to undo, and expensive if it goes wrong. Watching the middle of the run usually means that place was never chosen in advance.

I wrote this after reading Hanako (@hanakoxbt)’s “Loops and Graphs.” These are my notes, not a translation. I unpacked the original down to blocks you can paste into a coding agent.

Three points stuck.

  • Write a check a program can pass or fail, and write it before the work starts.
  • Connect two steps only when output actually feeds the next input. Otherwise run them side by side.
  • Step in where the blast radius is large. A model’s confidence is hard to see, and a poor guide.

Write the passing condition first

After you hand work to an agent, it is easy to follow the scroll and jump in whenever an intermediate result looks off. If the check is a matter of taste, the loop never settles.

The essay splits that habit into a Loop and a Graph. A Loop is produce, check, fix, and repeat until the check goes green. It has to be something a program can decide. Write that condition first, and the agent can run against it without a person reading every turn.

Produceproduce Checkcheck Fixcorrect Repeatrepeat Current check Waiting
$ npm test → waiting

The diagram runs one cycle: a failed check, a fix, then a pass. The center state flips from red to green.

Some things belong in the check. Some do not.

GREEN

A program can decide

  • The test suite exits 0
  • Every claim has a source (file:line)
  • The diff touches only the files in the plan

NOT A CHECK

This is a feeling

  • “The result looks fine”
  • “The model sounds sure”
  • “There were no errors.” A clean run is not the same as a correct one
  • Only asking another model to “review this.” That is two optimists agreeing

Connect only what actually connects

A Graph is how those loops attach. A node is a bounded piece of work with one input and one output. There’s an edge between two steps only when the output of one actually becomes the input of the next.

Ask this of every arrow. Can you name the value that crosses it? Does the next step actually read the previous output? If you cannot name it, there is no reason to run them in sequence. Put them side by side.

The diagram below shows the same work first as a chain, then with the extra lines removed so the workers can run together.

Time
3 workers in sequence: 3 time units

Draw the pipeline with four node types

The original draws a pipeline as four roles. The names matter less than this: how far a failure would spread.

Splitter

Split

Cut the work at the front. This is the decision to make first. Cut by blast radius, not by folder.

Worker

Worker

One unit, one point of view, its own context. Shared context makes the results converge. You pay four times and get one opinion.

Code node

Code

Merges, sorts, dedupes, and before/after comparisons have one right answer. Code should do them, not the model.

Gate

Gate

Pass the result, or send it back to the step that made it. Open the gate by blast radius, not by a confidence score.

If you can describe the step without words like “judge, decide, evaluate, or summarize,” build it in code, not with a model.

Do not run workers as subtasks in the same conversation. Launch each as a subagent, with its own context.

Worker Actx A
Worker Bctx B
Worker Cctx C
Worker Dctx D

The Loop lives inside a node. The Graph lives between nodes.

Each node runs alone until its own check goes green. Nodes connect only through output that actually crosses.

Worker A loop Merge (code) loop Gate loop

The green arc is the loop inside a node. The dashed line is a graph edge between nodes.

There are two ways back

Most setups only build the short path. You need the long path too, or the same mistake shows up on the next run.

The short path is a correction edge. The gate returns the failed unit to the step that made it. That fixes this run.

The long path is a learning edge. You extract constraints from accepted results and put them in the splitter’s brief. That fixes later runs. This is the path people drop.

Splitter brief Worker produce a unit Gate pass / reject Accepted accepted result correction edge · fixes this run learning edge · fixes later runs

Here is the example from the original. When the utils slice ports and goes green on the first pass, you derive a constraint: adapters must preserve keyword args exactly. That line lands in the splitter’s brief for every later slice. In Claude Code, you can append it to the “Learned constraints” section of CLAUDE.md.

Return only the failed unit. If one of four fails, retry that one. Rewrite the whole batch, and the three that already passed get written differently. The results stop lining up.

utils slice 1→
handlers slice 2GATE retry 0 / 3
adapters slice 3→
models slice 4→

Only the failed handlers unit goes back to the gate. The other three stay as they are.

When you send it back, send five lines with it.

UNIT      handlers slice
VERDICT   red
REASON    test_auth_redirect failed
EVIDENCE  expected 302, got 200, handlers/auth.py:88
SCOPE     fix this file only, do not touch other slices

Without SCOPE, the fix spreads. You end up with a large diff nobody reviewed.

If the same unit fails three times, the unit is probably not the problem. The split is. Escalate that to a human.

Step in only where the blast radius is large

Pick the intervention point by blast radius. Even if the model’s score is high, do not auto-pass work that is hard to undo.

OPEN

Easy to undo, and local

These can pass automatically.

Copy changes, tests, a covered independent function

GATED

Easy to undo, but wide

Pass only after a deterministic check and a clean run history.

Shared utils, a new schema, code with many call sites

CLOSED

Hard to undo

A human approves these, regardless of score.

Migrations, deletions, production data, money movement

This is the order of evidence a gate should trust.

What a gate should trust, in order

1Deterministic results (tests, and the like)
2The path of this run
3How often this node has been rolled back
4The model's self-evaluation (last)

Blocks you can paste today

These are reconstructed from the examples in the original, so you can paste them into a coding agent.

CLAUDE.md rules block

Paste this into the project-root CLAUDE.md, or into ~/.claude/CLAUDE.md.

## Agent working rules (Loop + Graph)
Goal: I do not review intermediate results. I approve only the step that is hardest to undo and has the largest blast radius.

1. Write the check first
   - Before work starts, show a GREEN list a program can pass or fail.
     e.g. tests exit 0 / every claim has a file:line citation / the diff touches only the planned files
   - "Looks fine", "the model is confident", "no errors", "another model reviewed it" are not checks.
   - Produce, check, and fix until GREEN.

2. Edges are real data flow only
   - For every arrow, name the variable that crosses it.
   - If you cannot name it, it is not an edge — run the steps in parallel.
   - Parallel work runs as subagents, each in its own context.

3. Do deterministic work in code
   - Merging, sorting, deduping, and before/after diffs are scripts, not the model.
   - If you can describe the step without "judge / decide / evaluate / summarize", it is code.

4. Split by blast radius
   - Cut the work by blast radius, not by folder.

5. Return only the failed unit
   - Do not rewrite the whole batch. Retry the failed unit in this form:
     UNIT / VERDICT / REASON / EVIDENCE / SCOPE
   - Do not touch files outside SCOPE.
   - Maximum 3 attempts. After 3 failures, stop, propose a new split, and report to me.

6. Open gates by blast radius
   - Easy to undo and local (copy, tests, a covered independent function) → proceed automatically
   - Easy to undo but wide (shared utils, a new schema, code with many call sites) → only after a deterministic check and a clean run history
   - Hard to undo (migrations, deletions, production data, money movement) → stop and ask for approval, regardless of score
   - Evidence order: deterministic results → this run's path → past rollback rate → self-evaluation (last)

7. Keep what you learned
   - Add each confirmed constraint from accepted results to "Learned constraints" below, and use them in later splits.

## Learned constraints
- (example) adapters must preserve keyword args exactly

Start-of-task prompt

Send this as the first message on a new task, so the agent draws GREEN conditions and the graph first.

Task: <what to do>

Before writing code, show me these five things. Start only after I confirm.

1. GREEN conditions
   3–5 completion checks a program can decide.
   (e.g. `npm test` exit 0 / the diff changes only the file list below / every claim has a file:line citation)
   Do not write "looks fine" or "no errors".

2. Split (Splitter)
   The list of work units. Split by blast radius, not by folder,
   and mark each unit [local / wide / hard to undo].

3. Edges
   For every arrow between units, the variable name that crosses it.
   If there is no name, mark it "parallel" and run it as a separate subagent.

4. Code nodes
   Steps a script should handle, such as merge, sort, dedupe, or compare.

5. Approval point
   The single step I must approve (the one that is hardest to undo and has the largest blast radius).
   If any other step is GREEN, continue without asking.

Reject / retry template

Fill this in when a result fails. Use the same form with a subagent.

UNIT      <one failed unit. e.g. handlers slice>
VERDICT   red
REASON    <the check that failed. e.g. test_auth_redirect failed>
EVIDENCE  <expected vs actual, file:line. e.g. expected 302, got 200, handlers/auth.py:88>
SCOPE     Fix this file only. Do not touch other units.
ATTEMPT   <n> / 3

Rule: if the third attempt also fails, stop fixing.
Instead, report what is wrong in the split.
If it passes, extract one confirmed constraint from this fix and add it to CLAUDE.md "Learned constraints".

Pipeline checklist

Checks are stored only in this browser.

Start in this order

Pick one recurring task. Draw a splitter, the lanes, a merge, one gate, and one return edge. Then build them in this order.

1

The gate first

Decide what counts as GREEN, which lanes can pass on their own, and which ones a person sees.

2

Split the lanes

Cut by blast radius. If no value crosses between two steps, put them in parallel lanes.

3

The learning edge last

You need accepted results before you can extract constraints. When you have them, put them in the splitter brief — in CLAUDE.md.

4

A human at one point only

Approve the merge, or choose which fix to ship. That is the one job.

Next time I give an agent a task, I want to write two lines before I watch the screen.

I haven’t run my own work this way yet. These are notes from reading, not a field report.

Sources

  • Original: Hanako(@hanakoxbt), “Loops and Graphs” — https://x.com/hanakoxbt/status/2091515787366306154
  • About this post: A blog post written in my own words after reading the original. It is not a full translation. Any mistakes in the retelling are mine.
  • Author: Woobin (Srevil)
  • Written with: Claude
  • Diagrams: The Loop and Graph animations, plus the extra figures and templates, are adapted from an earlier HTML guide of mine (Loops-and-Graphs.html), trimmed to what helps this post.