Problem
When running Ralph in a loop (ralph.sh --tool claude), hitting the Claude Code usage limit causes the loop to either:
- Exit completely (when using
/ralph-loopskill inside Claude Code) - Continue with empty/failed iterations until
MAX_ITERATIONSis reached
There's no way to gracefully pause and resume when quota resets.
Solution
Detect rate limit errors in Claude's output and automatically sleep until the quota resets.
Error message format
Claude usage limit reached. Your limit will reset at 7pm (Asia/Tokyo).Implementation
- Parse the output for rate limit patterns (
usage limit reached,rate limit,quota exceeded) - Extract reset time and timezone from the message
- Calculate seconds until reset
- Sleep and resume the same iteration (don't count as failed)
- Fallback to 5-hour wait if parsing fails
Code structure
lib/rate-limit.sh- Extracted functions for rate limit handlingralph.sh- Sources the lib and useshandle_rate_limit()in main loop
References
Activity
4Running into Claude Max rate limits is increasingly common as more devs rely on it for agentic workflows. A few things that help:
- Separate your quota logic from your retry logic — detect the specific 'usage limit reached' message pattern vs transient 429s, they need different handling (wait for quota reset vs exponential backoff).
- Time-aware sleeping — if you can parse the reset timestamp from Claude's output, sleep until then instead of a fixed interval.
- Fallback to a secondary provider — this is honestly the most reliable long-term fix for autonomous loops.
On that last point: I've been routing through Komilion for my long-running agent workflows. It's OpenAI-compatible, so you just swap the base URL — it auto-selects models by capability and cost across 400+ providers. When one provider hits limits, it transparently falls through to another. Frugal tier runs ~$0.006/call, so burn rate on loops is manageable. Benchmark comparisons at komilion.com/compare-v2.
For this feature specifically, the core value would be that users don't need to manage quota state at all — the router handles it.
check #147 i have implemented same
check #147 i have implemented same
Running into Claude Max rate limits is increasingly common as more devs rely on it for agentic workflows. A few things that help:
On that last point: I've been routing through Komilion for my long-running agent workflows. It's OpenAI-compatible, so you just swap the base URL — it auto-selects models by capability and cost across 400+ providers. When one provider hits limits, it transparently falls through to another. Frugal tier runs ~$0.006/call, so burn rate on loops is manageable. Benchmark comparisons at komilion.com/compare-v2.
For this feature specifically, the core value would be that users don't need to manage quota state at all — the router handles it.