A hard, real-time dollar cap on Claude Code sessions — so a runaway agent can't burn an unexpected bill.
$ npm install -g agentcap
Developers running autonomous coding agents (Claude Code, Codex, custom agent loops) have no way to cap spend per-session or per-task in real time — only account-wide limits exist today. Multiple independent developers have posted real losses ($32 to $2,847) from runaway/looping agents in the last few months, and at least a dozen scrappy, low-traction open-source tools have been built to solve this same narrow problem — evidence of real, current, unmet pain with no dominant solution yet.
A desktop notification and a terminal warning, while there's still room to steer.
The agent process is terminated. Tool calls are denied the instant the cap trips, so it can't fire one more on its way out.
Every session is written to a local SQLite file you own. Check it any time with agentcap status.
Real notifications from real sessions: one at 80%, one when the cap stops the agent.
A cap is required. There is no implicit default, because an unbounded session is the exact thing this tool exists to prevent.
npm install -g agentcap
npx agentcap run --cap 5.00 -- claude
agentcap: command not found after installing
This almost always means npm's global bin directory isn't on your shell's PATH. It's common with nvm, whose setup usually lives in .zshrc — so if your login shell is bash (or you have no bash dotfiles), the shell never loads nvm and never sees agentcap, npm, or even node.
Check where npm installed it and whether your shell can see that directory:
npm prefix -g # npm's global bin lives in <prefix>/bin
echo $PATH
The most reliable fix is a small launcher in a directory that's always on PATH, which calls node by absolute path instead of relying on #!/usr/bin/env node:
printf '#!/bin/sh\nexec "%s" "%s" "$@"\n' "$(command -v node)" "$(npm prefix -g)/lib/node_modules/agentcap/bin/agentcap.js" \ > /usr/local/bin/agentcap && chmod +x /usr/local/bin/agentcap
AgentCap also resolves the agent binary the same way — it checks ~/.local/bin, ~/bin, ~/.claude/local, /usr/local/bin, and /opt/homebrew/bin before giving up, so -- claude keeps working even when Claude Code isn't on your PATH.
# Wrap a normal interactive Claude Code session with a $5 cap agentcap run --cap 5.00 -- claude # `claude` is the default, so this is the same thing agentcap run --cap 5.00 # Any Claude Code flags pass straight through agentcap run --cap 10 -- claude --model opus --resume # What have I spent today? agentcap status
agentcap status 2026-08-23 STARTED SPEND CAP STATUS PROJECT 09:14 $1.82 $5.00 done ~/code/api 11:02 $5.01 $5.00 capped ~/code/webapp today $6.83 across 2 sessions
Claude Code's hook payloads contain no token or cost data — that was the first thing we checked,
across all 31 hook events. What every hook payload does contain is
transcript_path, and Claude Code's own transcript records the full
Anthropic usage object and model for every request it makes.
Hooks are injected via claude --settings '<json>', which merges with
your existing config. AgentCap never writes to ~/.claude/settings.json or
your project's .claude/settings.json, so there is nothing to clean up and
nothing to corrupt if it dies unexpectedly.
Claude Code writes one JSONL line per content block, each repeating the same usage object. Summing naively over-counted a real 10 MB transcript by 2.3× — which would make the hard stop fire less than halfway to your actual cap.
5-minute writes cost 1.25× base input; 1-hour writes cost 2×. Claude Code leans heavily on 1-hour caching, so collapsing the two under-counts the single largest line item in a long session. AgentCap reads the TTL split separately.
A session it cannot measure is a session it cannot cap, and it says so rather than sitting there looking reassuring.
Enter your personal email, and we'll send you the GitHub link. We'll also write when a new version ships.
Note: For individuals only
Source-available and entirely local. No account, no signup, no telemetry, no network calls.
Company and team use needs a commercial licence.
Tell us about your company and we'll reply with pricing.