Why Soft Prompt Caps Fail Under Retry Spirals
Telling an autonomous coding agent "be concise and stay within budget" inside CLAUDE.md fails the moment a test suite enters an infinite fix-fail loop. Each retry re-sends the growing conversation history, turning a $2 task into a $500+ API bill overnight.
Benni-OS/claude-code-finops solves this outside the prompt layer with a zero-dependency Python gate bound to PreToolUse and PostToolUse.
How the FinOps Circuit Breaker Works
- Real-Time Token & USD Accounting:
PostToolUselogs model usage (claude-opus-4,claude-sonnet-4,claude-haiku-4) into an append-only SHA-256 chained ledger (.claude/finops/finops_ledger.jsonl). - Hard Dollar Ceiling: Before any tool executes,
PreToolUsechecks cumulative spend against--cap-usd. Once reached, exit code2blocks execution deterministically. - Identical-Call Loop Detection: Each tool call is hashed into a signature. If the agent repeats the exact same failing call
Ntimes consecutively, the breaker halts the spiral immediately.
git clone https://github.com/Benni-OS/claude-code-finops.git
cd claude-code-finops
pip install -e .
python -m unittest discover -s tests -p "test_*.py" -v
Launch the Benni Master OS v10 Sandbox
Verify 38 canonical skills, 8 deterministic packs, and Reality Lock invariants live in your browser, or contact bennialencar@gmail.com for B2B pilots.