Problem
PR #126 fixes the main token usage over-reporting bug by capturing per-request usage from message_start/message_delta stream events. However, completeTurn still falls back to accumulated totals from result.usage when lastKnownTokenUsage is undefined — which happens when no stream events arrive (e.g., non-streaming mode, or API calls that dont stream).
// ClaudeAdapter.ts completeTurn (approx line 1506-1533)
const accumulatedSnapshot = normalizeClaudeTokenUsage(
result?.usage,
resultContextWindow ?? context.lastKnownContextWindow,
);
// Falls back to context.lastKnownTokenUsage,
// which could be accumulatedSnapshot if no stream events
Acceptance criteria
Related
Problem
PR #126 fixes the main token usage over-reporting bug by capturing per-request usage from
message_start/message_deltastream events. However,completeTurnstill falls back to accumulated totals fromresult.usagewhenlastKnownTokenUsageis undefined — which happens when no stream events arrive (e.g., non-streaming mode, or API calls that dont stream).Acceptance criteria
result.usagecan be used differently in non-streaming scenariosRelated
token-usage-bug-report.html(root of repo) — contains detailed analysis of all three bug paths