claude-code - 💡(How to fix) Fix [BUG] ENABLE_PROMPT_CACHING_1H is not working (API key user) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#49139Fetched 2026-04-17 08:49:47
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×5commented ×1renamed ×1

Error Message

Error Messages/Logs

Code Example

**Request (client → server):**

POST https://api.anthropic.com/v1/messages?beta=true
anthropic-beta: claude-code-20250219,context-1m-2025-08-07,interleaved-thinking-2025-05-14,context-management-2025-06-27,prompt-caching-scope-2026-01-05,advisor-tool-2026-03-01,advanced-tool-use-2025-11-20,effort-2025-11-24,afk-mode-2026-01-31

System block cache_control: {"type":"ephemeral","ttl":"1h","scope":"global"}
Message block cache_control: {"type":"ephemeral","ttl":"1h"}


**Response (server → client):**

{
  "input_tokens": 3,
  "cache_creation_input_tokens": 7025,
  "cache_read_input_tokens": 12112,
  "cache_creation": {
    "ephemeral_5m_input_tokens": 7025,
    "ephemeral_1h_input_tokens": 0
  }
}

The server creates cache entries (7025 tokens) but places them all in the 5-minute bucket despite the client requesting 1-hour TTL.
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

The ENABLE_PROMPT_CACHING_1H environment variable (which opts into 1-hour prompt cache TTL) has no effect. Cache entries are always created with 5-minute TTL regardless of the setting.

By intercepting the raw HTTP traffic between Claude Code and the Anthropic API, I confirmed that:

  • The client correctly sends cache_control: {"type":"ephemeral","ttl":"1h","scope":"global"} on system blocks and cache_control: {"type":"ephemeral","ttl":"1h"} on message blocks
  • The anthropic-beta header includes prompt-caching-scope-2026-01-05
  • The server responds with ephemeral_5m_input_tokens: 7025, ephemeral_1h_input_tokens: 0 — all cache creation goes into the 5-minute bucket, none into the 1-hour bucket

This is reproducible on both an enterprise/organization API key and a personal API key.

What Should Happen?

When ENABLE_PROMPT_CACHING_1H=1 is set, cache entries should be created with a 1-hour TTL. The server response should show ephemeral_1h_input_tokens > 0 and ephemeral_5m_input_tokens: 0 for the cache creation.

Error Messages/Logs

**Request (client → server):**

POST https://api.anthropic.com/v1/messages?beta=true
anthropic-beta: claude-code-20250219,context-1m-2025-08-07,interleaved-thinking-2025-05-14,context-management-2025-06-27,prompt-caching-scope-2026-01-05,advisor-tool-2026-03-01,advanced-tool-use-2025-11-20,effort-2025-11-24,afk-mode-2026-01-31

System block cache_control: {"type":"ephemeral","ttl":"1h","scope":"global"}
Message block cache_control: {"type":"ephemeral","ttl":"1h"}


**Response (server → client):**

{
  "input_tokens": 3,
  "cache_creation_input_tokens": 7025,
  "cache_read_input_tokens": 12112,
  "cache_creation": {
    "ephemeral_5m_input_tokens": 7025,
    "ephemeral_1h_input_tokens": 0
  }
}

The server creates cache entries (7025 tokens) but places them all in the 5-minute bucket despite the client requesting 1-hour TTL.

Steps to Reproduce

  1. Set ENABLE_PROMPT_CACHING_1H=1 (either as environment variable or in settings.json under env)
  2. Start Claude Code
  3. Send a message
  4. Observe usage stats — ephemeral_1h_input_tokens is always 0

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.110 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Other

Additional Information

No response

extent analysis

TL;DR

The issue can be resolved by verifying the correct usage of the ENABLE_PROMPT_CACHING_1H environment variable and ensuring the Anthropic API properly handles the 1-hour TTL cache control requests.

Guidance

  • Verify that the ENABLE_PROMPT_CACHING_1H environment variable is correctly set to 1 and that the Claude Code application is properly configured to use this environment variable.
  • Check the Anthropic API documentation to ensure that the cache_control requests with a 1-hour TTL are correctly formatted and supported.
  • Test the cache creation with different TTL values to see if the issue is specific to the 1-hour TTL or if it's a more general caching problem.
  • Inspect the server response to see if there are any error messages or indicators that the 1-hour TTL cache control requests are being rejected or ignored.

Example

No code snippet is provided as the issue seems to be related to the interaction between the Claude Code application and the Anthropic API, and the provided information does not include any code that can be modified to fix the issue.

Notes

The issue may be related to a misconfiguration or a bug in the Anthropic API, and further investigation is needed to determine the root cause. The fact that the ephemeral_1h_input_tokens is always 0 suggests that the 1-hour TTL cache control requests are not being properly handled by the server.

Recommendation

Apply workaround: Verify the correct usage of the ENABLE_PROMPT_CACHING_1H environment variable and ensure the Anthropic API properly handles the 1-hour TTL cache control requests, as the issue seems to be related to the interaction between the Claude Code application and the Anthropic API.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] ENABLE_PROMPT_CACHING_1H is not working (API key user) [1 comments, 2 participants]