New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

cost-gate

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cost-gate

Claude Code hook that tracks cumulative token spend and denies tool calls when a budget ceiling is hit

latest
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

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-gate

Setup

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 fresh

Requirements

  • Node.js >= 22
  • ESM only

License

MIT

FAQs

Package last updated on 22 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts