#82

feat: Auto-detect rate limits and wait for reset

OpenIbramadi75opened 8mo ago

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

Activity

4
hshahrokni28mo ago

Running into Claude Max rate limits is increasingly common as more devs rely on it for agentic workflows. A few things that help:

  1. 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).
  2. Time-aware sleeping — if you can parse the reset timestamp from Claude's output, sleep until then instead of a fixed interval.
  3. 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.

hshahrokni28mo ago

Running into Claude Max rate limits is increasingly common as more devs rely on it for agentic workflows. A few things that help:

  1. 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).
  2. Time-aware sleeping — if you can parse the reset timestamp from Claude's output, sleep until then instead of a fixed interval.
  3. 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.

merahul226mo ago

check #147 i have implemented same

merahul226mo ago

check #147 i have implemented same