AI agents › Harnesses and loops
What is loop engineering? A plain guide for AI coding agents
Loop engineering means building a system that prompts, checks, and re-runs an AI coding agent for you. Where the term came from and how a loop works.
If you’ve used an AI coding agent, you’ve probably typed a prompt, read the result, and typed the next prompt more times than you can count. However capable the agent became, you were still the one telling it what to do next. Around June 2026, though, a slightly different idea started spreading among developers. Stop writing prompts for your agent, it said, and design the loops that write prompts for it instead. The name that stuck to this idea is loop engineering.
Put in one sentence, loop engineering is designing a system that talks to the agent so you don’t have to do it every time. Finding the work, handing it out, checking the result, writing down what’s done, and deciding what comes next all become the loop’s job. That may sound grand at first. But if you trace it back, it starts from something simpler than you’d expect.
How the term spread
It isn’t clear who coined the term. How it spread, though, is fairly clear. On June 7, 2026, Addy Osmani pulled the idea together in an essay called Loop Engineering, quoting developer Peter Steinberger: you shouldn’t be prompting coding agents anymore, you should be designing loops that prompt your agents. The same essay quotes Boris Cherny, who leads Claude Code at Anthropic, as saying he doesn’t prompt Claude anymore and that his job is to write loops.
Explainers poured out over the following weeks, and in July IBM published its own definition. IBM describes loop engineering as designing agentic workflows, or loops, that keep guiding AI agents toward a goal the user set, with as little human intervention as possible. Still, the term is less than half a year old, so perhaps it’s fairest to call it a buzzword for now. Each article stresses slightly different things. Most of them share the same skeleton, though. You set a goal, the agent works, the result gets checked, and the loop either stops or runs again. And whatever was learned along the way is kept outside the conversation, in files or in the repository.
Prompts, context, harnesses, and loops
The easiest way to understand loop engineering is to line it up with the terms that came before it. Many explainers describe the four as layers, each one built on top of the last.
| Term | What it mostly shapes |
|---|---|
| Prompt engineering | A single instruction you give the model |
| Context engineering | Everything the model sees at each step |
| Harness engineering | The environment one agent works in (tools, permissions, checks) |
| Loop engineering | When the agent runs, how often, what checks it, and when it stops |
Anthropic sees context engineering as the natural next step after prompt engineering. The harness, in the words of the Claude Code docs, is the layer around the model that provides the tools and manages the context the model sees (How Claude Code works). And Osmani says loop engineering sits one floor above the harness. A new floor doesn’t remove the ones below it. So building a good loop still takes good prompts and well-organized context.
The inner loop and the outer loop
Agents have actually run in loops from the start. In December 2024, Anthropic’s Building effective agents described agents as LLMs using tools based on feedback from their environment, in a loop. The Claude Code glossary likewise defines the agentic loop as gathering context, taking action, and verifying results, repeated until the task is done.
If you call that the inner loop, then loop engineering designs the loop that runs outside it. The inner loop is about how to finish this one task. The outer loop is about which task to hand out and when, what checks the result, and how many times to try again. That’s where typing the next prompt, the part you used to do yourself, gets handed off.
Ralph, the simplest loop
The best-known example of an outer loop is the Ralph technique that Geoffrey Huntley introduced in July 2025. In its purest form, he says, Ralph is one line of shell: while :; do cat PROMPT.md | claude-code ; done. That’s copied exactly from his post, and the actual Claude Code command is claude. It keeps feeding the same prompt file to the agent, forever, and that’s all. Huntley adds that you should wire in checks like tests and type checking as “back pressure” to reject bad code. Anthropic later shipped the technique as the ralph-wiggum plugin for Claude Code. It uses a Stop hook to catch the moment Claude tries to finish, then feeds the same prompt back in. --max-iterations sets the most rounds it may run, and --completion-promise sets the phrase that signals it’s done.
Let’s shrink the idea down to something small enough to run yourself. All it takes is one prompt that goes in every time, one to-do list, and one shell script that runs the two. First, PROMPT.md.
Work through progress.md one item per run.
1. Find the first line that starts with TODO and do that item.
2. Change TODO to DONE on that line.
3. If no TODO lines are left, add a last line: ALL DONE
Do only one item, then stop.
progress.md is both the to-do list and the loop’s memory. It starts with two lines.
TODO write greet.py with greet(name) that returns "Hello, <name>!"
TODO write test_greet.py and make python3 -m unittest pass
And here’s loop.sh, which runs the two.
#!/bin/sh
# Same prompt, fresh session each time, until the list is done and the tests pass.
for i in 1 2 3 4 5; do
echo "iteration $i"
claude -p "$(cat PROMPT.md)" --permission-mode acceptEdits \
--allowedTools "Bash(python3 *)" < /dev/null >> loop.log
if grep -q "ALL DONE" progress.md && python3 -m unittest -q 2>/dev/null; then
echo "finished after $i iterations"
exit 0
fi
done
echo "stopped after 5 iterations"
exit 1
claude -p is a headless run that executes once without opening a chat and then exits. --permission-mode acceptEdits lets it edit files without asking, and --allowedTools lets it run python3 commands. Each round opens a new session, so the agent doesn’t remember the earlier conversation. It reads progress.md instead and picks up from there. The script decides on its own whether the work is done. It stops only when the list says ALL DONE and the tests actually pass, so the agent saying it’s finished isn’t enough. If five rounds go by without that, it stops anyway. Finally, < /dev/null is there so the agent doesn’t wait for input. Without it, every round prints a warning that it waited 3 seconds for input.
iteration 1
iteration 2
iteration 3
finished after 3 iterations
When I ran it with Claude Code 2.1.304, it finished in three rounds and took about a minute. The first round wrote greet.py, the second wrote the test, and the third saw that no TODO lines were left and added the last line. Here’s progress.md afterward.
DONE write greet.py with greet(name) that returns "Hello, <name>!"
DONE write test_greet.py and make python3 -m unittest pass
ALL DONE
Loops built into the tools
As Osmani points out, you often don’t need to write loops like this as shell scripts anymore. The pieces of a loop are arriving as built-in features of the tools. Take Claude Code. /loop re-runs the same prompt on an interval you choose (scheduled tasks), and /goal keeps starting new turns until a condition you wrote is true. With /goal in particular, a different model from the one doing the work judges the condition after every turn. Osmani lists a few more pieces. Automations go off at set times and find work on their own, and git worktrees keep several agents from touching each other’s files. Skills write down project knowledge, connectors plug in outside tools like an issue tracker, and sub-agents keep the maker apart from the checker.
What a good loop needs
The conditions the explainers keep coming back to are humbler than you might expect.
First, a machine has to be able to tell whether the work is done. The loop can only stop on its own when the condition is clearly true or false, such as all tests passing with no lint warnings. The Claude Code glossary warns that without such a check, the only thing deciding the agent is finished is the agent itself.
Second, it helps to separate the maker from the checker. Osmani says the model that wrote the code is far too nice when it grades its own homework. That’s why a second agent with different instructions, or a test the script runs itself as in the example above, does the checking.
Third, memory lives outside the conversation, on disk. As Anthropic’s post on harnesses for long-running agents explains, each new session starts with no memory of what came before. So progress files and git commits become the bridge from one round to the next.
Fourth, always have a way to stop. That means a maximum number of rounds, a cap on time or cost, and a check that halts the loop when several rounds bring no progress. The ralph-wiggum plugin’s README also recommends always using --max-iterations as a safety net, so the loop doesn’t run forever on a task that can’t be done.
What still falls to you
A loop changes the work, but it doesn’t remove you from it. Osmani warns about three things in the same essay. A loop that runs unwatched also makes mistakes unwatched, so checking is still your job. The faster a loop piles up code you didn’t write, the wider the gap grows between what you understand and the code that exists. And if you stop forming your own judgment because the loop runs itself, that’s where the danger lies. Cost deserves thought too, since a loop keeps spending tokens while nobody is watching. That’s probably why Osmani warns about token costs in his very first paragraph.
If you’re trying it for the first time
If you’re new to this, I’d suggest starting with a very small loop like the example above. Break the work into small items and write them in a file, check completion with something you trust, like tests, and put a cap on the number of rounds. Then read what the loop produced yourself. If you use Claude Code’s /goal, adding a limit such as “or stop after 20 turns” to the end of the condition, as its docs suggest, is a good place to start. I ran this example on October 27, 2026, on macOS with Claude Code 2.1.304.
AI tools helped with the research for this post.