Loop engineering, as I practice it

August 2026, updated October 2026

For a long time I worked with coding agents turn by turn. I wrote a prompt, read the answer, and wrote the next prompt. The agent did the work, but I was the loop. Every cycle went through me.

Loop engineering changes who the loop is. You design a small system that finds the work, does it, checks it, writes down what happened, and decides what comes next. Addy Osmani describes the goal as “replacing yourself as the person who prompts the agent.”

Claire Vo’s framing on How I AI is the one I keep coming back to: a loop is a job you design. You onboard it the way you’d onboard a person. It gets a scope, a cadence, an expected output, a set of tools it can touch, and someone to escalate to. That turns out to be harder than writing a good prompt.

Write the success criteria first

The rule that prevents most bad loops is simple. Write down what “done” means before you ask for anything. A loop without success criteria is a faster, more expensive way to review the same ambiguity.

I made this a hard step. I built a small interactive builder for new loops, and it won’t scaffold anything until I’ve written the success criteria and described how a verifier will check them.

Four kinds of trigger

Pick the trigger that matches the job.

  • A heartbeat polls on a short interval. Use it when work shows up at unpredictable times and you want to catch it soon.
  • A cron job runs on a fixed schedule, like every Monday at 9. Use it when the calendar sets the cadence.
  • A hook fires on an event, like a new email, a pull request, or a tool call. Use it when something else should decide the timing.
  • A goal loop runs until an outcome is validated or the agent gets stuck.

Goal loops are the most powerful and the easiest to get wrong. Without a finish line a script can check, a goal loop burns tokens until it talks itself into being done. I only use one when “done” is checkable (tests pass, a screenshot matches), and every one gets a cap on iterations.

Plenty of real loops are hybrids. My memory cleanup loop wakes on a heartbeat, checks a couple of cheap thresholds (how many memory files exist, how long since the last pass), and does nothing if none are met. Most wake-ups cost almost nothing. The expensive work only runs when there’s a reason.

The parts list

Osmani and Vo land on nearly the same set of parts. Skills are reusable processes, so the loop doesn’t re-derive the job every cycle. Connectors reach outside the file system. Subagents take delegated work, and one of them should be a verifier. Worktrees give parallel agents isolated checkouts so they don’t collide on files. Automations are the schedule or trigger that fires the loop. And state is the memory that lives outside the chat.

When I first read that list, I had most of it. State was the gap.

Put the state on disk

Each of my loops keeps a state file. The top of the file holds machine state (cursors, counts, last-run dates). Below that are three sections: the next action, a pending-review list, and a run log with one line per cycle, newest first. Cycles that do nothing still get a line, so I can tell the loop is alive.

The chat is disposable. A session can end at any time, and the next one starts from the file, not from whatever the last session happened to remember. If I want to steer a loop, I edit the file between cycles. If I want to stop it for a while, I set its status to paused. The loop reads the file fresh every time, so the change takes effect on the next run.

Gate by reversibility

Every action a loop can take goes in one of two buckets.

Two-way doors are things I can undo: a local edit, a memory cleanup, a commit on a branch, a screenshot. Those run on their own.

One-way doors are things I can’t take back: a post to a chat channel, a push to a shared repo, a delete, or a change to the hooks and permissions that enforce the rules. Those go into the pending-review list and wait for me. The loop never clears that list itself.

I gate by reversibility rather than by importance, because importance is a judgment call and reversibility mostly isn’t. A loop can narrow its own boundary. It can never widen it.

A separate verifier, with a rubric that reads real state

Osmani puts the problem well: “the model that wrote the code is way too nice grading its own homework.” Every loop of mine that changes something sends its diff to a fresh verifier agent with different instructions before anything is committed. I start the verifier clean, without the writer’s context, so it isn’t anchored to the writer’s reasoning.

That wasn’t enough on its own. In August a verifier gave a broken Figma build 94 out of 100 because nothing had thrown an error. I caught it by looking, and I rewrote the rubric that day. The verifier now reads real dimensions from Figma and fails the build outright if the shell doesn’t wrap the content. The re-run scored 85. The full story is in my agent operating system case study. Since then every verifier I write has structural checks that read actual positions and sizes. “The step ran without an error” isn’t a check.

Running loops with nobody watching

The in-session tools (the /loop command in Claude Code, a cron job inside a session, a monitor on a log) stop when the session closes. For jobs that run unattended, I use local routines in the Claude desktop app.

Two things bit me when I set them up. The default permission mode asks for approval, so an unattended run will sit at its first write, waiting for someone who isn’t there. And a local routine only runs while the computer is awake. A closed laptop skips the run. Anything that touches local files or local git has to be a local routine, since a cloud routine can’t see either of them.

For unattended runs I always use the loop version of a job, with its verifier and its pending-review list, and never the bare skill. The guardrails matter most when I’m not there.

Where it goes wrong

The faster a loop produces work, the wider the gap between what shipped and what I understand. Reading the output is still my job. A verifier raises the floor, but “done” is a claim, and claims need evidence. Loops make supervision cheaper. They don’t make it optional.

The quieter trap is that I stop having an opinion. When a loop runs itself, it’s tempting to take whatever comes back. The same loop can help me understand more or let me think less, and the loop design doesn’t decide which one happens.

Loops also spend tokens on every wake-up. A cheap threshold in front of the expensive work, and a hard cap on goal loops, keep the cost bounded.

The short version

  • Write the success criteria before the artifact.
  • Put a cheap check in front of expensive work, so most cycles do nothing.
  • Gate anything you can’t undo.
  • Read the diff yourself.

Sources

Most of the vocabulary here comes from those two. The mistakes are mine.