Daily Tool-Call Budget Gate
A blunt but effective ceiling for an unattended automation (like a scheduled headless agent) that could otherwise loop indefinitely on a bad day — once the configured daily count is hit, every further tool call is blocked until the counter resets at midnight.
1. Save this as the hook script
#!/usr/bin/env python3
"""PreToolUse hook — blocks tool calls once a daily ceiling is hit.
Wire with matcher "*"."""
import json, sys, datetime
from pathlib import Path
data = json.load(sys.stdin)
DAILY_LIMIT = 500
today = datetime.date.today().isoformat()
counter_path = Path(data.get("cwd", ".")) / ".claude" / f"tool_call_count_{today}.txt"
count = int(counter_path.read_text()) + 1 if counter_path.exists() else 1
if count > DAILY_LIMIT:
print(f"BLOCKED: daily tool-call ceiling of {DAILY_LIMIT} reached. "
f"Resets at midnight.", file=sys.stderr)
sys.exit(2)
counter_path.parent.mkdir(parents=True, exist_ok=True)
counter_path.write_text(str(count))
sys.exit(0)
Save to a path inside your project, e.g. .claude/hooks/daily-tool-call-budget-gate.sh, then chmod +x it.
2. Wire it into .claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "*",
"hooks": [
{"type": "command", "command": "python3 .claude/hooks/daily-tool-call-budget-gate.py"}
]
}
]
}
}
Before you use this
A hook runs with your local shell's permissions — review the script above before adding it, the same way you'd review any script you didn't write yourself. See our guide on hook security risks for the specific CVEs this category of feature has already produced.
Related hooks