Blog: Ralph Loop
A Simple Explanation
A Ralph Loop is, at its core, very simple:
Running AI agents inside a bash loop so they keep executing for as long as they need to.
By looping agents continuously, you allow them to refine their outputs, correct mistakes, and become more reliable over time. The obvious concern is token usage—loops can burn through tokens quickly. However, most Ralph plugins and frameworks include token consumption controls and rate-limiting features to prevent things from getting out of hand.
The Basic Technique
The fundamental idea behind a Ralph Loop is a basic infinite loop in bash:
while :; do cat PROMPT.md | claude-code ; done
Does Ralph Use More Tokens?
At first glance, it looks like Ralph uses more tokens. In practice, it often does the opposite.
When using the Ralph framework (not the plugin), each loop starts a brand-new claude-code session with a zeroed context window. This matters because as context grows, agent performance usually degrades. The more irrelevant or stale information piles up, the worse the outputs become.
This is why compaction is essential.
Instead of carrying a bloated context forward, Ralph resets the environment each time. That keeps agents focused, reduces hallucinations, and cuts down on wasted retries. Fewer retries usually means fewer tokens overall.
In short: Ralph doesn’t necessarily spend more tokens—it often saves them.
Framework vs Plugin
This is where most confusion comes from.
Claude Plugin
The loop runs inside your current session
Context continuously accumulates
The context window eventually overflows
Agent quality degrades over time
This approach isn’t wrong, but it’s fragile. If you rely on the plugin, you must compact or clear the context window frequently.
Ralph Framework
Each loop starts a new session
Context begins at zero every time
Compaction is part of the design
Output quality stays consistent
The framework approach is more complex, but it gives you far more control over context, performance, and cost.
Final Thoughts
The “correct” answer is usually the framework. Yes, it’s harder to set up—but complexity buys stability.
That said, if Ralph doesn’t need to behave exactly like this, the plugin can still work fine. Just be disciplined:
Loops don’t ruin agents.
Unmanaged context does.