Developer Builds 60-Second Cache to Stop Claude Code Hook From Slowing Workflows
A developer working with Claude Code's MAX plan found that calling the usage-checking tool 'ccusage' on every prompt submission added 200–400ms of latency, undermining the very efficiency the hook was meant to provide. To fix this, they built a shell script called cost_guard.sh that caches the token usage result for 60 seconds, throttling API calls even during rapid-fire prompting. The script also fails open on timeout, meaning a slow or failed ccusage call never blocks the workflow. A companion script, stop_cost_log.sh, runs at session end to calculate actual costs from the transcript and log them to a local file. Together, the two hooks provide both a real-time usage estimate and an accurate post-session cost record without degrading performance.
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