Numbers·Partial·Claude Code
Guard hook for usage window
The author built a Claude Code hook that warns before large uncached requests and blocks sub-agent spawning when the usage window is nearly used up.
Over 75 days, the biggest agent burst fell from 365 to 27, and requests above 500k tokens dropped from 14.5% to 0.6%.
Overview
How it was set up
Claude Code 2.1.287 or later with hooks. It counts agents across every session on the machine, makes no network calls, and is MIT-licensed.
Worth knowing
Lockouts still went up, because many parallel main sessions also use up the window.
A prompt to start from
The source does not show the prompt.
Sources 1
History
- Source published
- 2026-10-22
- Added to Agentic Feats
- 2026-10-26
- Pick
- No
- Markdown copy
- /c/guard-hook-for-usage-window-claude-code.md
More in setup and meta
38 featsResultTickets run unattended with per-turn cost receipts; one ticket reached $402 over nine runs before the cost showed in the app, which prompted a fix.
ResultEight identical TypeScript checks dropped from 22.32 s to 4.46 s on an M1 Pro, and digests cut context by about 97%.
ResultA demo shows Claude building the bat project (223 crates) with a single bar that fills during the build and turns green when done.