Everyone building with AI right now is talking about loops. Run the prompt, feed it a task, run it again, run it on a schedule. Loops are useful — and they’re also the tame version of a stranger idea sitting right next to them: recursion, a prompt that works on its own output.

The difference sounds academic. It isn’t. It’s the difference between a machine that repeats and a machine that climbs.

Loop vs. recursion, in one line

A loop runs the same prompt over and over on fresh input: “summarize this article,” a hundred times, on a hundred articles. Each run is independent and forgets the last.

A recursion feeds a prompt’s output back in as its next input: “summarize this — now summarize that — now summarize that.” Each pass stands on the one before it. You don’t get a pile of answers; you get a single answer that keeps getting refined, distilled, or deepened until something makes it stop.

That last clause is the whole game. Hold onto it.

Why it works

Language models are unusually good at operating on text that looks like their own. Hand a model its previous answer and ask it to improve, critique, distill, or expand it, and it will — because “here is a draft, make it better” is a task it has seen a million times. Recursion turns one shot into a staircase: each step is a small, easy transformation, but the steps compound.

Three shapes show up again and again:

  • Refine. Produce something, then critique and rewrite it, then critique the rewrite. Quality climbs each pass. (Researchers call the formal version “self-refine” or “reflexion”; by hand, you’re doing the same thing.)
  • Decompose. Break a problem into parts, then break each part into parts, until every leaf is trivial — then solve bottom-up. Recursion is how one hard problem becomes a stack of easy ones.
  • Converge. Apply the same operation until the output stops changing. Summarize a summary of a summary and you spiral down to the irreducible core of a thing.

How to actually do it in Claude

You don’t need an SDK to start — you need a base case. There are three levels of how far you take it.

Try these in a Claude chat

Refine: “Write two sentences pitching a $1 developer tool. Now critique your own pitch and rewrite it. Do that three times, show each version, and stop when another pass would make it worse.”

Converge: “Summarize this in one sentence. Now summarize that sentence. Keep summarizing until you reach a single word. Show every step.”

Decompose: “Explain how HTTPS works. Then take the most confusing term in your explanation and explain that. Recurse four levels deep, until it’s something a curious 12-year-old could follow.”

That’s recursion by hand: Claude runs the passes inside a single response. The next level up is to run the loop outside the model — in Claude Code or the API, take each response, feed it back as the next input, and keep going. Now the recursion is real code, and it can run as long as you let it. Which is exactly the problem.

The base case is the whole engineering job

Every recursion needs a reason to stop. In a chat, you are the base case — you read the output and quit. The moment you hand that job to an agent, you’ve built something that will happily recurse forever: refining a refinement of a refinement, spending tokens on diminishing returns, or spiraling into a loop that never converges. Unbounded recursion isn’t clever. It’s a runaway bill and a hung process.

This is the second-order habit we bring to every agentic system at Rebel Studios: before you let a prompt call itself, decide what makes it stop — a max depth, a “good enough” test, a token budget. The interesting power of recursion and the way it quietly drains your account are the same mechanism. You don’t get one without deciding about the other.

The bigger idea

Recursion is one of the oldest ideas in computing: something defined in terms of itself, a process that folds back on its own results. What’s new is that the thing doing the folding now works in plain language and has judgment. A prompt that improves its own output, then improves that, is a small taste of a system reasoning about its own reasoning — either the most useful pattern you’ll add to your toolkit this year, or the one that runs up a four-figure bill while you sleep.

Start it by hand, in a chat, where you’re the base case. Then, when you’re ready to let it run on its own, bring a stopping rule. What would your best prompt produce if you fed it its own answer — three times?

We build agentic systems that know when to stop — recursion, loops, and all — so the power doesn’t arrive with a runaway bill. That’s what we do at Rebel Studios.