Sun, November 8, 2026
11 min read
I Built cc-usage-guard — Recording rate_limits from the Claude Code Status Line and Stopping the Session at a Threshold with a PreToolUse Hook
#cc-usage-guard#claude-code#ai-agent#rate-limit#shell
To stop an unattended Claude Code agent from draining the last of my 5-hour or 7-day quota, I built cc-usage-guard. Because Claude Code only ships rate_limits to the status line command, the design splits into a writer (statusline.sh) that persists the usage payload and a reader (guard-hook.sh) that stops the session from PreToolUse / UserPromptSubmit when the threshold is hit. This post walks through the fail-open rules, the single jq invocation inside the hook, the plan-dependent set of windows, and the idempotent installer behind v0.1.0.
read more →