---
id: "concept-karpathy-loop"
type: "concept"
source_timestamps: ["00:02:03", "00:02:44", "00:09:04"]
tags: ["agent-architecture", "optimization", "constraints"]
related: ["concept-karpathy-triplet", "claim-constraints-enable-optimization", "framework-karpathy-loop-execution", "entity-andrej-karpathy"]
definition: "A constrained, iterative AI self-improvement cycle consisting of proposing an edit to a single file, running a time-boxed experiment, evaluating against one metric, and committing or reverting."
sources: ["s04-karpathy-agent-700"]
sourceVaultSlug: "s04-karpathy-agent-700"
originDay: 4
---
# The Karpathy Loop

## Definition
A constrained, iterative AI self-improvement cycle consisting of proposing an edit to a single file, running a time-boxed experiment, evaluating against one metric, and committing or reverting.

## Origin
Named by [[entity-nate-b-jones|Nate B. Jones]] after [[entity-andrej-karpathy-d4|Andrej Karpathy]]'s **630-line Python script** that demonstrated minimalist autonomous self-improvement of training code.

## The Cycle
The agent:
1. Proposes an edit to a **single file**.
2. Runs a **time-boxed experiment** (e.g., 5 minutes).
3. Evaluates against a **single objective metric**.
4. **Commits** the change if successful or **reverts** if it fails.

See [[framework-karpathy-loop-execution]] for the full step-by-step cycle.

## Why It Works
The magic lies entirely in the constraints (see [[claim-constraints-enable-optimization]]). By narrowing scope to one file, one metric, and a fixed time limit, the optimization problem becomes tractable for current LLMs. They can hold the entire context in memory, understand the full scope of their proposed changes, and iterate hundreds of times overnight without fatigue, distraction, or sunk-cost bias.

## Documented Result
Karpathy's loop found **20 genuine improvements** and **cut training time by 11%** on a codebase that had already been heavily optimized by top human researchers.

## Productization
For business deployment, the loop must be paired with the [[concept-karpathy-triplet|Karpathy Triplet]] (editable surface + metric + time budget) and applied through [[concept-harness-engineering|Harness Engineering]] rather than weight tuning. The architectural pattern is the [[concept-meta-task-agent-split|Meta-Agent / Task Agent split]], where outputs of the loop feed [[concept-trace-driven-optimization|trace-driven optimization]].

## Related Quote
> [[quote-magic-in-constraints|"The magic is actually in the constraints."]]


## Related across days
- [[concept-meta-task-agent-split]]
- [[concept-engineering-manager-mindset]]
- [[claim-constraints-enable-optimization]]
- [[concept-dark-factory]]
- [[arc-constraints-as-leverage]]
