Stop $500+ Runaway Claude Code Loops With a Zero-Dependency PreToolUse FinOps Circuit Breaker

Autonomous coding agents fail silently in two ways: corrupted code and runaway token burn. Here is how Benni-OS/claude-code-finops binds a hard USD circuit breaker and loop detector directly to Claude Code PreToolUse hooks.

Stop $500+ Runaway Claude Code Loops With a Zero-Dependency PreToolUse FinOps Circuit Breaker

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

  1. Real-Time Token & USD Accounting: PostToolUse logs model usage (claude-opus-4, claude-sonnet-4, claude-haiku-4) into an append-only SHA-256 chained ledger (.claude/finops/finops_ledger.jsonl).
  2. Hard Dollar Ceiling: Before any tool executes, PreToolUse checks cumulative spend against --cap-usd. Once reached, exit code 2 blocks execution deterministically.
  3. Identical-Call Loop Detection: Each tool call is hashed into a signature. If the agent repeats the exact same failing call N times 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
Production Shortcut: Need pre-built enterprise security rules alongside FinOps caps? Grab the Sovereign Policy & Red-Team Pro Pack ($49) or book a 48h team security & FinOps audit via bennialencar@benni-os.net.

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.

Open Live Sandbox →

Frequently Asked Questions

Does claude-code-finops require external databases or cloud proxies?
No. It runs on pure Python standard library with an append-only SHA-256 chained JSONL ledger in under 1 millisecond.
Can teams combine claude-code-finops with security guardrails?
Yes. You can pair it with Benni-OS/claude-code-sovereign or drop in the Sovereign Policy & Red-Team Pro Pack for OWASP LLM and infrastructure protection.