cost-gate
v0.1.1
Published
Claude Code hook that tracks cumulative token spend and denies tool calls when a budget ceiling is hit
Readme
cost-gate
Claude Code hook that tracks cumulative token spend across a session and blocks tool calls when a budget ceiling is hit.
Install
npm install -g cost-gateSetup
Add to ~/.claude/settings.json as both PreToolUse and PostToolUse hooks with matcher ".*".
Configuration
Create .cost-gate.json in your project root (optional):
{
"budget": 10.00,
"costPerToken": 0.000003,
"warningThreshold": 0.8
}How It Works
- Every tool call input is estimated as tokens (payload size / 4)
- Every tool response is estimated as tokens (PostToolUse, advisory)
- Running total stored in
.cost-gate-session.json - When total exceeds budget: all tool calls denied
- At warning threshold (80%): allowed but warning injected
CLI
cost-gate status # show current session spend
cost-gate reset # clear session, start freshRequirements
- Node.js >= 22
- ESM only
License
MIT
