Mods API: give the 5-minute and 1-hour split of cache writes in the usage of `turn.step`

Status Open
Reported on v2.1.294
Maintainer reply None cached
Activity 0 comments · opened Oct 9, 2026

Problem

A mod that shows the cache state and the cost of a session needs the cache life of each request. Claude Code sets the life per request, 5 minutes or 1 hour, from the plan, the usage state and several settings (FORCE_PROMPT_CACHING_5M, CLAUDE_CODE_PROMPT_CACHE_TTL, promptCacheTtl, the cacheTtl frontmatter of a subagent, ENABLE_PROMPT_CACHING_1H). A mod cannot see the result:

  • TurnUsage, the usage of a turn.step result, holds input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens and model. The Messages API response and claude -p --output-format json also hold cache_creation.ephemeral_5m_input_tokens and cache_creation.ephemeral_1h_input_tokens. The mod does not get them.
  • SessionRateLimit has no field that says that the account uses usage credits. That is the state in which the main conversation drops to 5 minutes.
  • Only the PreModelSwitch and PostModelSwitch events carry cache_ttl.

A mod can infer the life today from the rise of $.session.usage().cost.usd, because Claude Code books each request at the price of its real life. This works, but it needs an exact price table in the mod. It fails in fast mode, with US-only inference, with prices of an organization, and when two requests book their cost in the same window.

Request

  1. Add cache_creation: { ephemeral_5m_input_tokens: number; ephemeral_1h_input_tokens: number } to ModelUsage and TurnUsage, as the Messages API reports it.
  2. Optional: add the cache life that Claude Code resolved for the request (cacheTtl: '5m' | '1h') to TurnStepInput, so that a mod knows it before the response.
  3. Optional: add a flag to SessionRateLimit or SessionUsage that says that the account uses usage credits.

Environment

Claude Code 2.1.294. Mods API types written by 2.1.293.

View original on GitHub ↗