Mods API: give the 5-minute and 1-hour split of cache writes in the usage of `turn.step`
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 aturn.stepresult, holdsinput_tokens,output_tokens,cache_read_input_tokens,cache_creation_input_tokensandmodel. The Messages API response andclaude -p --output-format jsonalso holdcache_creation.ephemeral_5m_input_tokensandcache_creation.ephemeral_1h_input_tokens. The mod does not get them.SessionRateLimithas 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
PreModelSwitchandPostModelSwitchevents carrycache_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
- Add
cache_creation: { ephemeral_5m_input_tokens: number; ephemeral_1h_input_tokens: number }toModelUsageandTurnUsage, as the Messages API reports it. - Optional: add the cache life that Claude Code resolved for the request (
cacheTtl: '5m' | '1h') toTurnStepInput, so that a mod knows it before the response. - Optional: add a flag to
SessionRateLimitorSessionUsagethat says that the account uses usage credits.
Environment
Claude Code 2.1.294. Mods API types written by 2.1.293.