cheapestinference/claude-auto-retry
Auto-retry Claude Code on subscription rate limits, API overload (529/5xx) and safeguard false positives — waits for the printed reset, exponential backoff, tmux-based
What it solves
Long Claude Code sessions get stopped mid-task when Anthropic's subscription rate limits hit ("5-hour limit reached", "session limit", "weekly limit", "rate limit hit", etc.). Without help, Claude stops and you have to come back hours later to type "continue" yourself. Worse, if your SSH connection drops or your terminal closes during that wait, the session is lost.
This tool watches the terminal, notices when a limit message appears, waits until the exact reset time (plus a safety margin), and then sends "continue" automatically. It wraps the session in tmux so disconnections don't kill it — reattach later and your task is done.
Note: since Claude Code v2.1.234, the CLI itself can wait out usage limits natively for simple interactive cases. But that native wait dies with the process (no /resume restart), doesn't arm for weekly resets more than 24 hours out, model-specific limits, or Remote Control sessions, and doesn't cover API overloads, safeguard false-positives, interrupted streams, or wrap-up stalls. This tool covers those cases, and its tmux wrapper is what actually lets the native wait survive a disconnect.
How it works
Install by running npm i -g claude-auto-retry then claude-auto-retry install. The installer injects a shell function (in .bashrc/.zshrc) so claude still launches the same interactive TUI, but transparently inside a tmux session.
A background monitor polls the tmux pane every 5 seconds with near-zero CPU. It:
- Detects rate-limit banner text (many exact patterns are shipped; custom regex patterns can be added via config)
- Parses the reset time — timezone-aware with full IANA support, DST-safe
- Waits until reset + 60s margin
- Verifies Claude is still the foreground process
- Sends "continue" via tmux send-keys
If you're not already in tmux, the tool creates a session automatically; if tmux is missing, it tries to install it (apt, dnf, brew, pacman, apk).
Beyond usage limits, it handles several other failure modes: sustained API overload (429/5xx) triggers exponential backoff with jitter; AUP safeguard false-positives get a bounded re-send; interrupted mid-response streams get one resume; the ~95% wrap-up notice gets one "continue" nudge; and a stale native "Press enter to continue" gets an Enter press. Configuration lives in ~/.claude-auto-retry.json (all fields optional; invalid values fall back to defaults). Zero dependencies — pure Node.js.
Who it's for
People who run long Claude Code tasks overnight, over SSH, or unattended, and want them to finish without babysitting. Also anyone hitting subscription rate limits (5-hour, session, or weekly) or API overload errors (429/500/502/503/504/529) who'd rather not re-run the whole thing. Simple interactive users on one always-on machine with Claude Code v2.1.234+ may find the native feature sufficient.
Highlights
- Zero workflow change: same
claudecommand, same TUI, same everything - tmux wrapper keeps the session and the wait alive through SSH drops, terminal closes, and sleeps (the native wait dies with the process)
- Timezone-aware, DST-safe reset-time parsing (including half-hour offsets)
- Handles many failure modes: usage limits, API overload backoff, safeguard false-positives, interrupted streams, wrap-up stalls, stale native continue
- Self-healing: reconcile re-arms monitors for any live claude session that lost one; optional systemd/launchd timer runs it automatically
- Configurable: retries, wait margin, custom patterns, retry message — invalid config falls back to safe defaults
- Zero dependencies, pure Node.js, auto-installs tmux if missing
- tmux status bar indicator shows monitoring state (waiting, backing off, gave up)
- Safe by design: re-checks the banner before typing, defers to native auto-continue (up to 3 minutes), bounded re-arms
- Environment forwarding via a 0600 temp file — nothing appears on tmux command lines, so secrets can't leak into /proc/cmdline
Related
- Project
- Project
- Project
- Project
- Project