Loop Engineering: The Karpathy Method - and the workflow that just made it 5x better

Most people use AI the same way they used Google in 2005
- Type something, read what comes back, type again
The AI sits there doing nothing until you push it - you are the engine - The AI is a wrench you pick up and put down between every turn.
That worked fine for two years. It does not work anymore.
The people getting 10x more out of AI right now are not writing better prompts and not using secret models.
They are building loops. And the person who made this idea impossible to ignore is Andrej Karpathy
This article will explain:
1 - from scratch what a loop is
2 - show you how to use them the way Andrej Karpathy does
3 - then describe a method to improve this approach by a factor of 5
4 - and provide tips for getting started.
Part 1 · The Basics
1.1 - What a loop actually is ?
A prompt is one instruction. You ask, you get an answer, you decide what to do next.
A loop is a goal the AI keeps working toward until it gets there - without you sitting in the chair prompting every step
The AI discovers what needs doing, plans how to do it, does the work, checks the result, and if it is not there yet - feeds the result back in and goes again. You define the purpose once.
The loop handles the rest.
Three parts make or break it:
A stop condition keeps it sane. A loop with no exit runs until it succeeds, breaks, or drains your account. Every working loop has two ways to stop: the goal is met, or a hard limit says "after N tries, stop and report"
2.2. Do you actually need one? Run this test first.
Most articles sell you the loop before they tell you when it is a mistake.
A loop earns its cost only when all four of these are true. Miss one and it costs more than it returns.
The honest take: loop engineering is real, and most people do not need the heavy version yet. If you are on a consumer plan with limited tokens, a heavy loop will hit your rate limit or your wallet before the productivity gain arrives.
Part 2 · The Karpathy Loop
How Karpathy stopped prompting and started looping
In March 2026, Andrej Karpathy released a GitHub repo called AutoResearch.
Three files. About 630 lines of code.
Within a month it had 66,000+ stars and Fortune magazine gave it a name: The Karpathy Loop.
The setup is almost absurdly simple:
The agent runs in a loop:
Read the code → propose a change → train for five minutes → check if the result improved → commit if it did, roll back if it did not → repeat.
You go to sleep. You wake up to a log of experiments and hopefully a better model.
The human never touches train.py. You write program.md. - the agent handles execution.
- The results:
Karpathy pointed it at a model he had already carefully tuned by hand over two decades of experience. He let it run for two days.
Because humans get tired after experiment number twelve. The agent does not get tired at all.
Shopify CEO Tobi Lutke tried it overnight on an internal model:
The Karpathy Loop Fortune
Karpathy's core insight: if you have an objective metric, you should not be the one running the experiments. You are the bottleneck. Remove yourself from the loop and let it run.
Part 3 · The Building Blocks
Five pieces that make a loop work
Every working loop - whether you build it in Claude Code, Codex, or bash scripts - is assembled from five pieces.
Both Claude Code and Codex ship all five now.
In Claude Code: /loop for cadence, /goal for running until a condition holds. In Codex: the Automations tab. Without the heartbeat, you ran a script once and forgot about it. That is not a loop.
Written once in a markdown file, read by every run.
Without skills, the loop re-derives your entire project context from zero every cycle. With skills, intent compounds.
The model that wrote the code is too generous grading its own homework.
A second agent with different instructions catches the things the first one talked itself into. Your writer can be fast and cheap, your reviewer slow and strict. That separation is most of the quality.
The difference between an agent that says "here is the fix" and a loop that ships the fix and tells you about it in the morning.
Everything else is plumbing.
This is the part that makes the loop real. Without it you are paying for an agent to agree with itself all night
Part 4 · What Comes After Karpathy
The Bilevel - a Loop on top of the Loop
- this is where it gets interesting, hehe xD
They took Karpathy's loop and asked a simple question:
If autoresearch is itself a form of research - can you autoresearch autoresearch?
Bilevel Autoresearch
They built a second loop on top of the first one:
Then it injects that code and lets the inner loop run again.
- The result:
On Karpathy's GPT pretraining benchmark:
What the outer loop actually found: the inner loop kept falling into the same search patterns. The LLM has priors about what optimizations to try, and it keeps going back to those priors even when they stopped working. The outer loop broke those patterns by forcing exploration in directions the model's instincts avoided.
The paper ends with a line worth sitting with: "If autoresearch can meta-autoresearch itself, it can in principle meta-autoresearch anything with a measurable objective."
Part 5 · Try It Yourself
Run a loop right now - no tools needed
You do not need Claude Code or Codex to feel how this works. Paste this into any LLM and watch what happens:
You will work in a loop until the task meets the bar.
TASK:
[describe exactly what you want produced]
SUCCESS CRITERIA (be strict):
- [criterion 1]
- [criterion 2]
- [criterion 3]
LOOP PROTOCOL, repeat every turn:
1. PLAN - state the single next step.
2. DO - produce or improve the work.
3. VERIFY - score the result 1-10 on each criterion.
Be brutally honest. List exactly what is still weak.
4. DECIDE - if every criterion is 8+, print FINAL and stop.
Otherwise print ITERATING and go again, fixing
the weakest point first.
RULES:
- Never call it done until every criterion is 8 or higher.
- Each pass must fix the weakest score from the last VERIFY.
- Do not ask me questions. Make a sensible assumption
and keep going.
Begin.The model drafts, grades its own work against your criteria, finds the weak spot, rewrites, and repeats until it clears the bar.
That is a loop. You just built one with a paragraph.
It is limited - you are still the trigger, there is no schedule, no persistent state, close the tab and it is gone. But it shows the core mechanic. The jump from this to a full autonomous loop is adding the automation, the state file, and the gate.
Part 6 · The Honest Part
What the loop does not fix
Loops change the work. They do not delete you from it.
And two problems get sharper as the loop gets better - not easier:
Two people can build the exact same loop and get completely opposite outcomes. One uses it to move faster on work they understand deeply. The other uses it to avoid understanding the work at all.
The loop does not know the difference. You do!
Karpathy stopped writing code. Cherny stopped prompting. Neither of them stopped thinking. If you take one thing from this, take that.
start use loop like engineer . @0xCodila





