Writing AI Loops

How power users moved from prompting to context engineering to writing loops, and the three parts every loop needs.

There's a shift happening in how the best AI users work. First everyone learned to prompt. Then to context engineer (feed the model the right files, examples, and constraints). Now the people getting the most out of AI write loops. The loop does the work; the human designs the loop.

Dharmesh Shah laid this out in his agent.ai newsletter ("How to Write Your First AI Loop"), quoting Boris Cherny, the creator of Claude Code:

"I don't prompt Claude anymore. I write loops, and the loops do the work. My job is to write loops."

This matters to me because I already live in Claude Code, which ships a /loop feature. I've been treating it as a convenience. The reframe is that loop design is the actual skill, and the only one that compounds.

The three parts of a loop

A loop is not "run this prompt 10 times". It needs three things, and getting them right is what stops you babysitting every turn.

Part What it is The question it forces
Objective What you want the system to accomplish What does "good" actually look like?
Metric How the system itself (not just you) can tell whether a pass got better or worse Can the loop grade its own work?
Boundary How far the loop can run on its own before it checks back with you When must it stop and show me?

Get those three right and the loop runs itself: it asks, checks its own output against the metric, adjusts, and continues. You stop approving each turn and start reviewing the finished candidates.

The hard part is the metric. Most people can name an objective. Far fewer can define a signal the system can read on its own to know if it's closer or further from good. If the loop can't grade itself, it can't improve itself.

A worked example

Here's the loop prompt from the newsletter. Read it as three parts wearing one paragraph:

"Write a LinkedIn post about [topic]. Objective: teach one useful idea in under 200 words. After each draft, score 1 to 10 (does the first line earn the 'see more' click, is there exactly one idea, would a smart reader learn something new?). For scores below 9, critique and rewrite. Take up to 10 passes, then show me only the top 3."

Mapping it back:

  • Objective = teach one useful idea in under 200 words.
  • Metric = the 1-to-10 self-score against three concrete checks (hook, single idea, real learning).
  • Boundary = up to 10 passes, then surface the top 3.

Tip from Dharmesh: attach 3-4 example posts you actually love as context. The loop borrows their quality bar. This is where context engineering and loop writing stack: better context, better metric, better output.

A loop that runs vs a loop that learns

Not all loops are equal.

  • A loop that runs is automation. It does the same thing every pass. Useful, but it never gets better.
  • A loop that learns has a feedback wire. A signal from the outcome flows back into the next pass, so it compounds.

Dharmesh's example is a dad-joke generator. Add an upvote/downvote on each joke, feed that signal back in, and the loop starts converging on jokes people actually rate. His line:

"If you can go through a loop and know at the end whether you got better or worse, you'll win eventually."

That sentence is the whole game. The feedback wire is what separates a script from a system that improves.

Where the human belongs

The work moves up a level. It goes from task execution to workflow design:

  • Pick the objective.
  • Choose the metric.
  • Draw the boundary.

Keystroke work goes away. Judgment work does not, it concentrates. Choosing what "good" means and how to measure it is exactly the part a model can't do for you, and it's the part that compounds across every loop you write after.

Try this

Take one task you already hand to AI (for me: drafting outreach, prepping a call, cleaning pipeline data). Then write down three lines:

  1. Objective - what does a good result look like, concretely?
  2. Metric - what signal tells the loop it's closer or further from that?
  3. Boundary - how many passes before it stops and shows me?

If you can't name the metric, that's the real work, not the prompt.

Further reading

  • Dharmesh Shah, agent.ai newsletter, "How to Write Your First AI Loop" (no stable public URL).

The platform behind the newsletter, where you can build and run agents:

Dharmesh's companion site on practical AI for builders: