claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[DOCS] prompt-caching.md says subagents use the 5-minute TTL, but transcripts show 100% 1-hour cache-creation tokens

Open mariadb-KyleHutchinson opened this issue 3 months ago • 5 comments

[DOCS] prompt-caching.md says subagents use the 5-minute TTL, but transcripts show 100% 1-hour cache-creation tokens

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report
  • [x] I am using the latest version of Claude Code

What's Wrong?

The "Subagents and the cache" section of the prompt-caching docs (https://code.claude.com/docs/en/prompt-caching#subagents-and-the-cache) states:

Subagents use the five-minute TTL even on a subscription, since the automatic one-hour TTL applies to the main conversation.

This does not match what the actual API usage data in local session transcripts shows. Every response's usage.cache_creation field reports two buckets, ephemeral_1h_input_tokens and ephemeral_5m_input_tokens, which is the ground truth for which TTL a given request actually got.

I checked this across many subagent transcripts (~/.claude/projects/*/subagents/agent-*.jsonl and the equivalent nested subagent folders) spanning several different projects and sessions, all on a Claude subscription with no ENABLE_PROMPT_CACHING_1H / FORCE_PROMPT_CACHING_5M overrides set. Every single cache_creation entry checked landed entirely in ephemeral_1h_input_tokens, with ephemeral_5m_input_tokens at 0. Examples (one per file):

"cache_creation":{"ephemeral_1h_input_tokens":14705,"ephemeral_5m_input_tokens":0}
"cache_creation":{"ephemeral_1h_input_tokens":15745,"ephemeral_5m_input_tokens":0}
"cache_creation":{"ephemeral_1h_input_tokens":4364,"ephemeral_5m_input_tokens":0}
"cache_creation":{"ephemeral_1h_input_tokens":205,"ephemeral_5m_input_tokens":0}
"cache_creation":{"ephemeral_1h_input_tokens":4323,"ephemeral_5m_input_tokens":0}

I also asked a live subagent (general-purpose, spawned via the Agent tool) whether it had any visibility into its own cache TTL. It correctly reported it has no such information in its own context — so this isn't something a subagent can self-report; it has to be checked from the transcript's usage data, which is what I did.

This looks related to #54006 (closed, auto-stalled), which reported the opposite direction: subagent sessions stuck on 0% one-hour / 100% five-minute, treated as a bug because subagents were expected to get the 1-hour TTL like the parent. One commenter on that thread (oliver-kriska) found a version-correlated gradient where older Claude Code releases had much higher one-hour adoption for subagents than newer ones at the time. My data now shows 100% one-hour adoption for subagents, which is consistent with that trend continuing (or reverting) rather than subagents being hardcoded to 5m. Either way, the current docs page describing 5-minute TTL as intentional subagent behavior does not reflect what's actually happening for at least some class of subagent sessions today.

What Should Happen?

One of:

  1. If subagents are actually intended to get the 1-hour TTL when the parent session has it (which the evidence here suggests is now the real behavior), the docs page should be corrected to say so instead of asserting a hardcoded 5-minute TTL.
  2. If 5-minute TTL is still the intended behavior for some subagent types/paths and what I'm seeing is itself a bug (subagents getting 1h TTL when they shouldn't), then this needs a code-side look, and the docs are at least currently describing the intended-but-not-actual behavior.

Either way, right now the docs and the observed behavior disagree, and that should be reconciled by either fixing the docs or fixing the underlying behavior.

Error Messages/Logs

No error messages. See the cache_creation breakdown above, sourced from ~/.claude/projects/<project>/subagents/agent-*.jsonl (or ~/.claude/projects/<project>/<session-uuid>/subagents/agent-*.jsonl) transcript files.

Steps to Reproduce

  1. Use Claude Code on a Claude subscription (no ENABLE_PROMPT_CACHING_1H / FORCE_PROMPT_CACHING_5M set).
  2. Spawn any subagent via the Agent tool (or /agents) that does enough work to produce more than one API turn.
  3. Locate the subagent's transcript file under ~/.claude/projects/<project>/.../subagents/agent-*.jsonl.
  4. grep -oE '"cache_creation":\{[^}]*\}' <file> | sort -u
  5. Observe ephemeral_1h_input_tokens populated and ephemeral_5m_input_tokens at 0, contradicting the docs' claim that subagents always use the 5-minute TTL.

Claude Code Version

2.1.222

Platform

Claude subscription (not API key / Bedrock / Foundry)

Is this a regression?

Unclear — possibly related to the version-correlated trend noted in #54006's discussion, but in the opposite direction (higher, not lower, one-hour adoption than the docs describe).

mariadb-KyleHutchinson avatar Aug 05 '26 20:08 mariadb-KyleHutchinson

Thanks for the careful measurement. Claude Code itself requests the five-minute TTL for subagent requests on a subscription, which is what the docs sentence describes; the one-hour cache-creation buckets you're seeing in subagent transcripts indicate the effective TTL is being decided further along the pipeline. We're checking with the team that owns that behavior and will update the prompt-caching page (https://code.claude.com/docs/en/prompt-caching) so it describes what actually happens. Leaving open as a docs item.

🤖 Generated with Claude Code

bcherny avatar Aug 16 '26 22:08 bcherny

it would be nice if the users could gain some control on the pick of 5m vs 1h. There are genuine applications that would benefit greatly.

NubeBuster avatar Aug 22 '26 04:08 NubeBuster

Data point that partly contradicts the "transcripts show 100% 1-hour" observation: on Claude Code 2.1.258 with claude-fable-5-1 subagents (Max 20x subscription, macOS, no ENABLE_PROMPT_CACHING_1H / FORCE_PROMPT_CACHING_5M overrides), every subagent cache write I checked lands in the 5-minute bucket, and it costs a full re-cache on turns longer than the TTL.

From ~/.claude/projects/**/agent-*.jsonl, usage deduped by message.id, one session on 2026-09-03 with 8 parallel research subagents:

time (UTC) agent call # cache_creation cache_read bucket gap since previous response
16:03:25 a629058a 14 431,885 33,578 ephemeral_5m 5.7 min
16:04:47 a96ab1d3 8 270,587 33,578 ephemeral_5m 6.0 min
16:08:31 a9a4add8 10 271,077 33,578 ephemeral_5m 8.8 min
16:13:56 a9cd220c 13 303,392 33,578 ephemeral_5m 10.1 min

10 such rewrites (2.88M cache-write tokens) in under 40 minutes; 33,578 is exactly the shared system prefix, i.e. only the prefix survives. Same week, same machine: 0 full-context rewrites across 1,720 claude-opus-5 subagent calls and 179 claude-fable-5 subagent calls, so the 5m bucket only becomes a problem once the model's turns routinely exceed 5 minutes, which Fable 5.1's do.

So the docs sentence is right for my transcripts, and the request in the comment above (let users pick 5m vs 1h for subagents, or give subscription subagents the 1h TTL like the main conversation) would directly fix a real cost problem. Full write-up with request IDs and the cross-model comparison in #92090.

lucascampolina avatar Sep 04 '26 13:09 lucascampolina

Another data point on the docs side, matching @lucascampolina rather than the original observation — Windows, Claude subscription, no TTL overrides, Claude Code 2.1.156 → 2.1.272, 674 sessions, usage deduplicated by message.id:

  • Subagent transcripts (subagents/agent-*.jsonl): 92,525 cache writes, 100% in ephemeral_5m_input_tokens, across every version in the range.
  • Main thread in the same sessions: 159,724 writes, 100% 1h (16 exceptions in one session).

On whether the 5m subagent default is the wrong one: in this corpus subagent gaps of ≥ 5 min between consecutive calls do break the cache 81–100% of the time, but there are only ~390 such gaps in total. Pricing the alternative, forcing 1h on every subagent write (2× write premium) would cost 372M → 496M input-token-equivalents to save those ~390 re-writes — a net loss here. It only flips for workloads like the Fable 5.1 case above, where single turns routinely exceed 5 min; that argues for the per-user subagentPromptCacheTtl knob (shipped in 2.1.242+), not for changing the default.

Scripts and numbers: https://github.com/edubraqd/claude-context-forensics (tools/ttl.py, report/findings.md).

edubraqd avatar Sep 15 '26 15:09 edubraqd

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Nov 22 '26 22:11 github-actions[bot]