CLAUDE_CODE_MESSAGES_PROMPT_CACHE_TTL
Updated by Alex Sorokoletov
CLAUDE_CODE_MESSAGES_PROMPT_CACHE_TTL is a Claude Code environment variable: Set to 5m to force the messages prompt cache to a five-minute lifetime. It sits beside the existing CLAUDE_CODE_PROMPT_CACHE_TTL and CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL controls and pairs with the new 5m/1h cache-write split in telemetry. Added in v2.1.300 and still present in v2.1.332. It is not in the official reference.
| Status | Present in v2.1.332 |
|---|---|
| Added | Added in v2.1.300 |
| Category | Other |
| Official docs | Not listed |
How to set it
For one session, export it in the shell that starts Claude Code:
export CLAUDE_CODE_MESSAGES_PROMPT_CACHE_TTL=<value>
claudeTo apply it to every session, add it to the env object of a settings file:
// ~/.claude/settings.json
{
"env": {
"CLAUDE_CODE_MESSAGES_PROMPT_CACHE_TTL": "<value>"
}
}Release notes that mention it
- Claude Code Version Tracker: Undocumented Env Vars, Feature Gates & Models
- claude-code-env-vars-v2-1-300
Related variables
CLAUDE_CODE_PROMPT_CACHE_TTL: Sets the prompt cache TTL for the main conversation (interactive, -p, and SDK turns) to "5m" or "1h".CLAUDE_CODE_APPEND_PROMPT_HEAD: Designates a prompt-head string that is validated for integrity before use and then cleared after a single read; an invalid value is ignored.CLAUDE_CODE_EMIT_USER_PROMPT_SUBMIT_HOOK_EVENTS: When set, enables emitting start and end hook events for user prompt submission; the value is read once and then cleared.CLAUDE_CODE_FEDERATION_CACHE_DIR: Points at the directory holding the exchanged workload-identity-federation credential (default <config>/credentials/federation).CLAUDE_CODE_GROWTHBOOK_KICK_ON_WARM_CACHE: When set, triggers an early GrowthBook feature-flag fetch even when the cache is already warm.CLAUDE_CODE_INCLUDE_PARTIAL_MESSAGES: Include partial/streaming messages in output.CLAUDE_CODE_MORNING_BRIEF_PROMPT: Set a custom prompt for the morning brief; used when its trimmed length was within bounds, otherwise the default prompt applied.CLAUDE_CODE_NORMALIZE_PREFIX_CACHE: Set to false to disable prefix-cache normalization, or true to enable it at a 0.02 share when no server-side share is set; a server-side share between 0 and 1 takes precedence.
Frequently asked questions
What does CLAUDE_CODE_MESSAGES_PROMPT_CACHE_TTL do?
Set to 5m to force the messages prompt cache to a five-minute lifetime. It sits beside the existing CLAUDE_CODE_PROMPT_CACHE_TTL and CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL controls and pairs with the new 5m/1h cache-write split in telemetry.
Which Claude Code version has CLAUDE_CODE_MESSAGES_PROMPT_CACHE_TTL?
Added in v2.1.300 and still present in v2.1.332.
How do I set CLAUDE_CODE_MESSAGES_PROMPT_CACHE_TTL?
Export it before starting Claude Code (export CLAUDE_CODE_MESSAGES_PROMPT_CACHE_TTL=value), or add it to the "env" object in ~/.claude/settings.json to apply it to every session.
All variables, searchable: Claude Code environment variables.