## Definition
A **Ralph Loop** (also: Ralph Wiggum Loop) is an outer agentic loop that wraps an entire inner [[Agentic Loop]], repeatedly re-triggering the agent — with its own internal feedback — until a maximum iteration count is reached or a stopping criterion is met. The pattern was coined by Australian engineer Geoffrey Huntley as a homage to the naively optimistic Simpsons character Ralph Wiggum, capturing the idea of an agent that just keeps going, unconcerned with failure.
Formally: if the agentic loop is the sequence perceive → reason → act → observe for one task completion, the Ralph Loop is the meta-sequence `for i in 1..N: run_agentic_loop(prompt + feedback_from_previous)`.
## Mechanics
1. The agent receives an initial prompt and executes its full inner loop until it believes the task is complete.
2. At loop-end, a feedback step evaluates the output: an LLM reviewer (or a scripted test) identifies gaps and generates a delta-prompt describing what remains.
3. The outer loop appends the delta-prompt and restarts the agent from its current state, iterating up to `--max-iterations N`.
4. Context growth is managed between iterations (e.g. via context compaction) to prevent the window from saturating.
In Claude Code the pattern is delivered as the `ralph-loop` official plugin (`/plugin install ralph-loop@claude-plugins-official`). The run command is:
```
ralph-loop:ralph-loop "<main prompt>" --max-iterations <N>
```
The plugin writes a `ralph-loop-local.md` scratchpad in `.claude/` to track loop state.
## Relationship to YOLO Mode
A Ralph Loop is most powerful when combined with [[Permission Policy]] bypass (YOLO / `--dangerously-skip-permissions`), enabling fully unattended multi-hour runs. Without a [[Headless Agent in CI|sandbox]], YOLO + Ralph Loop is high risk; Huntley's recommended setup pairs it with a cloud sandbox that enforces a blast radius.
## When to Use
| Use | Avoid |
|---|---|
| Greenfield MVPs and prototypes | Mission-critical production codebases |
| Generating large volumes of boilerplate | Highly innovative or novel API integrations |
| Overnight autonomous builds | When predictable, reviewable increments are required |
The pattern trades predictability for throughput: an eight-minute YOLO task run ten times can produce work equivalent to eighty minutes of autonomous effort.
## Relation to Workflow Evolution
The Ralph Loop sits at stage five of the practitioner trust ladder — above YOLO (one unattended run) and below fully orchestrated [[Multi-Agent System|multi-agent swarms]]. Its distinguishing feature is the **self-generated feedback mechanism**: the agent critiques and extends its own output across iterations, unlike YOLO which simply runs once without checkpointing.
## Related
- [[Agentic Loop]]
- [[Permission Policy]]
- [[Multi-Agent System]]
- [[Orchestrator-Subagent Pattern]]
- [[Context Compaction]]
- [[Headless Agent in CI]]
- [[Parallel Agents via Worktrees]]
## Sources
- [[AI Coder - Claude Code and Coding Agents (Udemy)]]