Agent Loop Runaway Cost Calculator
Autonomous coding and research agents suffer from quadratic context growth because every tool call appends logs that get re-read on all future steps. Adjust the loop parameters below to see how fast an uncapped retry spiral burns through your API budget.
Interactive calculator
| Run Scenario | Steps Executed | Total Input Tokens | Run Cost | 20 Runs / Month |
|---|
Frequently asked questions
Why do agent loop costs grow quadratically?
Because LLMs are stateless. On step 1 you send 20K tokens; on step 40 you send 20K plus all 39 prior tool outputs, causing total billed input tokens to scale with the square of step count.
Can prompt instructions alone stop a runaway coding agent?
No. Soft instructions inside a prompt can be ignored when context fills up. Only an external hook or gateway process like cost_guard.py can enforce a non-bypassable dollar ceiling.
What is a safe per-session dollar cap for Claude Code?
For interactive feature work on Sonnet 4, $3 to $6 per session catches stuck loops early while allowing 40 to 70 productive turns with prompt caching enabled.
All calculations run 100% locally in your browser with zero external API calls. Pricing and rate limits reflect published 2026 provider rate cards.