Agent Loops & Loop Engineering 2026: The Harness Underneath

Agent Loops & Loop Engineering 2026: The Harness Underneath

Max TecheraSubscribe

Everyone's posting that code is free now. That you point an agent loop at your repo overnight and wake up to finished features. Meanwhile, here's my actual Claude bill.

📥 Want the exact prompts and workflows I use with Claude Code every day? Grab the free library of 100+ prompts and build your first loop without torching tokens.

The term is a mess. Agent loops. Loop engineering. Some say it's the future of software. Some say it's a while loop with extra steps. They're both half right, because both skip the part that matters.

Everyone yelling "just write loops", that's the easy part. The thing that keeps a loop from setting your bill on fire has a name: the harness. That's what this guide is about.

# This is the core of a "Ralph loop." Seriously. This is the whole thing.
while :; do cat PRD.md | claude; done

That's a while loop. It's the part everyone dunks on, and honestly, it's an afternoon's work. The loop is the hook. The harness is the substance.

Claude Code Mastery

Aprende a usar Claude Code en contexto real. 5 módulos, 15 lecciones, ejemplos de producción.

This guide condenses what I've learned running real loops in production since February, what works, what funds your AI provider's yacht, and why the model is only one part of the machine.


Who This Guide Is For

  • ✅ You already use Claude Code and want to go from "I ask it for things" to "I leave loops running"
  • ✅ You saw the loop engineering hype and can't tell if it's real or noise
  • ✅ You're (rightly) nervous about leaving an agent running solo and coming back to a horror-story bill
  • ✅ From the right definition to running your first loop without blowing up your budget

What You'll Learn

  1. The real evolution, from prompting to context engineering to the harness to loops, and why each layer wrapped the last
  2. What a loop actually is, the one-sentence definition, no jargon
  3. Why they blow up, context rot, false completions, and the numbers nobody shows you
  4. The governor ladder, the fix: same model, completely different result depending on the harness
  5. The fair-fight experiment, how to run a loop bake-off with a judge that can't grade its own homework
  6. How to run one yourself, lanes, primitives, budget, and the honest readiness bar

🔔 Want the workflows I don't publish here? Every Tuesday I send loops, prompts, and the mistakes I made (so you don't have to).


How We Got Here: The Evolution

This didn't come from nowhere. It was a ladder:

Prompting → Context engineering → The harness → Loops.

Each step wrapped the one before it. The prompt is still in there; it just got buried deeper.

"We quickly expanded from prompt engineering to context engineering… tool calling, MCP and RAG… for managing the context window more efficiently." , Caleb Writes Code

"Loop" is the newest word, but the loop runs inside the harness. So that's where the rest of this guide spends its time, not on the buzzword. Boris Cherny, one of the creators of Claude Code, put it bluntly:

"I don't prompt Claude anymore. I have loops that are running… My job is to write loops." , Boris Cherny

Origin note, for anyone who thinks this is brand new: Ralph loops were originally introduced by Jeff Huntley back in July. The mechanism is old. What's new is making it not set your money on fire.


What an Agent Loop Actually Is

Forget the jargon. Here's the whole thing in one sentence:

That's it. The model acts, reads the result, decides if it's done, and goes again.

  • The loop is the verb. The thing that repeats.
  • The harness is the machine. The tools, the verification, the memory, the budgets.

Theo has an analogy that sticks:

"Imagine a really good engineer whose brain gets wiped whenever they do too much work at once." , Theo

That's why the harness matters so much. The model is brilliant but amnesiac. The harness is what gives it memory, limits, and a way to know whether it's actually done. As someone in the comments put it, perfectly:

"Prompting = hope. Harness = Work."

The distinction is everything. A loop without a harness is automated hope. A loop with a harness is work.


Why They Blow Up: The Real Numbers

Here's what nobody shows you: the bills. And the most expensive failure mode isn't the direct cost, it's the loop that says "done" when it isn't.

Failure #1: Context rot

"Context rot happens when there is too much information in the context, which causes the models to behave worse." , Theo

The context window fills up, the model degrades, and when it really fills up, it summarizes. And what happens when it summarizes badly?

"If context started to fill up mid task, it would summarize and assume the task is already finished… when it really wasn't." , Caleb (false completions)

Failure #2: The agent grades itself

This is the dangerous one. The loop invents its own test, passes it, and treats the result as evidence that it worked.

"The agent can invent the tests, pass them, and then treat the result as evidence that the loop worked… it's asking it to audit its own paperwork." , community comment

It's like letting someone write their own exam and grade it. They'll pass every time.

And the costs

This isn't theoretical:

"Uber recently blew through their entire AI budget in four months." , Sean Kochel

"Code is still not free, it is still a technical debt and responsibility." , community comment

And yeah, a loop is, at its core, a cron job with a decision-maker. The mechanism is old. What's new is making it not light your account on fire.


The Fix: The Governor Ladder

The fix isn't more loop. It's control. Same model, same raw capability, completely different result, depending on the harness around it.

"Same model, same raw capability, completely different result." , AI Revolution

Think of it as a ladder. Climb one rung at a time:

Rung 0, No governor          → the bare while loop. Hope. DON'T ship this.
Rung 1, Stop on green        → stop when the tests pass
Rung 2, Tests + review       → one agent reviews what another wrote
Rung 3, Bounded + verify     → budget caps + external verification the agent can't touch

The rule underneath all of it:

Andrej Karpathy frames it well:

"Everything can be made verifiable to some extent… it's more about what's easy or hard." , Andrej Karpathy

The model is only one part of the machine. The next major bottleneck isn't a smarter model, it's scaling the harness. Most of the token-burning horror stories disappear once the loop is engineered properly: deterministic guardrails, hard circuit breakers, and a verifier the agent can't bribe.


The Experiment: The Fair Fight

The best way to see that it's the harness, not the model, is to put them on the same job.

The bake-off setup:

  • One PRD, a real app: front end, backend, database.
  • Empty repo. Five loops, five branches.
  • Each builds the whole thing and writes its own tests.
  • The catch: I grade every one with a test suite they never see.
One PRD
   ├── branch 1 · Rung 0 (no governor)
   ├── branch 2 · Rung 1 (stop on green)
   ├── branch 3 · Rung 2 (tests + review)
   ├── branch 4 · Rung 3 (bounded + verify)
   └── branch 5 · your recipe

   Hidden judge (a test suite no loop ever saw)

   Scoreboard: each lane's real bill + the held-back-judge column

Watch for the lane that passes its own test and fails mine, a test soft enough to wave its own code through.

"The model that wrote the code is way too nice grading its own homework." , Addy Osmani


Run It Yourself: Lanes, Primitives & Budget

Don't read this and come back "when you have time." That moment doesn't come. Here's how to run your first loop today.

The 5 recipes (climb the ladder, don't ship rung 0)

Each lane is the same idea with more control. To package these recipes into something reusable, the skills lesson of the course is what you want. Every loop needs four things:

⚡ trigger        → what starts it (an open PR, an issue, a cron)
🎯 goal           → what "done" looks like, in plain text
✅ verification   → the test/check the agent does NOT control
💰 budget cap     → the hard token/$ limit before it stops
+ branch          → everything isolated, never on main

Name the real primitives

  • Loop vs. governance layer, the loop is one thing; the limits and verification are another.
  • Role-split agents, the one writing code isn't the one writing tests. (I build these isolated roles in the subagents lesson of the course.)
  • Session forks, branch the context so you don't contaminate it.

Role separation is what keeps the agent from cheating itself:

"The coding agent is the only one that can update source and the test agents are the only ones that can edit tests." , community comment

The honest readiness bar

I won't lie to you that this is for everyone from day one:

"If you're not already comfortable running two to three parallel sessions at the same time… building a loop is a really really bad idea." , Sean Kochel

But note: that bar is about running several at once. The on-ramp is one loop, one session, which is exactly tonight's homework.

The budget doesn't need to be billionaire-sized

Here's what almost nobody tells you: you don't need a token-billionaire budget. The same lane runs on a Pro plan or a cheaper model. Same job, smaller bill. Start there.

CURSO GRATUITO

Claude Code Mastery

Aprende a usar Claude Code en contexto real. 5 módulos, 15 lecciones, ejemplos de producción.

2+ horas de contenidoEjemplos realesAcceso inmediato

❌ Mistakes That Will Cost You Tokens (And How to Avoid Them)

1. Looping something you can't verify

The mistake: leaving a loop running on a task with no external check. The cost: the agent grades itself, declares "done," and you pay for every iteration up to the budget. The lesson: if you can't describe the test that proves it's finished, don't loop it yet.

2. Running rung 0 in production

The mistake: taking the while :; do … done off Twitter and pointing it at your real repo. The cost: context rot + false completions + an uncapped bill. The lesson: that tweet is a demo, not a workflow. Climb the ladder.

3. No budget cap = no safety net

The mistake: starting a loop with no hard token limit. The cost: you find out about the problem when the bill arrives, not before. The lesson: budget cap first, loop second. Always.

4. One agent writes both the code and the tests

The mistake: letting a single agent do both jobs. The cost: soft tests that wave the agent's own code through. The lesson: split roles. Coder edits source, tester edits tests. Never crossed.

5. Confusing the loop with the harness

The mistake: thinking "write loops" is the skill. The cost: you copy the loop, skip the verification, and repeat every horror story. The lesson: the while loop is free. The control around it is the real skill.


Conclusion: The Loop Layers On, It Doesn't Replace

The loop doesn't replace the prompt or the context, it wraps them. The while loop is free. The control plane around it, budgets, verification, the rule you add after a loop burns you once, that's the actual skill. And it's the part that outlives the next buzzword.

"You can outsource your thinking, but you can't outsource your understanding." , Andrej Karpathy

And you don't need ten years of CS for this. If you can describe what "done" looks like, you can run a loop.

📅 Your Action Plan

Tonight (30 min)

  • Pick one open PR or small issue
  • Define the 4 pieces: trigger, goal, verification, budget cap
  • Run one rung-2 lane (tests + review) on an isolated branch
  • Check the result against your verification, not the agent's

Goal: have a loop save you one hour this week. Just one. That's it.

Next week

  • Climb a rung: add an external verifier the agent can't control
  • Run the same lane on a cheaper model and compare the bill
  • Document the first time a loop said "done" without being done (it will happen)

If you want to see how I apply this in real projects, head to maxtechera.me and follow the weekly ships straight from the home page.


Frequently Asked Questions

What is an agent loop?

An agent loop is a small program that prompts an agent, reads what it produced, decides whether it's done, and reprompts it if it isn't. The loop is the verb. The harness, the tools, verification, memory, and budgets around it, is the machine that keeps it from running away.

Is loop engineering just a while loop with extra steps?

At the core, yes, it's a while loop, and that's an afternoon of work. What's new isn't the loop, it's the harness around it that keeps it from burning your bill. The hard part is verification and limits, not the loop itself.

Why do agent loops cost so much?

Two reasons: context rot (the context fills up, the model degrades, and it summarizes badly) and false completions (the loop says "done" when it isn't, it writes its own test, passes it, and calls it finished). Uber burned through its entire AI budget in four months. The rule that fixes it: only loop what you can verify.

Do I need to be a senior engineer to run an agent loop?

Not to run one. The high bar is running several sessions in parallel. The on-ramp is one loop, one session, with a trigger, goal, verification, and a budget cap. If you can describe what "done" looks like, you can run a loop.

Do agent loops replace prompting and context engineering?

No. The loop doesn't replace the prompt or the context, it wraps them. The prompt is still in there, just buried deeper. Each layer wrapped the one before it: prompting, context engineering, the harness, loops.


Keep learning:

Share