claude-code - 💡(How to fix) Fix [DOCS] Agent SDK transcript viewer docs missing final token usage semantics [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45482Fetched 2026-04-09 08:04:23
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
labeled ×2
RAW_BUFFERClick to expand / collapse

Documentation Type

Missing documentation (feature not documented)

Documentation Location

https://code.claude.com/docs/en/agent-sdk/sessions

Section/Topic

getSessionMessages() / get_session_messages() transcript viewer guidance and transcript token-usage semantics

Current Documentation

The sessions guide currently says:

Both SDKs expose functions for enumerating sessions on disk and reading their messages: listSessions() and getSessionMessages() in TypeScript, list_sessions() and get_session_messages() in Python. Use them to build custom session pickers, cleanup logic, or transcript viewers.

The TypeScript reference currently says:

message | unknown | Raw message payload from the transcript

The Python reference currently says:

message | Any | Raw message content

The cost-tracking guide currently says:

Each assistant message contains a nested BetaMessage (accessed via message.message) with an id and usage object with token counts.

When the query() call completes, the SDK emits a result message with total_cost_usd and cumulative usage.

The docs describe transcript access and live per-step usage separately, but they do not explain what token-usage values transcript-derived per-block entries contain.

What's Wrong or Missing?

Changelog v2.1.97 introduced a transcript-facing behavior change:

Improved transcript accuracy: per-block entries now carry the final token usage instead of the streaming placeholder

That matters for developers who read ~/.claude/projects/<project>/<session>.jsonl directly or use getSessionMessages() / get_session_messages() to build transcript viewers or usage analytics.

What's missing is a clear explanation of transcript token-usage semantics:

A. No transcript-specific usage guidance

The docs say session messages come from the transcript, but they do not explain whether transcript-derived assistant/per-block entries include token usage, or how those values should be interpreted.

B. No note about the v2.1.97 accuracy change

There is no documentation stating that per-block transcript entries now carry the final token usage instead of a streaming placeholder.

C. No guidance on per-block usage vs final totals

The cost-tracking guide explains per-step usage and the authoritative final ResultMessage.usage, but it does not connect that guidance to transcript readers who need to know when transcript usage is suitable for display versus when they should rely on the final result totals.

Suggested Improvement

Add a short “Transcript usage semantics” note to the sessions guide, with cross-links from the TypeScript and Python API references.

Suggested content:

  1. State that session transcripts are stored in ~/.claude/projects/<project>/<session>.jsonl and can be read directly or via getSessionMessages() / get_session_messages().
  2. Document that transcript-derived assistant/per-block entries can include token-usage data.
  3. Note that as of v2.1.97, those per-block entries carry the final token usage rather than the earlier streaming placeholder.
  4. Clarify that transcript viewers can display those finalized per-block values, but billing/whole-query totals should still use the final result message (usage, total_cost_usd, and per-model breakdowns).
  5. Cross-reference the existing cost-tracking guidance about deduplicating assistant messages that share the same message ID during parallel tool turns.

Impact

Medium - Makes feature difficult to understand

Additional Context

Affected Pages:

PageContext
https://code.claude.com/docs/en/agent-sdk/sessionsTells users to use session-message APIs to build transcript viewers
https://code.claude.com/docs/en/agent-sdk/typescriptgetSessionMessages() return type and SDKAssistantMessage.message.usage context
https://code.claude.com/docs/en/agent-sdk/pythonget_session_messages() return type and AssistantMessage.usage context
https://code.claude.com/docs/en/agent-sdk/cost-trackingExplains per-step usage and authoritative final totals, but only for streamed query output
https://code.claude.com/docs/en/claude-directoryDocuments where transcript JSONL files are stored

Total scope: 5 pages affected

Source: Changelog v2.1.97

Exact changelog entry: “Improved transcript accuracy: per-block entries now carry the final token usage instead of the streaming placeholder”

extent analysis

TL;DR

Add a "Transcript usage semantics" note to the sessions guide to clarify how transcript-derived token-usage values should be interpreted.

Guidance

  • Review the suggested improvement section for the exact content to add to the sessions guide.
  • Ensure the note includes information about the change introduced in v2.1.97, where per-block transcript entries now carry the final token usage.
  • Cross-reference the existing cost-tracking guidance to provide a clear understanding of when to use transcript usage versus final result totals.
  • Update the affected pages (sessions, TypeScript, Python, cost-tracking, and Claude directory) to reflect the new guidance.

Example

No code snippet is necessary for this issue, as it is focused on documentation improvements.

Notes

The suggested improvement provides a clear outline of what needs to be added to the documentation. It is essential to follow this outline to ensure that the documentation accurately reflects the changes introduced in v2.1.97 and provides clear guidance for developers.

Recommendation

Apply the suggested improvement to add a "Transcript usage semantics" note to the sessions guide, as this will provide the necessary clarity for developers to understand how to interpret transcript-derived token-usage values.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING