#82·ralph

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-loop skill inside Claude Code)
  • Continue with empty/failed iterations until MAX_ITERATIONS is 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

  1. Parse the output for rate limit patterns (usage limit reached, rate limit, quota exceeded)
  2. Extract reset time and timezone from the message
  3. Calculate seconds until reset
  4. Sleep and resume the same iteration (don't count as failed)
  5. Fallback to 5-hour wait if parsing fails

Code structure

  • lib/rate-limit.sh - Extracted functions for rate limit handling
  • ralph.sh - Sources the lib and uses handle_rate_limit() in main loop

References