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 Tadashi Shigeoka published cc-usage-guard v0.1.0, an unofficial tool that records Claude Code subscription rate_limits from the status line and halts a session via a PreToolUse/UserPromptSubmit hook once any monitored window (five_hour, seven_day, spend_limit) reaches a configurable threshold, 90% by default. The design is forced by the fact that rate_limits, exposed to the status line command since Claude Code 2.1.80, is absent from the JSON delivered to PreToolUse and UserPromptSubmit hooks, so statusline.sh atomically writes usage to ~/.claude/usage-guard/usage.json and guard-hook.sh reads it with jq to decide whether to return continue: false. The tool targets Claude.ai Pro, Max and Ultra plans and is not affiliated with Anthropic. 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 Tadashi Shigeoka https://codenote.net/en/author/tadashi-shigeoka/ · Sun, November 8, 2026 Leaving a Claude Code https://code.claude.com/docs/en/overview agent session running while I stepped away to another task sometimes ate through the rest of my 5-hour or 7-day quota before I got back. If I were watching, closing claude at 90% would have been enough, but that only works when I’m at the terminal. What I wanted was for the session to stop itself the moment usage crossed a threshold, so that the remaining slice is still available for a short manual fix or a quick check. I rolled that behavior into two shell scripts and one state file and published cc-usage-guard https://github.com/codenote-net/cc-usage-guard . The initial PR is codenote-net/cc-usage-guard 1 https://github.com/codenote-net/cc-usage-guard/pull/1 and the release is v0.1.0 https://github.com/codenote-net/cc-usage-guard/releases/tag/v0.1.0 . This post walks through the one constraint that shaped the design that rate limits https://code.claude.com/docs/en/statusline is only exposed to the status line command and the decisions that fell out of it. The tool is unofficial, not affiliated with Anthropic, and targets Claude.ai https://claude.com/product/overview Pro, Max, and Ultra plans. What it does Once installed, the status line shows the subscription usage after the first response in a claude session, next to anything else that was there before: If a tool call or a prompt submission happens while any monitored window is at or above the threshold 90% by default , the hook stops the session: The reset time is included in the message so you can decide when to come back. The threshold is configurable through CLAUDE USAGE GUARD THRESHOLD or the threshold key in config.json , and the monitored windows five hour , seven day , spend limit are selected through windows . rate limits is only exposed to the status line Reading the Claude Code hooks documentation https://code.claude.com/docs/en/hooks first, I noticed that the JSON delivered to PreToolUse or UserPromptSubmit does not contain rate limits . The status line command https://code.claude.com/docs/en/statusline , which has carried rate limits since Claude Code 2.1.80, is the one surface that does: on every refresh it receives a JSON payload with fields such as rate limits.five hour.used percentage . That asymmetry set the architecture. Usage can only be observed from the status line, so one process has to record the state and a different process has to consult it and stop the session. cc-usage-guard is organized exactly that way: php flowchart TD TUI Claude Code TUI -- |status line JSON