AI News DailyTips한국어
← AI tool tips
Claude Code✓ Confirmed in official docsAdded Oct 16

How to split Claude Code prompt cache writes into 5-minute and 1-hour with OpenTelemetry

Since Claude Code v2.1.300, the OpenTelemetry api_request event carries cache_creation_5m_tokens and cache_creation_1h_tokens. Cache writes that used to be lumped into cache_creation_tokens can now be split by lifetime, which helps you check how much write cost went up after turning on the 1-hour cache.

  1. Turn on telemetry and export log events. Start with the console exporter to print them in the terminal.
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_LOGS_EXPORTER=console
claude
  1. Compare the two values in the claude_code.api_request event. You can set the cache lifetime separately for the main conversation and for subagents.
export CLAUDE_CODE_PROMPT_CACHE_TTL=1h
export CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL=5m

At API rates, 5-minute cache writes cost 1.25 times the base input price and 1-hour cache writes cost 2 times. If turning on the 1-hour cache only raised write tokens without a matching rise in cache_read_tokens, consider going back to 5 minutes. The two attributes are only in the changelog so far; the reference docs still list just cache_creation_tokens for api_request.

Get notified when a new tip lands

Tip alerts only go out in the app. Install it and turn notifications on.

Get the app

All tips →