LoopFlow
Tutorial Workshop Keywords Blog ๐ŸŽฎ LoopFlow Lab
Blog / What is an AI coding loop?

What is an AI coding loop?

A self-correcting AI agent that plans, acts, and re-runs a real verification check until the proof is green โ€” not a one-shot prompt you have to babysit.

An AI coding loop is a workflow in which an AI agent repeatedly plans a change, makes it, and runs a real verification check โ€” feeding each failure back into the next attempt โ€” until the check passes or a retry ceiling stops it. It replaces the fire-once prompt with a self-correcting cycle that stops on proof, not on the model's say-so.

Put another way: a one-shot prompt asks for an answer and trusts the reply. An AI coding loop asks for a result and won't stop until a command your machine ran agrees the result is there. The loop is the control structure; the model is just the worker inside it.

The anatomy of an AI coding loop

Every self-correcting AI agent loop, whatever the tooling, is built from the same five parts. In LoopFlow โ€” a small natural-language DSL for writing these loops as .loop files โ€” each maps to one line:

The engine that ties them together is a repeated cycle: plan (decide the smallest change), act (make it), observe (run the check). On a red check the loop reflects โ€” it reads the failure output, writes a short diagnosis, and hands that to the next plan. That back-edge is what makes the agent self-correcting rather than blindly retrying.

Why a loop beats a one-shot prompt

A single prompt fires once and stops when the model stops typing. You are the verification step: you re-run the test, notice it failed, and re-prompt โ€” every time. The failure mode is silent. The model replies "Done โ€” fixed the rounding," and you find out later that the test never went green.

An AI coding loop closes that gap on three fronts:

  1. "Done" is provable. The verdict never comes from the model. At the observe step, deterministic runtime code spawns your check as a real OS process and reads the exit code. Exit 0 = pass; anything else = fail. The agent does the work; the operating system grades it.
  2. Failure is fuel, not a dead end. A red check triggers a reflect-and-replan instead of a stop. The loop learns from each miss automatically.
  3. Risk is gated, scope is bounded. The agent works on a branch, never pushes to main/master, and pauses at the gates you set.

A concrete .loop, walked through

Here is a complete AI coding loop for a failing test. Every line is one of the five parts above:

loop "fix the checkout tax test":
  goal: the checkout tax test passes with no regressions
  done when the test "checkout.spec.ts::tax" passes

  look at: the checkout code, and the last failure
  allow edits automatically, but ask me before pushes

  each cycle: plan, then act, then observe
  when it fails: reflect, then plan again
  after 6 tries: stop and warn "tax fix thrashing"

Reading it top to bottom โ€” the finish line first, the safety net last:

Run it and the loop runs the test every cycle. Red? It reflects on why, edits, and re-checks. It stops only when checkout.spec.ts::tax is green โ€” or warns after six attempts. The same file works tomorrow, and a teammate can read exactly what "done" meant.

Verification is the whole trick

The check is the loop's definition of reality, so it has to be real. LoopFlow supports several predicate forms, and you can list as many as you need โ€” all must pass:

loop "harden the auth module":
  goal: auth is covered and free of high-severity findings
  done when "pnpm test src/auth" passes            # a shell command, exit 0
  done when "semgrep --severity=high" finds nothing # exit 0 AND empty output
  done when the skill "code-review" approves         # an LM-judge eval

  look at: src/auth, and the last failure
  each cycle: plan, then act, then observe
  when it fails: reflect, then plan again
  after 8 tries: stop and warn "auth hardening stuck"

The command runs in your shell with your privileges โ€” treat a .loop from an untrusted source as you would their shell scripts. A test runner that exits 0 on failure will make the loop lie to you, so write the check like you mean it.

Where AI coding loops scale

One loop fixes one thing. Real work is a sequence of them, and LoopFlow composes loops two ways:

Because each stage carries its own verification, a multi-step AI agent workflow degrades safely: the pipeline can only advance past a stage whose check actually went green.

How to run one

With LoopFlow installed (npx @loop-lang/loop init), there are two surfaces:

The default installed into CLAUDE.md means you rarely type the slash: ask for something repeatable and verifiable and the agent reaches for a loop on its own; ask a one-off question and it just answers.

The takeaway

An AI coding loop is the difference between an agent that claims it finished and one that keeps working until the world agrees it did. Give it a goal, scope its context, gate the risky actions, hand it a check it can't fake, and cap the retries โ€” and you get a self-correcting AI agent you can leave running, review in a PR, and re-run tomorrow.

Try it: write a .loop and watch its shape in the playground, or learn the whole language line by line in the tutorial.