claude-autoresume
A Claude Code plugin that automatically resumes a session running inside
tmux after a usage/rate limit resets — no polling, no screen-scraping.
See REQUIREMENTS.md for the full design and rationale, and
TODO.md for build status. In short: it reacts to Claude Code's own
StopFailure hook (matcher rate_limit) rather than watching the terminal,
so it can't be fooled by a transcript that merely mentions "rate limit", and
it targets the exact pane the session is running in via $TMUX_PANE rather
than guessing.
Status: implemented and verified against real StopFailure events,
including one caught-and-fixed real-world failure. This plugin's own
development sessions have hit real rate limits (session-limit and
weekly-limit both), which confirmed (via Claude Code's hooks docs plus this
session's own transcripts) that StopFailure's payload carries no
error-detail fields at all — only session_id, prompt_id,
transcript_path, cwd, permission_mode, hook_event_name. The reset
message (e.g. "You've hit your weekly limit · resets 3pm (America/Los_Angeles)") lives in the transcript at transcript_path, so the
hook reads it from there.
A real weekly-limit event exposed a real bug: a transcript can accumulate
more than one rate_limit line over a session's life (an earlier
session-limit hit, then a later weekly-limit hit hours after), and the
original retry logic would happily lock onto an old stale line just because
it already existed on disk, scheduling a waiter for the wrong time entirely.
Fixed by having the hook snapshot the transcript's line count before
handing off, so the resolver only ever considers lines appended after that
point — see TODO.md Phase 0 for the full account. Still open: a live
"continue while still limited" retry loop (S1.6).
How it works
Claude Code session (inside tmux)
└─ StopFailure hook (matcher: rate_limit) hooks/hooks.json
└─ scripts/on-rate-limit.sh runs <1s, then exits
└─ spawns a DETACHED resolver
└─ scripts/resolve-reset.sh
├─ reads the reset message from the session's own
│ transcript (transcript_path from the hook payload),
│ retrying for up to ~60s in case that line hasn't
│ been flushed to disk yet
├─ else: guessed payload fields, else: one pane capture
├─ writes a per-pane lock file (dedupes repeated events)
└─ spawns a DETACHED waiter
└─ scripts/waiter.sh
├─ sleeps until reset time + grace period
├─ re-checks: pane still exists, running an
│ allowed command, not in copy-mode, no
│ recent user activity
└─ tmux send-keys -l "continue" ; send-keys Enter
The hook/resolver split exists because reading the reset time can take up to
a minute (retrying against a not-yet-flushed transcript), but the hook
itself must return in well under a second — so the retry lives in its own
detached process instead of blocking Claude Code.
If any safety check fails, or no reset time can be determined, the script
logs why and does nothing — it never guesses, never retries blindly, and
never sends Escape.
Prerequisites
- tmux. Claude Code must be running inside a tmux pane — this is how the
plugin locates and re-injects into the right session. Outside tmux, the
hook still runs but can only fire a best-effort desktop notification (see
below); it will not and cannot type anything for you.
- bash (present on essentially every Linux/macOS system; scripts avoid
bashisms that require a particularly recent version).
- Claude Code with plugin support (
/plugin command available).
- Optional: jq, for more robust JSON field extraction from the hook
payload. If absent, a regex-based fallback is used instead — this covers
the flat string/number fields the payload is expected to contain, but is
not a general JSON parser.
- Optional:
notify-send (Linux) or osascript (macOS), used only for the
best-effort desktop notification when Claude Code is running outside tmux.
Install
Clone the repo first:
git clone https://github.com/RootInit/Claudimator.git
Quick test (no persistent install):
claude --plugin-dir /path/to/Claudimator
Loads the plugin for that one session only. Good for trying it out before
committing to a persistent install. Replace the path with wherever you
cloned this repo.
Persistent install:
# inside a Claude Code session:
/plugin marketplace add /path/to/Claudimator
/plugin install claude-autoresume@claudimator