Skip to main content
MindStudio
Pricing
Blog About
My Workspace

What Is Recursive Self-Improvement in AI? The Karpathy Loop Explained

Andrej Karpathy's Auto Research project lets AI agents propose, test, and commit code changes autonomously. Learn how recursive self-improvement works.

MindStudio Team RSS
What Is Recursive Self-Improvement in AI? The Karpathy Loop Explained

When AI Writes, Tests, and Ships Its Own Code

Recursive self-improvement in AI sounds like science fiction. An AI that makes itself smarter, which makes it better at making itself smarter, which… you get the picture. But the concept isn’t hypothetical anymore. Andrej Karpathy — former Tesla AI director and OpenAI co-founder — has outlined a practical implementation of this idea in what’s become known as the Karpathy Loop: an agentic workflow where an AI proposes changes to a codebase, tests them, and commits the ones that work, then starts the cycle again.

This article breaks down what recursive self-improvement actually means, how the Karpathy Loop works in practice, and why it matters for anyone building or using AI systems today.


What Recursive Self-Improvement Actually Means

Recursive self-improvement (RSI) is when a system uses its own capabilities to enhance those same capabilities. Each improvement makes the next improvement easier or more effective, creating a feedback loop.

In traditional software, this doesn’t really happen. Code doesn’t rewrite itself based on how well it’s performing. But with large language models (LLMs) that can write, read, and reason about code, the dynamic changes.

RSI in AI doesn’t necessarily mean a system becomes superintelligent overnight. In practice, it refers to something more modest but still significant: an AI agent that can:

  • Identify a problem or hypothesis
  • Write code to test it
  • Execute that code and observe the output
  • Decide whether to keep, discard, or modify the result
  • Use that outcome to inform the next iteration
Cursor
ChatGPT
Figma
Linear
GitHub
Vercel
Supabase
remy.msagent.ai

Seven tools to build an app. Or just Remy.

Editor, preview, AI agents, deploy — all in one tab. Nothing to install.

Each cycle potentially improves the system — or the model’s understanding of the problem — without a human in the loop at every step.

The Difference Between Self-Improvement and Self-Modification

It’s worth distinguishing between two things that often get conflated:

Self-modification means changing the model’s weights or architecture — something current LLMs don’t do at runtime. A model like Claude can’t update its own parameters during a conversation.

Self-improvement through tooling means building better scaffolding, writing better prompts, improving the code the agent operates in, or refining the workflows it runs. This is what Karpathy’s approach actually addresses — and it’s far more tractable today.

The Karpathy Loop is about the second kind. The model doesn’t change itself. But it changes the system around itself in ways that make subsequent runs more effective.


The Karpathy Loop: Auto Research in Practice

Karpathy has described a workflow he calls “Auto Research” — an agentic loop designed to automate the most repetitive parts of machine learning research. The basic idea: a model proposes an experiment, runs it, reads the results, and decides what to try next.

Here’s a simplified version of how the loop works:

  1. Propose — The agent generates a hypothesis or a specific change to test (e.g., “use a different learning rate schedule,” “add a normalization layer here,” “try a different tokenization approach”).
  2. Implement — The agent writes or modifies the relevant code.
  3. Execute — The code runs. Results come back: metrics, logs, outputs.
  4. Evaluate — The agent reads the results and decides: did this work? Is it better than the baseline?
  5. Commit or discard — If the change improves the metric, it gets committed to the codebase. If not, the agent rolls back and tries something else.
  6. Repeat — The agent proposes the next change based on everything it’s learned so far.

What makes this “recursive” is that the committed changes become part of the codebase that the next iteration works from. The system is always building on its most recent best version.

Why Claude Fits This Pattern

Karpathy has specifically referenced Claude as a capable actor in these loops, largely because Claude handles long contexts well and follows complex multi-step instructions reliably. In an Auto Research loop, the agent needs to keep track of what’s been tried, what worked, what the current state of the codebase is, and what the next logical step is. That requires a model that doesn’t lose the thread across long exchanges.

Claude’s extended thinking capabilities also make it better suited to reasoning about tradeoffs — not just generating code blindly but actually reasoning about why a particular change might work.


Why This Approach Is Different From Simple AI Coding Assistants

Tools like GitHub Copilot or code completion in ChatGPT are reactive. You write code; they help. They don’t close the loop.

The Karpathy Loop is agentic — the model decides what to do next based on previous outcomes. That’s a meaningful shift.

Here’s what separates an agentic coding loop from a standard coding assistant:

FeatureStandard AI Coding AssistantKarpathy-Style Agent Loop
Initiates tasksNo — waits for human inputYes — proposes next steps autonomously
Runs codeSometimesYes — execution is core to the loop
Reads outputNoYes — evaluates results programmatically
Commits changesNoYes — based on defined success criteria
IteratesOnly when you askAutomatically, until criteria are met
TIME SPENT BUILDING REAL SOFTWARE
5%
95%
5% Typing the code
95% Knowing what to build · Coordinating agents · Debugging + integrating · Shipping to production

Coding agents automate the 5%. Remy runs the 95%.

The bottleneck was never typing the code. It was knowing what to build.

The difference isn’t just convenience. It changes what’s possible. A human working with a standard coding assistant can do maybe 10–20 meaningful iterations in a day. An autonomous loop running on cloud compute can do hundreds.

The Role of Defined Criteria

One thing that keeps this from spiraling is that the agent needs clear stopping conditions. What counts as “better”? Accuracy on a benchmark? Lower loss? Faster inference? Fewer tokens used?

Karpathy’s framing emphasizes that the human still sets the objective. The agent optimizes toward it. This is a crucial point for anyone worried about runaway self-improvement: the loop isn’t open-ended. It’s bounded by whatever metric or constraint the human defines at the start.


Real-World Applications Beyond ML Research

Karpathy’s framing is specific to ML research workflows. But the underlying loop — propose, implement, test, commit, repeat — applies much more broadly.

Software Debugging

An agent can identify a failing test, generate a fix, run the test suite, and commit the fix if it passes. This is already happening in tools like Devin and various CI/CD automation frameworks.

Prompt Optimization

An agent can propose variations on a prompt, run each version against a set of test cases, score the outputs, and retain the best-performing version. The next iteration starts from that improved prompt.

Data Pipeline Tuning

Agents can tweak ETL (extract, transform, load) configurations, run them against sample data, check output quality, and commit changes that reduce errors or improve throughput.

Content and Copy Testing

Less technical, but the same structure: generate variants, test against an objective (click rate, readability score, conversion), and iterate. The loop doesn’t care whether it’s optimizing model weights or subject lines.


The Safety Question: Is Recursive Self-Improvement Dangerous?

It’s impossible to write about RSI without acknowledging the safety dimension. AI safety researchers have long identified recursive self-improvement as a potential path to rapid, uncontrolled capability growth.

The concern goes like this: if a system can improve itself, each improvement makes it better at improving itself, which makes the next improvement faster, which creates an accelerating cycle that humans can’t keep up with.

That concern is real. But it applies primarily to a system improving its own reasoning or intelligence — not to a system that’s optimizing code metrics within a bounded loop.

The Karpathy Loop is constrained in several important ways:

  • No weight modification — The underlying model doesn’t change. Only the codebase or prompts do.
  • Human-defined objectives — The agent optimizes for what humans specify.
  • Auditable commits — Every change is logged. Humans can inspect and revert.
  • Bounded scope — The agent works within a defined repository or system, not unconstrained access.

That said, the line between “optimizing a coding workflow” and “improving the agent’s own scaffolding” is not always clear. If an agent can modify its own prompts, adjust its own memory retrieval, or rewrite its own tool-calling logic, the loop becomes more recursive in a way that warrants careful attention.

Responsible Deployment Practices

For teams building on these patterns, some practical safeguards:

  • Require human approval for commits above a certain scope — small changes can auto-commit; larger refactors need review
  • Log everything — every proposal, every test result, every commit decision
  • Set explicit rollback triggers — if a key metric degrades past a threshold, pause the loop
  • Limit what the agent can access — scope permissions tightly

How MindStudio Fits Into Agentic Loops

Building an autonomous agent loop from scratch — even following Karpathy’s framework — requires stitching together a lot of infrastructure: model API calls, code execution environments, output parsing, version control hooks, and conditional logic.

MindStudio handles most of that infrastructure layer. It’s a no-code platform for building and deploying AI agents, with support for 200+ models (including Claude), and a visual workflow builder that lets you define multi-step agentic processes without writing boilerplate.

For teams who want to implement a Karpathy-style loop — propose, test, evaluate, commit — MindStudio’s autonomous background agents are a practical starting point. You can define:

  • What the agent proposes (prompted by a task queue or schedule)
  • How it tests (via webhook calls to your execution environment)
  • How it evaluates (structured output parsing against a rubric)
  • What happens next (branch logic based on pass/fail, or retry with a modified approach)

The platform also includes the Agent Skills Plugin, an npm SDK that lets custom agents call over 120 typed capabilities — including agent.runWorkflow() for chaining multi-step processes — which is useful when integrating MindStudio agents with existing developer tooling like Claude Code or LangChain.

You don’t need to build the plumbing. The loop logic is the interesting part. You can try MindStudio free at mindstudio.ai.


Frequently Asked Questions

What is the Karpathy Loop?

The Karpathy Loop refers to an agentic workflow described by Andrej Karpathy, where an AI agent autonomously proposes changes to a codebase, executes tests, evaluates results, commits improvements, and repeats the cycle. It’s designed to automate the iterative experimentation at the core of ML research — but the same pattern applies to software development, prompt engineering, and other optimization tasks.

Is recursive self-improvement dangerous?

The danger from RSI depends heavily on what’s being improved. A system that optimizes code metrics within a bounded loop — with human-defined objectives and auditable commits — poses very different risks than a system that can modify its own reasoning or expand its own access. Current implementations of RSI in AI agents are constrained in ways that make runaway improvement unlikely, provided humans maintain meaningful oversight and set clear scope limits.

What models work best for autonomous coding loops?

Models with strong instruction-following, long context handling, and reliable code generation tend to perform best in agentic loops. Claude (particularly Claude 3.5 Sonnet and Claude 3 Opus), GPT-4o, and Gemini 1.5 Pro are commonly used. Claude in particular has been highlighted for its ability to reason about complex multi-step tasks without losing context — important when an agent needs to track many iterations of a loop.

How is this different from reinforcement learning?

Not a coding agent. A product manager.

Remy doesn't type the next file. Remy runs the project — manages the agents, coordinates the layers, ships the app.

BY MINDSTUDIO

Reinforcement learning (RL) trains a model by updating its weights based on reward signals over many iterations. The Karpathy Loop doesn’t update model weights at all. Instead, it uses an LLM as a fixed reasoning engine and improves the artifacts the model works with — code, prompts, configurations. You can think of it as RL at the system level rather than the model level.

Can non-engineers use these kinds of agentic loops?

Increasingly, yes. Platforms like MindStudio let non-technical users define agentic workflows visually, without writing code. The underlying logic — define an objective, generate a candidate, test it, evaluate, iterate — can be configured through a UI. The harder part is defining clear success criteria and setting up a reliable execution environment, which still requires some domain knowledge regardless of technical background.

What’s the difference between an autonomous agent and a simple automation?

A simple automation executes a fixed sequence of steps when triggered (e.g., “when form is submitted, send email”). An autonomous agent reasons about what to do next based on context and outcomes. It can branch, retry, and adapt. An agentic loop like the Karpathy Loop is autonomous because the agent decides whether to commit or discard a change — it’s not following a script, it’s evaluating and choosing.


Key Takeaways

  • Recursive self-improvement in AI refers to agents that improve the systems or artifacts they operate on, not their own model weights.
  • The Karpathy Loop is a practical implementation: propose a change → implement it → test it → evaluate → commit or discard → repeat.
  • The loop is bounded by human-defined objectives, auditable commits, and scoped access — which distinguishes it from more speculative RSI scenarios.
  • The same loop structure applies beyond ML research: prompt optimization, software debugging, data pipelines, and more.
  • Building these loops requires stitching together model calls, execution environments, and conditional logic — platforms like MindStudio reduce that overhead significantly.
  • Start with clear success criteria and tight scope limits. The loop is only as useful as the objective it’s optimizing for.

If you want to experiment with building your own agentic loop — without setting up infrastructure from scratch — MindStudio is a practical place to start. The average agent takes under an hour to build, and you can connect it to the models and tools you’re already using.

Presented by MindStudio

No spam. Unsubscribe anytime.