claude-auto-retry
Automatically retry Claude Code sessions when you hit Anthropic subscription rate limits.
When Claude Code shows "5-hour limit reached - resets 3pm", this tool waits for the reset and sends "continue" automatically. You come back to find your work done.
No dependencies. No workflow change. Just install and forget.
💡 Why wait out the limit at all? This tool auto-resumes Claude Code the moment you're rate-limited — but if you run overnight jobs or always-on agents, there's a way to stop hitting the wall in the first place. See how it's done →
The Problem
You're in the middle of a complex task with Claude Code. After a while, you see:
You've hit your limit · resets 3pm (Europe/Dublin)
Claude stops. You have to wait hours, come back, and type "continue". If you're running long tasks overnight or while AFK, this kills your productivity.
The Solution
npm i -g claude-auto-retry
claude-auto-retry install
That's it. Type claude as you always do. When the rate limit hits, the tool:
-
Detects the rate limit message in the terminal
-
Parses the reset time (timezone-aware)
-
Waits until the limit resets + 60s margin
-
Verifies Claude is still the foreground process
-
Sends "continue" automatically
You come back to find your task completed.
How it Works
You type "claude"
│
▼
Shell function (injected in .bashrc/.zshrc)
│
├─ Already in tmux? ──▶ Start background monitor
│ Launch claude with full TUI
│
└─ Not in tmux? ──▶ Create tmux session transparently
Launch claude + monitor inside
Attach (looks the same to you)
MONITOR (background, ~0% CPU):
│
├─ Polls tmux pane every 5 seconds
├─ Detects rate limit text
├─ Parses reset time from message
├─ Waits until reset + safety margin
├─ Verifies Claude is still the foreground process
└─ Sends "continue" via tmux send-keys
Why tmux?
When you disconnect (SSH drops, close terminal, laptop sleeps), tmux keeps running. The monitor keeps waiting. When you reconnect with tmux attach, you find Claude working on your task. This is the key advantage over wrapper scripts.
Features
-
Zero workflow change — same
claudecommand, same TUI, same everything -
Works with and without tmux — auto-creates tmux session if you're not already in one
-
Auto-installs tmux if missing (apt, dnf, brew, pacman, apk)
-
Timezone-aware — parses reset times with full IANA timezone support (including half-hour offsets)
-
DST-safe — iterative offset correction handles daylight saving transitions
-
Safe send-keys — verifies Claude is still the foreground process before injecting text
-
Self-healing coverage —
reconcilere-arms monitors for any liveclaudesession that lost one; an optional timer (systemd --useron Linux, launchd on macOS) runs it automatically (details) -
Overload backoff — detects sustained API overload (
429/500/502/503/504/529) and retries on a configurable exponential backoff with jitter and a cumulative-wait cap, distinct from the usage-reset path (details) -
Safeguard retry — auto-continues past an AUP-safeguard false-positive (often transient), capped at a few tries so a sticky flag can't loop (details)
-
tmux status bar indicator — see at a glance whether a pane is being monitored, waiting on a reset, backing off from overload, or has given up (details)
-
--printmode support — buffers output, retries cleanly for piped/scripted usage -
Configurable — retry count, wait margin, custom patterns, retry message
-
Config validation — bad config values fall back to safe defaults instead of crashing
-
Zero dependencies — pure Node.js, no
node_modules
Messages Detected (verbatim)
The tool acts on these real-world Claude Code renders — if you landed here after pasting one of these errors into a search engine or an AI assistant: yes, this tool automates the wait-and-retry for all of them.
Usage / session limits — waits until the printed reset, then continues
Render Example
N-hour limit
5-hour limit reached - resets 3pm (UTC)
Session limit
You've hit your session limit · resets 2am (Europe/Zurich)
Weekly limit
You've hit your weekly limit · resets Oct 9, 10am
Usage limit
Claude usage limit reached. Resets at 2pm
Out of extra usage
You're out of extra usage · resets 3pm
Try again
Please try again in 5 hours
Hit your limit
You've hit your limit · resets 3pm (Europe/Dublin)
Rate limit
Rate limit hit. Resets at 4pm
Live-limit companion hint
/usage-credits to finish what you're working on.
The /rate-limit-options menu — driven to "Stop and wait", never "Upgrade"
What do you want to do?
❯ 1. Upgrade your plan
2. Stop and wait for limit to reset (3pm)
Handled across any menu layout (the option order varies by Claude Code version); the tool locates the cursor and the "Stop and wait" option, and refuses to press Enter if the layout is unreadable.
API overload / transient errors — exponential backoff with jitter
Render Example
Terminal API error (colon form)
API Error: 529 {"type":"error","error":{"type":"overloaded_error","message":"Overloaded"}}
5xx family
API Error: 500 / 502 / 503 / 504 … (including bodyless renders like 503 no healthy upstream)
API-level 429
API Error: Server is temporarily limiting requests (not your usage limit) · Rate limited
Safeguard false positives — bounded immediate re-send
API Error: <model>'s safeguards flagged this message (https://www.anthropic.com/legal/aup).
They may flag safe, normal content as well. … Claude Code can't respond to this request with <model>.
Custom patterns can be added via config for future message format changes.
Detection is chrome-aware: it looks at the live bottom of the pane, but first skips
past Claude Code's UI furniture — the input box, footer, key hints, the todo/task widget,
the status spinner, and the /usage-credits hint. So a genuine limit banner still
registers even when a tall task list or background-agent status pushes it well above the
prompt, while a banner merely quoted in scrollback (with real output below it) does not
trigger a retry.
Your own customPatterns are the exception: they are matched against the raw last-N
lines (not the chrome-skipped view), so a pattern keyed on footer text — a usage
percentage, a model name — keeps firing. You own the false-positive tradeoff for your
regexes; the built-in detection keeps the chrome-aware discipline.
Configuration
Optional. Create ~/.claude-auto-retry.json:
{
"maxRetries": 5,
"pollIntervalSeconds": 5,
"marginSeconds": 60,
"fallbackWaitHours": 5,
"retryMessage": "Continue where you left off. The previous attempt was rate limited.",
"customPatterns": ["my custom pattern"]
}
Option Default Description
maxRetries
5
Max retry attempts per rate-limit event
pollIntervalSeconds
5
How often to check the terminal (seconds)
marginSeconds
60
Extra wait after reset time (seconds)
fallbackWaitHours
5
Wait time if reset time can't be parsed
retryMessage
"Continue where..."
Message sent to Claude on retry
customPatterns
[]
Additional regex patterns to detect rate limits
All fields optional. Invalid values fall back to defaults automatically.
Launch wrapper
Set CLAUDE_AUTO_RETRY_LAUNCH_WRAPPER to a prefix command and it's prepended to each
interactive session — useful for keeping a machine awake while Claude works, or any other
per-process wrapper:
# macOS: don't sleep while a session runs
export CLAUDE_AUTO_RETRY_LAUNCH_WRAPPER="caffeinate -i"
Generic (not macOS-specific — e.g. nice, chrt … work too). Unset or blank spawns
claude directly, unchanged.
Overload backoff
Separate from subscription rate limits, this fork also detects sustained API
overload — Claude Code's own terminal API Error: <code> line for the retryable
set (429 / 500 / 502 / 503 / 504 / 529, or an overloaded_error JSON body) — and
retries on an exponential backoff instead of waiting for a usage reset. The two
paths never collide; usage limits always take precedence.
Sustained only. Claude Code already retries transient 5xx/529 internally with its own backoff. This feature fires only when those internal retries are exhausted and a terminal error is left in the pane. It should rarely trigger.
Terminal vs. transient. Claude Code renders an in-progress retry as the
parens form API Error (529 …) · Retrying in 5s · attempt 3/10, and the final
exhausted error as the colon form API Error: 529 …. Detection requires the
colon form and suppresses the · Retrying… / attempt n/m suffix, so the tool
never interrupts Claude's own backoff.
Anchored, tail-only matching (why it won't fire on your code). Patterns are
case-insensitive regexes matched against only the last 12 lines of the
pane — never the full scrollback. They are anchored to Claude Code's API Error: <code> render, so a bare 503 in code you're editing (res.status(503)),