Ralph loop
A Ralph loop runs a coding agent again and again with the same prompt, each time in a fresh context, until the task is done.
A Ralph loop is a simple way to keep a coding agent working on a large task. A script starts the agent with a fixed prompt, waits for it to finish, and starts it again with the same prompt. Each run begins with an empty context. The loop itself has no logic beyond restarting the agent.
Progress carries over through files rather than through the context. The prompt points the agent to a plan, a list of tasks, and the code itself, and each run picks the next piece of work and updates them. Because every run starts fresh, the agent never fills its context window or needs compaction. Tests and other checks in the repository decide whether each run's work holds up.
A Ralph loop can run for hours without a person watching, so it is a form of background agent. It runs commands that no one reviews as they happen. For that reason, it usually runs in a sandbox, with access only to the repository and the tools it needs. The loop stops when the plan is complete or when a person ends it.