Bedrock: Prompt caching TTL hardcoded to 5m, no way to configure 1h
Summary
When using Claude Code with AWS Bedrock, prompt caching breakpoints (cache_control) are always injected with the default 5-minute TTL. Bedrock supports 1-hour TTL (ephemeral with ttl: "1h"), which is significantly more cost-effective for long development sessions. There is no user-facing configuration to switch to 1h TTL.
Problem
A typical Claude Code development session lasts 1-4 hours. With a 5-minute TTL, the prompt cache expires frequently, causing full cache rewrites on every expiration:
# After 5m TTL expires — full cache rewrite (~$1.14 for 61k tokens):
[#11] cache: read=0 write=61149 ← cache miss, full rewrite
# With 1h TTL — subsequent requests hit cache:
[#14] cache: read=61149 write=246 ← cache hit, minimal write
Over a session with 100+ requests, the cost difference between 5m and 1h TTL is substantial — cache rewrites at $9.375/M tokens (Opus) vs cache reads at $0.9375/M tokens (10x cheaper).
Evidence from Proxy Logs
Using a local intercepting proxy, I can see CC sends cache_control with no ttl field (defaults to 5m). After the proxy upgrades them to 1h:
# Proxy upgrades existing breakpoints from 5m to 1h:
[#76] thinking: effort->max (was high) | cache: 1bp(tools,1h,pre=3,upg=3)
[#76] cache-extract: message_start cr=56700 cw=696 inp=1 [5m=0,1h=696]
[#76] cache: read=56700 write=696 uncached=1
# Consistent 1h cache hits across the session:
[#78] cache: read=46842 write=124 uncached=1
[#79] cache: read=46966 write=10 uncached=295
[#84] cache: read=57396 write=1969 uncached=1
[#89] cache: read=59365 write=631 uncached=1
Internal Code Reference
The CLI bundle contains an internal env var ENABLE_PROMPT_CACHING_1H_BEDROCK and associated logic for 1h TTL, but:
- It is not documented anywhere
- It's unclear if it works correctly in all code paths (main REPL, subagents, Agent SDK)
- There's no user-facing way to enable it
Proposed Solution
Either:
- Default to 1h TTL for Bedrock — since Bedrock sessions are long-running, 1h is a better default than 5m
- Expose an environment variable — document
ENABLE_PROMPT_CACHING_1H_BEDROCK=1or create a more generalCLAUDE_CODE_CACHE_TTL=1hsetting - Auto-detect — if the provider is Bedrock, automatically use 1h TTL
Cost Impact
For a 100-request Opus session with ~60k cached tokens per request:
- 5m TTL: ~20 cache rewrites × 60k tokens × $9.375/M = $11.25 in rewrites
- 1h TTL: ~1 cache write + 99 reads × 60k tokens × $0.9375/M = $5.57 in reads
- Savings: ~50% reduction in caching costs
Environment
- Claude Code version: 2.1.76
- Provider: AWS Bedrock (ap-northeast-1)
- Models: Opus 4.6, Sonnet 4.6
- Analysis method: Local reverse proxy intercepting and logging all API requests
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗