# CLAUDE_CODE_PROMPT_CACHE_TTL

> It sets the cache time for the main chat: 5m or 1h.

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL

## Think of it like

It is like you choose how long the shop keeps your bag at the desk.

## Definition

CLAUDE_CODE_PROMPT_CACHE_TTL sets how long a saved prompt lasts for the main chat. It takes 5m or 1h and nothing else. Its twin with SUBAGENT in the name does the same for subagents, workflows and work in the back. Both win over the one-hour switch and the settings. It needs version 2.1.242 or later.

## Example

Jack's main chat sits idle for long spells, but his subagents finish fast. He gives the main chat 1h and the subagents 5m.

## Example code

```bash
export CLAUDE_CODE_PROMPT_CACHE_TTL=1h
export CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL=5m
claude
```

A long cache for you, a short one for helpers.

## Why it matters

The main chat and the helpers have different gaps between calls, so one time does not fit both.

## Common mistake

Writing 60m or 3600. It only takes 5m or 1h.

## Three principles

- **5m or 1h.** Nothing else.
- **Main and subagent.** Two variables.
- **Beats the 1h switch.** But not the force.

## Related terms

- [ENABLE_PROMPT_CACHING_1H](https://learn.benibix.com/term/ai/enable-prompt-caching-1h-variable)
- [FORCE_PROMPT_CACHING_5M](https://learn.benibix.com/term/ai/force-prompt-caching-5m-variable)
- [Prompt Caching](https://learn.benibix.com/term/ai/prompt-caching)

## Told apart from

- [ENABLE_PROMPT_CACHING_1H vs CLAUDE_CODE_PROMPT_CACHE_TTL](https://learn.benibix.com/compare/enable-prompt-caching-1h-variable-vs-claude-code-prompt-cache-ttl-variable): People think ENABLE_PROMPT_CACHING_1H is the way to set how long the cache lasts. It is one switch for everything. CLAUDE_CODE_PROMPT_CACHE_TTL sets the main chat alone, and its SUBAGENT twin sets the helpers. Both win over the switch. So set the switch for a quick change, and the two TTL variables when the main chat and helpers need different times.

![The 5-minute force wins, then the TTL variables, then the 1-hour switch, then the default.](https://learn.benibix.com/diagrams/env-cache-ttl.svg)

---

Source: https://learn.benibix.com/term/ai/claude-code-prompt-cache-ttl-variable
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
