Ralph loops (named after Ralph Wiggum from The Simpsons) are a technique popularized by Geoffrey Huntley in mid-2025 for running AI coding agents in persistent, iterative loops.
tldr
- •simple bash `while true` script that keeps feeding the agent a prompt until done
- •solves context rot: quality drops as conversation history bloats → hits limits → gets compacted → loses key details
- •each iteration starts with fresh context (new agent session)
- •memory persisted externally: git commits, plan files (PRD.json), progress logs (AGENTS.md)
- •agent reads specs at start of every loop → picks undone task → implements/tests/commits → updates plan → loops
how it works
- •external bash loop kills/restarts agent each time → full fresh context every iteration
- •git + files as single source of truth
- •agent signals "done" (e.g., `<promise>COMPLETE</promise>`) or hits max iterations to exit
- •safeguards: max iterations (avoid burning tokens), acceptance criteria (tests, linter feedback), pre-commit hooks
common mistakes
- •many plugins run loop inside one long session → still hits context limits/compaction → loses benefits
- •Jeff says: "this isn't it" - must be external wrapper, not internal loop
- •better results from bash scripts around Claude Code / other CLIs
when to use
- •larger/complex tasks (building whole features from a PRD)
- •linear execution reduces merge conflicts
- •focuses on context engineering - give agent right starting info every time
when not to use
- •very long single tasks/refactors - tools like CodeEx handle extended sessions better
- •some top agentic coders prefer those over Ralph loops
bottom line
Ralph loops aren't just "keep going forever" - they're a way to rethink agent orchestration, avoid context rot via fresh starts + external memory, and hand off bigger scopes to AI reliably.