Home › Products › Agent Spend Guard
Agent Spend Guard
Stop runaway Claude Code and Cursor agents: subagent fan-out, nested agents, retry loops and blown token budgets.
In October 2026 developers reported weekly limits draining in hours, an orchestrator that ignored its limit of 6 agents and ran about 16, and a Cursor CLI call that spawned agents recursively: about 318M tokens in 33 minutes.
Agent Spend Guard enforces limits while the agent works: a cap on subagents at once and per session, a block on agents launched from the shell (claude -p, cursor-agent, codex exec…), a stop on the same failing command or repeated call, and a per-session token budget that warns at 80% and stops at 100%.
A usage report shows where your tokens went by day, session, subagent and model, with SPIKE, FAN-OUT, LOOP and UNATTENDED flags. Python standard library only, runs locally, about 25 ms per hook.
What's in the download
- guard/spend_guard.py and guard/policy.json: one hook for Claude Code and Cursor
- install/install.py: one-command install per project, keeps your settings, --uninstall
- tools/usage_report.py: where did my tokens go, with flags and a suggested budget
- skills/agent-spend-discipline/SKILL.md
- README, tests/, TEST-REPORT.md, LICENSE.txt, REFUND.txt
Who it's for
Developers on Claude Code or Cursor plans who have watched a weekly limit drain in hours, or who let agents run unattended or start subagents.
What's tested
- 49/49 automated tests: 27 guard, 8 installer, 6 usage report, 2 skill
- 6 of the 49 run the hooks inside the real Claude Code CLI, with the model replaced by a local mock (no Anthropic account or paid calls used)
- The guard runs as a separate process fed hook JSON in Claude Code's and Cursor's documented formats; median 25 ms per hook call
What isn't tested
- No live Cursor agent run: Cursor hook formats come from Cursor's docs
- Not tested on Windows or macOS (Windows paths are unit-tested only)
- The usage report's weighted tokens are a relative measure, not Anthropic's or Cursor's plan meter; the guard can't change how your plan is metered
Requirements
Python 3.9+ (tested on 3.13). Claude Code and/or Cursor with hooks. In Cursor only the nested-agent and repeat-call rules apply (this version uses Cursor's shell and MCP hooks only).
How to use it
Run python3 install/install.py --project /path/to/repo, restart Claude Code or reload Cursor, and edit guard/policy.json to set your limits. Run tools/usage_report.py to see past usage.
Agent Spend Guard · Instant download · 30-day refund · Licence