If you run claude -p unattended, the most expensive bug is the one where a usage-limit failure gets retried by the next
cron slot. The second most annoying is the opposite: pausing for hours because a successful run mentioned "rate limit".
Use the JSON result, not grep on everything
Run with --output-format json. The final result object has is_error, result, and num_turns. Decide in this order:
- Exit code 0 and
is_error: false-> success. Do not scan the text at all: an agent that edited your rate-limiter docs, or a turn count of 429, would otherwise trip the check. - Otherwise, scan the error text and non-JSON output for limit wording:
usage limit|rate.?limit|limit reached|hit your .{0,30}limit|out of extra usage|\b429\b|\b529\b|overloaded - Limit -> write a pause-until timestamp (we use 5 hours) and never retry. Anything else -> short backoff (1 hour) and keep the full output for debugging.
Also handle the case where the CLI reports a limit with exit code 0 but is_error: true.
Test it for free
Put a stub claude first on PATH that prints canned results (ok, limit, "hit your limit" with rc 0, success that mentions
"rate limit", plain crash) and assert on your launcher's log. Our selftest does exactly that: https://github.com/spikeyjr/agent-autopilot-kit/blob/main/ops/selftest.sh
The full launcher (lock, daily cap, timeout, API-key stripping, stop date) is MIT: https://github.com/spikeyjr/agent-autopilot-kit
Audit your own cron job (free)
I packaged the checks as a free Claude Code skill, cron-preflight (pay what you want, $0 is fine). It reads your crontab
and launcher and reports pass/fail on ten headless pitfalls, including whether a usage-limit message stops further runs.
The download link is in the README's optional extras, next to a paid setup guide and a paid ops skills pack.
Disclosure: I maintain the repo and sell the paid items; this post was drafted with AI assistance. Unofficial, not
affiliated with Anthropic.

