How a $1,100 Runaway Claude Session Made Me Build AI Cost Guardrails
$1,100 gone in one afternoon. A single Claude Code agent deleted a config file, tried to fix it, couldn't, and spiraled into hundreds of retry attempts. Nobody was watching. By the time I checked, the damage was done.
This is the story of the most expensive bug I never wrote. And the guardrails system I built to make sure it never happens again.
What Happened
I had a Claude Code agent running a routine cleanup task on our field service system. Simple stuff — reorganize some config files, update some paths. Should have taken 5 minutes.
The agent accidentally deleted a critical config file. Then it tried to recreate it. The recreation failed because of a permissions issue. So it tried again. And again. And again. Each attempt spawned more tool calls, read more context, and burned more tokens.
By the time I noticed, the agent had made over 400 tool calls in a single session. The context window was maxed out. The bill was $1,100.
The 3 Deadly Patterns
After analyzing what went wrong, I identified three patterns that cause runaway AI costs. Every expensive incident I've seen (mine and others') falls into one of these:
Pattern 1: Memory Leak
The agent reads entire codebases or directories without filtering. Each read adds thousands of tokens to the context. The context window fills up, responses get slower, and every subsequent operation costs more because the full context is sent with every request.
Symptom: Context usage climbing rapidly without meaningful progress.
Fix: Limit file reads to specific paths. Never cat an entire directory.
Pattern 2: Retry Loop
This is what killed me. The agent hits an error, retries the same operation, hits the same error, retries again. It's the AI equivalent of clicking a broken button 400 times.
Symptom: Same tool call appearing repeatedly in logs.
Fix: Max 3 consecutive retries on any operation. After 3 failures, stop and report.
Pattern 3: Tool Cascade
The agent makes dozens of tool calls with zero meaningful progress. It's exploring, reading, listing, checking — doing "work" without accomplishing anything. Each tool call costs tokens.
Symptom: High tool call count with no deliverables.
Fix: Max 50 tool calls per operation. Circuit breaker kills the session if exceeded.
The Guardrails Config
Here's the exact config we now run in production:
{
"daily_limit_usd": 50,
"session_limit_usd": 10,
"max_consecutive_retries": 3,
"max_tool_calls_per_operation": 50,
"context_warning_tokens": 150000,
"context_hard_stop_tokens": 180000,
"circuit_breaker": true,
"alert_on_breach": true
}
How it works:
- $50/day limit — Total spend across all sessions. Resets at midnight.
- $10/session limit — No single session can burn more than $10.
- 3 retry max — After 3 consecutive failures on the same operation, the agent stops and reports.
- 50 tool calls max — If an agent makes 50 tool calls without completing its task, something is wrong. Circuit breaker kills it.
- Context warnings — At 150K tokens, the agent gets a warning. At 180K, it's forced to summarize and compress.
How to Set Your Limits
Your limits depend on how you use AI:
- Light usage (solo, occasional): $25/day, $5/session
- Moderate (daily use, small team): $50/day, $10/session
- Heavy (production systems, multiple agents): $75/day, $15/session
- Enterprise (large team, critical systems): $100/day, $25/session
Start conservative. You can always raise limits. You can't un-spend $1,100.
Get the complete guardrails system
The AI Workspace Blueprint includes the full guardrails config, circuit breakers, cost logger, and session management. Plus Claude interviews you and builds your entire workspace personalized to your business.
Get the AI Workspace Blueprint — $149 →More resources at darklineaisystems.com