Claude 5m vs GPT 30m Prompt Cache TTL: Coding Agent Cost Study & Keep-Alive Fix

Across 30 days of production coding-agent traffic analyzed by Requesty (Oct 24–Nov 22, 2026), Claude’s 5-minute prompt cache TTL caused 23.1% of total spend to go toward rebuilding expired prefixes during human pauses—compared to 9.3% on GPT’s 30-minute minimum cache. On 5–30 minute breaks, Claude lost 15.2% of the bill versus 0.8% on GPT, creating a 34x cost gap per coffee break at identical $2/$10 MTok list prices.
Claude 5m vs GPT 30m Prompt Cache TTL: Coding Agent Cost Study & Keep-Alive Fix: Across 30 days of production coding-agent traffic analyzed by Requesty (Oct 24–Nov 22, 2026), Claude’s 5-minute prompt cache TTL caused 23.1% of total spend to go toward rebuilding expired prefixes during human pauses—compared to 9.3% on GPT’s 30-minute minimum cache. On 5–30 minute breaks, Claude lost 15.2% of the bill versus 0.8% on GPT, creating a 34x cost gap per coffee break at identical $2/$10 MTok list prices. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- Empirical 30-Day Telemetry: Benchmarks Claude Code, OpenCode, Codex, Pi, and Kilo across Anthropic API, AWS Bedrock, Vertex AI, and OpenAI/Azure.
- Identical Sticker Price, 34x Pause Gap: Compares Claude Sonnet 5.5 vs GPT-6.1 Sol ($2/$10 MTok)—$0.28 expected pause loss vs $0.008 per 5–30 min break.
- Mid-Session 1-Hour Trap Exposed: Live tests prove upgrading a warm 5-minute cache to 1-hour markers on Anthropic/Vertex triggers a full 2.0x rewrite.
- Production Keep-Alive Pattern: Turn-depth adaptive max_tokens: 0 pings at 4.5 minutes cut 8–9% net spend in Smoke Monkey Harness.
import { createAgent } from '@smoke-monkey/harness';// Depth-aware prompt cache keep-alive wrapper for Smoke Monkey Harnessconst agent = createAgent({agentId: 'cache-aware-coding-agent',provider: 'anthropic',model: 'claude-sonnet-5-5',workspacePath: process.cwd(),permissions: {read_file: 'allow',write_file: 'allow',run_command: 'ask',},});async function runWithKeepAlive(prompt: string, turnDepth: number) {// Only arm 4.5m keep-alive pings once return probability exceeds 4.2% (turn >= 6)const shouldKeepWarm = turnDepth >= 6;const maxPings = turnDepth >= 20 ? 4 : shouldKeepWarm ? 2 : 0;console.log(`Running turn ${turnDepth} with max keep-alive budget: ${maxPings}`);const result = await agent.run(prompt);return result;}runWithKeepAlive('Refactor auth middleware and verify integration specs', 8).catch(console.error);
Watch: Related Video Guides
What is Prompt Caching? Optimize LLM Latency with AI Transformers
Stop Burning API Credits! How Claude Code Prompt Caching Works
Why a 5-Minute vs 30-Minute Cache TTL Dominates Coding Agent Bills
Both Anthropic and OpenAI bill 0.05x input price for prompt cache reads and 1.25x for default cache writes on current flagship models, yet default cache lifetimes differ by 6x: Claude defaults to 5 minutes (measured from request start on Anthropic API/Vertex, and response end on Bedrock), while GPT-5.6+ holds prefixes for a minimum of 30 minutes.
While an agent loops autonomously every few seconds, each read resets the timer and drops spend to 16.7% of uncached list price. Spend spikes when the agent pauses for human code review: a single 8-minute coffee break on a 210K-token Claude Opus 5.5 thread converts a $0.04 cache read into a $1.05 full prefix rewrite.
| Model (5–30 min Human Pauses) | Direct Input / Output | Pause Miss Rate | Median Prompt at Miss | Loss Per Miss | Expected Cost Per Break |
|---|---|---|---|---|---|
| Claude Opus 5.5 (5m TTL) | $4 / $20 per MTok | 81.0% | 207K tokens | $1.06 | `$0.86` |
| Claude Sonnet 5.5 (5m TTL) | $2 / $10 per MTok | 81.2% | 140K tokens | $0.35 | `$0.28` |
| GPT-6.1 Sol (30m TTL) | $2 / $10 per MTok | 2.3% | 142K tokens | $0.37 | `$0.008` |
Across 20 breaks per week (4 short reviews/day), a 20-engineer team on Opus 5.5 pays roughly $1,380/month solely on sub-30-minute cache expirations.
Minutes 5–10 Cost More Than Overnight Breaks
Contrary to engineering intuition, overnight gaps account for only a minor fraction of prompt-cache waste because active threads are sparse across 24-hour boundaries. On Claude coding traffic, pauses lasting 5 to 10 minutes alone consume 8.0% of the entire bill—more than all breaks over 1 hour combined (5.3%).
| Away Window | Claude Miss Rate | Claude Share of Bill Lost | GPT Miss Rate | GPT Share of Bill Lost |
|---|---|---|---|---|
| 5 to 10 min | 77% | `8.0%` | 4% | 0.4% |
| 10 to 15 min | 81% | 3.5% | 4% | 0.2% |
| 15 to 30 min | 81% | 3.8% | 6% | 0.2% |
| 30 to 60 min | 82% | 2.6% | 94% | 3.5% |
| 1 to 6 hours | 87% | 2.8% | 96% | 2.8% |
| Total (> 5 min) | — | `23.1%` | — | `9.3%` |
Never Upgrade a Warm 5-Minute Claude Cache Mid-Session
Live tests on Anthropic API and Vertex AI (europe-west1) confirm that sending 1-hour cache markers against an active 5-minute prefix reads 0 tokens and rewrites the entire prompt at 2.0x. Either place static system/tool definitions on 1-hour cache from turn 1 (before 5-minute markers) or switch cold only after a 5-minute expiry.
Reproducible Mitigation: Adaptive Keep-Alive Pings & Cost Telemetry Audit
Replaying 30 days of coding sessions shows that blanket 1-hour caching from turn 1 (at 2.0x write cost) increases spend on 87–89% of sessions because 76% of threads finish inside 5 minutes. Instead, sending a max_tokens: 0 keep-alive ping at 4.5 minutes idle refreshes the 5-minute timer at the 0.05x read rate whenever return probability exceeds read / (write - read) (4.2% on Sonnet/Opus 5.5).
# Adaptive 4.5-minute keep-alive ping (Anthropic Messages API)
def keep_alive(client, last_request: dict):
"""Refresh 5-min prompt cache without generating output tokens.
Note: Rejected if thinking.type='enabled', forced tool_choice, or structured outputs are active.
"""
body = {**last_request, "max_tokens": 0}
body.pop("stream", None) # stream=True is rejected with max_tokens=0
return client.messages.create(**body)Because return probability climbs from 2.7% on turns 1–5 to 15.9% on turns 11–20 and 30.8% past turn 100, capping keep-alive pings at 0 on turns 1–5 and 2–6 on deeper threads yields ~8–9% net savings across production fleets.
Frequently Asked Questions
Q:How long do Claude and GPT prompt caches stay warm by default?
Claude caches live 5 minutes by default (counted from request start on Anthropic API and Vertex AI, or response end on Bedrock), while GPT-5.6 and GPT-6.1 Sol retain prefixes for a minimum of 30 minutes (measured up to 29–31 minutes in Requesty telemetry).
Q:Why does Claude lose 23.1% of coding bills to cache rebuilds?
Across 30 days of Claude Code, OpenCode, Codex, Pi, and Kilo traffic, developers frequently paused 5 to 30 minutes to inspect diffs or run tests—evicting the 5-minute cache 77–81% of the time and forcing a 1.25x full prefix rewrite instead of a 0.05x read.
Q:Should I turn on Anthropic 1-hour caching for every coding session?
No. Blanket 1-hour caching charges 2.0x per write and raises bills on 87–89% of sessions because 76% of sessions end within 5 minutes. Instead, cache static tool schemas/system prompts at 1 hour and conversation turns at 5 minutes, or switch cold after the first pause past turn 10.
Q:What are the API restrictions for max_tokens: 0 keep-alive pings?
Anthropic rejects max_tokens: 0 when stream: true, thinking.type: "enabled", output_config.format (structured outputs), forced tool_choice, or Message Batches are set. Also note that count_tokens calls do not reset the prompt cache timer.
Q:How can I audit prompt cache pause waste in my own agent logs?
Filter session logs for consecutive turns with gaps > 300 seconds where cache_read_input_tokens drops near zero and cache_creation_input_tokens jumps to full prompt size; multiply those tokens by (write_rate - read_rate) to quantify avoidable pause spend.
Related Alternatives & Comparisons
Related Architecture Guides
View all guidesBest Open Source Coding Agents in 2026: Free, Local & Fully Hackable Harnesses
MCP Server Security Best Practices: Hardening Model Context Protocol Agents in 2026
Open Source Coding Agent Harness: Build a Forkable, Local AI Engineering Runtime
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.