FreeBuilder's Perspective8 min read

Put Your AI in a Loop: The Self-Improving System That Makes Your Code and Workflows Better While You Sleep

Most people use AI one shot at a time. The real unlock is the loop: an agent that changes your asset, scores it against a number it cannot cheat, keeps what wins, and repeats overnight. Here is how Karpathy's autoresearch system works, and how to point it at your own work.

Marcus Volsted
Marcus Volsted

AI & Web Consultant · June 21, 2026

Put Your AI in a Loop: The Self-Improving System That Makes Your Code and Workflows Better While You Sleep

Most people use AI like a vending machine. Ask once, take the answer, walk away. One shot, one result.

That leaves the best part on the table.

The real unlock is not a smarter prompt. It is a smarter loop. Instead of asking an AI to fix something once, you put it in a cycle: change one thing, measure whether it actually got better, keep the change if it did, throw it out if it did not, then go again. And then you walk away and let it run.

Andrej Karpathy put a beautifully clean version of this idea into a public repo called autoresearch. It is built for training ML models, but the system underneath it is general, and that system is the thing worth stealing.

🎯 Result
A loop that makes one change, tests it against a fixed score, keeps the winners and reverts the losers, running about every five minutes, overnight, with nobody watching. You wake up to work that is measurably better than when you went to bed.

What "the loop" actually is

Karpathy's autoresearch is deliberately tiny. One GPU, three files, none of the usual distributed-training machinery. The agent's only job is to improve a small training script, and it does it by running the same cycle over and over:

  1. 1Read the current code and the last score
  2. 2Make one hypothesis-driven change
  3. 3Run a short experiment, around five minutes
  4. 4Score the result on a single fixed metric
  5. 5Keep the change if the score went up, revert it if it went down

Then it does it again. Roughly twelve experiments an hour, through the night. The README jokes that the codebase is already on its "10,205th generation" - the point being that nobody hand-wrote those generations. The loop did.

5 min
One change, tested
~12
Experiments per hour
1
Metric that decides everything
3
Files in the whole system

The magic is not the model. It is the structure built around the model.

Why a loop beats one-shot prompting

When you prompt once, you get the AI's first guess. It might be great. It might be confidently wrong. You have no way to know without checking it yourself, and no mechanism for it to improve on its own.

A loop changes the deal. The AI does not have to be right the first time. It only has to be right more often than the scoreboard rejects it. Bad ideas get measured, fail, and are reverted automatically. Good ideas survive and stack. Over hundreds of cycles, that ratchet only turns one way.

One-shot prompting asks the AI to be smart. A loop asks it to be persistent. Persistence, measured against a score it cannot fake, beats raw cleverness on any task where you can tell better from worse.

Here is what that looks like after 83 experiments on Karpathy's own setup. Every grey dot is a change that was tried. The green line is the running best, and it only ever steps down, locking in each winner as the losers get thrown away.

83 experiments, 15 kept. The agent keeps proposing tweaks - halve the batch, add warmup, tune the learning rate, shift the RoPE frequency - and the validation score, where lower is better, ratchets down with every change it keeps. Nobody steered it between steps.
83 experiments, 15 kept. The agent keeps proposing tweaks - halve the batch, add warmup, tune the learning rate, shift the RoPE frequency - and the validation score, where lower is better, ratchets down with every change it keeps. Nobody steered it between steps.

Notice what is actually happening. No single change is dramatic, and the agent is not having a stroke of genius. It is stacking dozens of small, measured wins that a human would never have the patience to grind through by hand. Because each one had to beat the score to survive, the line cannot drift the wrong way.

The system: three files, and why each one matters

Here is the part to actually internalize. The loop works because of how the files are split, not because of any clever prompt. There are three, and the line between them is the entire safety model.

text
instructions    you edit this, the AI never does
the asset       the AI edits this freely
the score       the AI reads this, but can NEVER change it
  • The instructions are the brief: what you are optimizing, the rules, the hypotheses worth trying. You write this, and the agent treats it as law.
  • The asset is the thing being improved - the training script, a function, a landing page, an email. The agent has free rein here. It is the only file it is allowed to rewrite.
  • The score is the judge: a locked file that turns any version of the asset into a single number. The agent can read it to see how it is doing. It can never edit it.

That last rule is what everything hinges on. If the AI can touch its own scoring, it stops improving the asset and starts gaming the test - like a student who can rewrite the answer key always gets an A. Lock the score, and the only path to a higher number is genuinely better work.

⚠️ Heads up
The locked scorecard is not a nice-to-have. It is the difference between a system that improves your work and one that quietly learns to lie to you. If the model can move the goalposts, it will, and your numbers will look great while the asset rots.

Does your task even qualify?

Not everything belongs in a loop. The dreamlabs master prompt, a ready-made version of this system you can hand to Claude, opens by interviewing you to check the task is a fit. The checklist is worth knowing before you start. A task is loop-able when you can honestly tick these:

If you cannot score it objectively, the loop has nothing to aim at and just wanders. If a single test takes a week, you get a handful of cycles a month instead of hundreds a night, and the whole advantage evaporates. Get those two right and almost anything is fair game.

💡 Tip
Stuck on how to define the score? Lean on SMART goals: Specific, Measurable, Achievable, Relevant, Time-bound. The loop lives or dies on two of them. Measurable gives it the single number to climb - "make the page better" is nothing to chase, "lift signup conversion on a fixed traffic split" is. Time-bound keeps each cycle fast enough to run hundreds of times. Nail Specific and Measurable and almost anything in AI becomes loop-able.

Where I would point this

Karpathy aimed it at model training. The same machine works on plenty of everyday builder problems, as long as you can write the scorecard:

  • Landing page conversion - score is conversion rate or a CRO heuristic. The agent rewrites copy and layout, and keeps only what lifts the number.
  • Prompt optimization - score is pass rate on a fixed eval set. The agent tunes a system prompt against cases it cannot see or edit.
  • Function performance - score is benchmark runtime. The agent refactors, the benchmark decides, regressions get reverted.
  • Test pass rate - score is green tests. The agent chips away at a failing suite overnight.
  • Ad or subject-line copy - score is click-through against a held-out judge. The agent generates and filters.

In every case the shape is identical: one asset it can change, one number it cannot, and a loop in between.

How to start

You do not need a GPU or a research stack to try this. Two starting points:

  • Read the autoresearch repo to see the bare-metal version. Three files, one loop, no ceremony. It is the clearest mental model you will find.
  • Grab the Karpathy Auto Research master prompt if you want something ready-made to paste into Claude. It sets up the same three-file system, interviews you to confirm your task is a fit, and runs the cycle for you.

Start small. Pick one asset, write an honest scorecard, lock it, and let the loop run for an hour while you watch. Once you trust it, you let it run overnight.

The shift is from AI as autocomplete to AI as a tireless optimizer. You stop asking it for the answer and start handing it a goal, a scorecard it cannot cheat, and the keys to keep trying until the number climbs. Once you have felt that, one-shot prompting feels like leaving the engine idling.

That is the whole system: instructions in, the asset in the middle, the locked score holding the line, and the loop turning between them. Steal the structure, point it at something you can measure, and go to sleep.

Want help implementing this?

I help B2B companies implement AI solutions that actually move metrics, not science projects. If this guide resonated, let's talk about what it looks like for your business.

Get in touch