[BUG] ENABLE_PROMPT_CACHING_1H_BEDROCK does not apply 1h TTL to subagent requests
Summary
The undocumented ENABLE_PROMPT_CACHING_1H_BEDROCK=1 environment variable correctly applies 1-hour prompt cache TTL to main thread (Opus) requests, but does not propagate to subagent (Sonnet) requests. Subagents still use the default 5-minute TTL.
Evidence
Using a local intercepting proxy that distinguishes native 1h TTL from proxy-upgraded TTL:
Main thread (Opus) — 1h TTL works natively:
[#8] model=claude-opus-4-6-v1 | cache: 1bp(tools,1h,pre=3,native=3)
native=3 means CC sent 3 breakpoints with ttl: "1h" — no proxy upgrade needed.
Subagent (Sonnet) — 1h TTL NOT applied:
[#16] model=claude-sonnet-4-6 | cache: 2bp(tools+msgs,1h,pre=2,upg=2)
upg=2 means CC sent 2 breakpoints without ttl: "1h" — proxy had to upgrade them.
Root Cause (from binary analysis)
The erK() function that decides whether to use 1h TTL correctly checks ENABLE_PROMPT_CACHING_1H_BEDROCK:
function erK(querySource) {
if (F8() === "bedrock" && n_(process.env.ENABLE_PROMPT_CACHING_1H_BEDROCK))
return true;
// ...
}
However, the subagent code path uses enablePromptCaching: K.enablePromptCaching ?? false and appears to construct cache_control markers through a different code path that doesn't call erK() / dQ() with the correct context, so the 1h TTL condition is never evaluated for subagent requests.
Cost Impact
Subagent requests are frequent in agentic sessions (tool search, explore agents, etc.). With 5-minute TTL, subagent cache expires quickly, causing repeated full cache rewrites at 1.25x input token cost instead of 0.1x cache read cost with 1h TTL.
For a typical session with ~50 subagent requests and ~70k cached tokens per request:
- 5m TTL: ~10 cache rewrites × 70k × $3.75/M (Sonnet write) = $2.63 in rewrites
- 1h TTL: ~1 write + 49 reads × 70k × $0.30/M (Sonnet read) = $1.03 in reads
Expected Behavior
When ENABLE_PROMPT_CACHING_1H_BEDROCK=1 is set, all requests to Bedrock should use 1h TTL, including subagent requests.
Environment
- Claude Code: v2.1.79 (Homebrew)
- Provider: AWS Bedrock (
ap-northeast-1) - Models: Opus 4.6 (main thread), Sonnet 4.6 (subagent)
CLAUDE_CODE_USE_BEDROCK=1ENABLE_PROMPT_CACHING_1H_BEDROCK=1
Related Issues
- #2603 — Original feature request for 1h cache support
- #29966 — Agent SDK subagents have prompt caching disabled by default
- #32102 — SDK consumers cannot control prompt cache segmentation
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗