feat: Auto-detect rate limits and wait for reset
Author: Ibramadi75Created Feb 3, 2026Updated Apr 15, 2026
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
Source: snarktank/ralph