Expose extended (1h) prompt-cache TTL for interactive sessions

Status Fixed / completed
Maintainer reply ✓ Yes — bcherny
Activity 5 comments · opened Jul 4, 2026 · closed Aug 17, 2026
💡 Likely answer: A maintainer (bcherny, collaborator) responded on this thread — see the highlighted reply below.

Problem

The Anthropic API's prompt cache defaults to a 5-minute TTL. In interactive Claude Code sessions, the human reply gap routinely exceeds that: measured across 1,967 reply times in one power user's session telemetry, 27% of replies landed after the 5-minute window and 10% after 15 minutes. Each late reply forces a cold re-read of the entire conversation context (often hundreds of KB in long sessions), paying full input cost and latency for content that was cached moments earlier.

Users can't reasonably be expected to watch a cache clock while thinking, reviewing diffs, or juggling parallel sessions — and the UI surfaces no signal about when the window lapses.

Ask

The API already supports cache_control: {type: "ephemeral", ttl: "1h"} (2x write cost, ~0.1x reads, break-even at ~3 requests). Expose it in Claude Code, any of:

  1. A setting (cacheTtl: "1h" in settings.json) or env var, or
  2. Automatic: use the 1h TTL for interactive sessions (or adaptively, when the user's recent reply gaps exceed the 5-minute window), keeping 5m for headless/scripted runs.

For long interactive sessions the economics clearly favor 1h: one 2x write amortizes across every turn of an afternoon session, versus repeated full-price cold re-reads.

Workaround today

None exposed. Users can only restructure their workflow (fewer, longer autonomous runs; checkpoint files + fresh short sessions instead of resuming stale transcripts), which helps but shouldn't be required to avoid a silent 10x cost cliff on a reply that took six minutes instead of four.

View original on GitHub ↗

4 Comments

dixit-ty-chetan · 2 months ago

Environment Details

  • Provider: AWS Bedrock (Company Managed)
  • Model: Claude 4.6 Sonnet (1M Context)
  • Tool: Claude Code CLI

Problem Statement

The current prompt cache TTL is fixed at 5 minutes on the AWS Bedrock backend gateway. For long single-task developer sessions (e.g., a full day of mobile automation development on a single ticket), this means any gap longer than 5 minutes results in a full cache miss and full input token billing—with no way to prevent it.

This is especially painful when:

  • Using the 1M context window model: Leads to extremely high per-token compounding costs.
  • Working on manual human decision points: Approvals, manual mobile testing, and environment setup naturally exceed 5 minutes.
  • Continuous single workflows: The task cannot be split into parallel, independent terminal sessions without losing critical conversational context.

Current Behavior

Cache TTL = 5 minutes, hardcoded. Even when using the CLI or standard env variables, Bedrock forces a 5-minute timeout on interactive sessions. Furthermore, users have no visibility into cache hit/miss rates per turn without checking /cost repeatedly.

Expected Behavior

Allow users to configure the cache TTL—up to 1 hour—specifically ensuring that the ttl parameters map correctly to the Bedrock API payload body via:

  • A Claude Code setting configuration flag (cacheTimeout: 3600)
  • A dedicated environment variable (e.g., CLAUDE_CODE_CACHE_TTL="1h")

Impact

For enterprise and professional users running day-long agentic coding sessions, a hardcoded 5-minute TTL effectively renders prompt caching useless during typical development loops.

As a concrete example, a single ticket workflow over a 24-hour wall-clock window resulted in:

  • Total Cost: $24.14 for a modest change (~500 lines)
  • Cache Writes: 2.0 million tokens
  • Cache Reads: 50.4 million tokens

Because the 5-minute TTL constantly expired during manual testing and approval pauses, the CLI was forced to repeatedly rewrite the exact same codebase context from scratch at full price. A 1-hour TTL would have kept those 2.0M tokens inside the 90% discounted "cache read" bucket, lowering the bill significantly without any architectural downsides.

<img width="687" height="126" alt="Image" src="https://github.com/user-attachments/assets/b0a4af90-fa7d-4d33-b221-b2f85cc8c237" />

Workarounds Tried

  • /compact to reduce context size — helps marginally, but the root cache invalidation remains.
  • Keeping turns frequent — not feasible during active manual testing or framework compilation.
  • Splitting into multiple sessions — defeats the purpose of an interactive, continuous coding agent.
carrotRakko · 2 months ago

This is no longer just a feature request — the 1h TTL was already in use and was silently removed in 2.1.218.

  • 2.1.215 and earlier: 1h TTL for interactive sessions (measured: 157/157 records with ephemeral_1h_input_tokens > 0)
  • 2.1.218+: 5m-only (0/347 records with any 1h cache)

The economic case you made (break-even at ~3 requests) is now a regression cost: 13.8% of total session cost across 236 sessions is attributable to the 1h→5m switch. Your "27% of replies land after the 5-minute window" stat is the user-driven half; the agentic half (test suites, subagent delegations, web fetches) makes the real-world gap frequency even higher.

Asking to "expose" the 1h TTL is right, but the more urgent ask is to restore it — it was there and was removed.

Filed as #84253.

✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)

dixit-ty-chetan · 2 months ago

Update:

ENABLE_PROMPT_CACHING_1H=1 env var works on 2.1.223 + AWS Bedrock (claude-opus-4-6).

Added to ~/.claude/settings.json:

"env": {
"ENABLE_PROMPT_CACHING_1H": "1"
}

Verified over a 58-minute session with intentional 6-14 minute idle gaps between turns:

Images -

  • <img width="694" height="149" alt="Image" src="https://github.com/user-attachments/assets/1c4096ea-ffb9-43ae-80bb-05374cfb2dd6" />
  • <img width="688" height="154" alt="Image" src="https://github.com/user-attachments/assets/3eb72014-f140-4bb9-b360-dd07a11e2dda" />
  • <img width="672" height="152" alt="Image" src="https://github.com/user-attachments/assets/78e2453e-b665-4979-993d-cf2b6d9be1cc" />

Observations -

  • Cache writes stayed flat (~402k → 403k) — no re-caching after idle gaps
  • Cache reads grew steadily (787k → 1.1m) — hitting cached prefix successfully
  • Cost per turn: ~$0.09 (consistent with cache read pricing, not full input)

Previously with 5-min TTL, any 6+ minute gap would spike cache writes and cost. This confirms the 1h TTL is active and functioning on Bedrock.

This env var was introduced in 2.1.108 (changelog) but isn't documented anywhere obvious — found it by grepping the changelog. Would still benefit from proper docs/UI exposure.

bcherny collaborator · 1 month ago

This is already available. On a Claude subscription (Pro/Max/Team/Enterprise) within included usage, Claude Code uses the 1-hour prompt-cache lifetime automatically. On an API key or a cloud provider (Bedrock, Vertex, Foundry) — or when a subscription is drawing on usage credits — set the environment variable:

ENABLE_PROMPT_CACHING_1H=1

Note that 1-hour cache writes are billed at a higher rate. Docs: https://code.claude.com/docs/en/env-vars and https://code.claude.com/docs/en/costs

Closing since this is covered today — reopen if you're seeing 5-minute expiry on a subscription.

🤖 Generated with Claude Code

Showing cached comments. Read the full discussion on GitHub ↗