Long-running autonomous agents are the newest frontier in software engineering. Tools like Claude Code, Cursor, and terminal agents can be assigned an issue at 6 PM and left to explore codebases, run test suites, and draft pull requests overnight. But giving an autonomous system the power to invoke frontier APIs in a continuous loop carries unprecedented financial and operational risks.
The reality of enterprise agent spend: Ramp data
When Anthropic introduced Claude Fable 5.1 at $10.00 input and $50.00 output per million tokens, many expected it to become the universal agent driver. However, analysis of spending data across 70,000 companies from corporate card provider Ramp reveals a stark reality: Fable 5 carries approximately 6% of tokens and 11% of company spending on Anthropic APIs. Claude Opus 5.5 ($4/$20) and Sonnet 5.5 ($2/$10) carry the overwhelming majority of production volume.
Quadratic token growth and prompt caching
In a multi-turn agent session, each new prompt re-sends the cumulative history: file contents, bash tool outputs, lint errors, and previous reasoning. Over a 30-turn session, an agent that reads 20,000 tokens of code on turn 1 will process over 600,000 cumulative input tokens by turn 30.
| Model | Input / 1M | Output / 1M | Cache Read / 1M | Total Session Cost |
|---|---|---|---|---|
| Claude Fable 5.1 | $10.00 | $50.00 | $0.25 | $4.85 |
| Claude Opus 5.5 | $4.00 | $20.00 | $0.20 | $1.94 |
| Claude Sonnet 5.5 | $2.00 | $10.00 | $0.10 | $0.97 |
| Uncached Fable 5.1 (Worst Case) | $10.00 | $50.00 | N/A | $15.50 |
Sizing max_tokens and effort headroom
Under adaptive thinking, thinking tokens count against max_tokens alongside visible output. If an agent task requires 1,500 tokens of code output and the model expends 2,500 tokens exploring alternatives in its internal reasoning trace, setting max_tokens to 3,000 will cause the request to truncate halfway through the code block. Always size max_tokens with at least 4,000 to 8,000 tokens of headroom on complex agent turns.
<agent_task>
<goal>{{HIGH_LEVEL_GOAL}}</goal>
<budget>
Max turns: 20
Max session spend: $5.00
Preferred model: claude-sonnet-5-5 (escalate to claude-fable-5-1 only on 2 consecutive test failures)
</budget>
<stop_conditions>
- Stop immediately if test suite passes.
- Stop and request human guidance if blocked by missing environment secrets.
</stop_conditions>
</agent_task>Clear stop conditions and hard turn ceilings prevent runaway retry loops when an agent encounters missing dependencies.
Deterministic governance with SDK hooks
Never rely on the LLM to police its own spending or permissions. Implement host-side pre-execution hooks in your agent runtime. These hooks inspect tool call names and arguments before execution, intercepting destructive shell commands (like git reset --hard or rm -rf) and enforcing hard session spend ceilings at the network boundary.
Frequently asked questions
How does prompt caching protect multi-turn agent sessions?
Prompt caching serves previously sent conversation history and file buffers at up to 90% discount ($0.10–$0.25/1M vs $2.00–$10.00/1M), preventing linear context growth from causing exponential cost curves.
When should an agent escalate from Sonnet 5.5 to Fable 5.1?
Use Sonnet 5.5 for initial code exploration, test running, and straightforward edits. Escalate to Fable 5.1 or Opus 5.5 when an agent encounters elusive architectural bugs, complex concurrency races, or unresolvable test regressions.
Why do thinking tokens count toward output billing?
Providers generate thinking tokens dynamically during autoregressive decoding on GPU compute, billing them at output rates ($10–$50/1M depending on model tier).
What is the most common cause of runaway agent expenses?
Unbounded retry loops on failing tests where the agent repeatedly re-reads large files without a hard turn ceiling or spending circuit-breaker.
Synthesized from Claude Code documentation, enterprise Ramp spending studies, and TokenCalc AI live catalog pricing.