Part of the AI Coding Harness Guide — environment design for coding agents in production.

Claude Code Prompt Cache Shows 5m Instead of 1h: Cache Keepalive and How to Force the One-Hour TTL#

Published by

Since mid-October 2026, interactive Claude Code sessions on a Claude subscription can write their prompt cache with the 5-minute TTL while the client asks for one hour. This is cache keepalive: Claude Code renews the cache every 30 seconds while you were active in the last hour. To get one-hour cache writes instead, set "promptCacheTtl": "1h".

What you see#

  • /usage shows Prompt cache (main) with a 5-minute cache.
  • Session transcripts show cache writes under ephemeral_5m_input_tokens, with ephemeral_1h_input_tokens at 0.
  • A status line that reads prompt_cache.expires_at shows expiry about five minutes ahead instead of an hour.
  • claude -p runs on the same account still write one-hour caches, according to the reports in issue #101685.

Why: cache keepalive#

From v2.1.286, a main-conversation request on the default subscription TTL can carry the cache-keepalive-2026-09-03 beta. When the server accepts it, the response carries anthropic-cache-keepalive: active, and the cache is written with the 5-minute TTL. Claude Code then sends a touch to /v1/messages/cache_touch to renew it. Reporters in #101685 confirmed the link: with only that beta removed from the request, the same session wrote one-hour caches again.

Keepalive runs only when every condition holds:

ConditionWhat turns keepalive off
Claude subscription, within plan usageAn API key, a cloud provider, or drawing on usage credits
The one-hour TTL comes from the subscription defaultAny explicit TTL: promptCacheTtl, CLAUDE_CODE_PROMPT_CACHE_TTL, ENABLE_PROMPT_CACHING_1H or FORCE_PROMPT_CACHING_5M
Requests go to the Anthropic API directlyANTHROPIC_UNIX_SOCKET, or a provider other than Anthropic
Organization policy allows "Renewing the prompt cache lifetime"A HIPAA policy
Anthropic has turned it on for the accountRemote configuration; it reached accounts at different times from 2026-10-12

The touch schedule also comes from remote configuration. The defaults:

ValueDefaultAllowed range
Time between touches30 seconds10 to 120 seconds
Touches continue while there was activity in the last60 minutes1 to 1,440 minutes

Activity means a request, your input, the start or end of work, or Claude waiting on you. After three failed touches in a row, Claude Code stops keepalive for an hour.

What it changes for you#

While Claude Code runs and you were active in the last hour, the cache stays warm, much like a one-hour cache. The difference is that the running Claude Code process sends the touches. When you quit, close the laptop or lose the network, the touches stop and the cache expires about five minutes later instead of an hour later. The first message after that pays to reprocess the whole conversation.

How to get one-hour cache writes#

Set the TTL yourself. Any explicit TTL skips keepalive. In ~/.claude/settings.json:

{
  "promptCacheTtl": "1h"
}

Or with an environment variable:

export CLAUDE_CODE_PROMPT_CACHE_TTL=1h

promptCacheTtl and CLAUDE_CODE_PROMPT_CACHE_TTL take 5m or 1h and need v2.1.242 or later. ENABLE_PROMPT_CACHING_1H=1 also works and applies to subagents too. Reporters in #101685 saw running sessions switch to one-hour writes on their next turn after adding the setting. One-hour cache writes are billed at a higher rate than five-minute writes, which matters on an API key or usage credits.

How to check which one you have#

  • Run /usage and read the Prompt cache (main) line (v2.1.251 or later).
  • Run claude --debug and look for [cache-keepalive] lines: header on for this chain and touch ok <request id> mean keepalive is active; off for this chain: flag off means it is not turned on for you.
  • Read the transcript: one-hour writes count under ephemeral_1h_input_tokens, five-minute writes under ephemeral_5m_input_tokens in message.usage.cache_creation.

Timeline#

Version or datePublishedChange
v2.1.2422026-08-24promptCacheTtl and CLAUDE_CODE_PROMPT_CACHE_TTL arrive.
v2.1.2512026-08-28/usage shows a Prompt cache (main) line.
v2.1.2862026-09-30Cache keepalive and the touch requests arrive. The release notes do not mention them.
From 2026-10-12n/aInteractive sessions start writing 5-minute caches, account by account (#101685).
v2.1.3042026-10-19Keepalive unchanged; no release note yet.

Should you set promptCacheTtl to 1h?#

Set it if you often leave a session for more than five minutes with Claude Code closed, asleep or offline, and come back to the same long conversation, or if you need the cache to match what /usage and your status line report. Leave the default if you keep Claude Code running while you work: keepalive keeps the cache warm for the hour after your last activity with cheaper five-minute writes.


FAQ#

Q: Why does Claude Code use the 5-minute prompt cache when I'm on a subscription?

A: Cache keepalive. From v2.1.286, when Anthropic turns it on for your account, the main conversation's cache is written with the 5-minute TTL and Claude Code renews it every 30 seconds while you were active in the last hour.

Q: How do I force the 1-hour prompt cache in Claude Code?

A: Add "promptCacheTtl": "1h" to ~/.claude/settings.json, or set CLAUDE_CODE_PROMPT_CACHE_TTL=1h. Any explicit TTL skips keepalive. Both need v2.1.242 or later.

Q: Is the 5-minute cache a bug?

A: The 5-minute writes come from keepalive, which renews the cache while Claude Code runs. It differs from a one-hour cache when Claude Code is closed, asleep or offline: the cache then expires after about five minutes.

Q: Why does claude -p still get a 1-hour cache?

A: Reports in #101685 show claude -p runs keep one-hour writes on accounts where interactive sessions get five-minute writes.

Q: How do I see whether keepalive is on?

A: Run claude --debug and look for [cache-keepalive] header on for this chain and touch ok lines.


Sources: Claude Code prompt caching documentation | Claude Code changelog (no entry for cache keepalive through v2.1.304) | Issue #101685

Related: Idle compaction guide | CLAUDE_CODE_PROMPT_CACHE_TTL in the env-var glossary | ENABLE_PROMPT_CACHING_1H in the env-var glossary | Context Window Management Guide