March 2026
Running AI Agents in a Loop: How I Built Self-Iterating Code
I got tired of the AI coding dance. You know the one — you ask an agent to build something, it writes some code, you review it, point out what's wrong, it fixes it, you review again, repeat until done. It's not terrible, but it's also not what I signed up for when I started using AI to write software.
So I built the Ralph Loop.
The Problem
Here's the thing about autonomous AI coding agents: they're great at writing code, but they need a lot of hand-holding. They don't know when they're done. They don't always run the tests. They'll happily write 500 lines of code that don't compile and call it a day unless you explicitly check their work.
I wanted something that could:
- Plan out what needs to happen
- Build it in chunks
- Validate each chunk with tests and lints
- Know when it's actually finished
Without me sitting there saying "okay, now run the tests" after every single iteration.
How It Works
The Ralph Loop is a skill I installed from ClawHub (it's called ralph-loops if you want to look it up). Under the hood, it spins up OpenCode or Claude Code and runs it in a loop with some structure around it.
Here's the basic flow:
Planning Phase — The agent writes out what it's going to do in an
IMPLEMENTATION_PLAN.mdfile. This isn't a formal spec, just a running checklist of tasks.Building Phase — The agent writes code, makes changes, does its thing.
Backpressure — Before the loop iterates, tests and lints run. If they fail, the agent fixes things before moving on. This is the key part — it's not just writing code into the void, it's getting actual feedback.
Completion Detection — The loop knows when it's done by looking for "promise phrases" or sentinel lines in the output. Basically, the agent tells it when it's finished, and the loop trusts that.
That's it. Simple concept, but it makes a huge difference.
What I've Used It For
I've used the Ralph Loop to build several things now:
QRPro (qrpro.tools) — My QR code generator and link shortener. The loop handled the API integrations, the frontend, the database schema. It wasn't hands-off the whole time, but I definitely wasn't reviewing every function.
TLDHunt — Domain availability checker. The loop worked through the WHOIS API integration and the scanning logic without me needing to micromanage each step.
transcribely — Audio transcription tool. This one had more moving parts (file upload, processing queue, API calls), and the loop handled the iteration well.
What Worked
The backpressure mechanism is the real MVP. Tests and lints running after each iteration catches so many issues early. I used to spend way too much time debugging things that would've been caught by a simple lint check. Now the agent catches them itself.
The IMPLEMENTATION_PLAN.md approach is also solid. It keeps the agent focused and gives you a window into what's happening. You can check in halfway through and see exactly where things stand.
What Didn't
Completion detection is trickier than it sounds. Sometimes the agent thinks it's done but it's really just done with one part. I've had a few runs where it declared victory prematurely and left half the features unfinished. Now I add more explicit sentinel phrases and double-check the plan file.
Also, it works best with well-tested codebases. If you don't have tests, the backpressure thing doesn't work as well. You're basically flying without a net.
The Verdict
The Ralph Loop isn't magic. It's not going to build your entire startup while you sleep. But it does eliminate a lot of the tedious back-and-forth that makes AI coding feel like herding cats. You set it up, it runs, it validates, it keeps going until it's done.
For me, that's the difference between "AI helped me build this" and "I built this with AI doing most of the work."
If you're running AI coding agents and tired of the constant hand-holding, give it a shot. Install the ralph-loops skill from ClawHub and see what happens.
Buckley builds things at wooderson.ai. Currently running QRPro, TLDHunt, transcribely, and a few other projects that started as "let me see if this works."