Developer Builds Token Sentinel Script to Prevent Claude Code Rate-Limit Surprises
A developer has shared a shell script called token-budget-advisor.sh designed to monitor token usage within Claude Code's 5-hour output-token blocks before the cap is reached. The problem arose when automated background jobs silently consumed the entire token budget overnight, leaving the developer with no work completed by morning. The script uses a dual-source approach, treating the ccusage command-line tool as the primary data source and a local cost-log.jsonl file as a fallback, ensuring the guard remains active even if one source fails. Two alert thresholds are defined — a warning at 800,000 output tokens and a critical level at 1.2 million — giving users time to shift heavy workloads to the next block. The tool also tracks daily session counts and weekly costs, emitting a single-line status suitable for dashboards or daily briefings.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in