fix: token counter undercounted cached requests; Forge clarify UI polish - #80
Merged
Merged
Conversation
…ify UI polish The token counter silently dropped cache_read_input_tokens and cache_creation_input_tokens from Anthropic's usage response, counting only the fresh/non-cached portion as `inputTokens` — since the recent caching optimizations mean nearly every request now involves a cache read or write, the displayed total badly undercounted real spend. Folds both into `inputTokens`, matching how OpenAI's `prompt_tokens` already reports the full total with cached tokens as a subset. Also fixes two UI issues in the Radical Forge wizard: the absolutely- positioned close button overlapped the token-count badge once it grew wide (e.g. "25.9K tokens"), and the clarify form's submit button was labeled "Continue" — the same word as the footer's "Continue →" button, which does something different (advances the wizard step vs. confirms clarify answers for the current stage). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
providers/claude.ts'sparseUsageonly read Anthropic'sinput_tokensfield as the total input token count — but Anthropic deliberately reportsinput_tokensas only the fresh, non-cached portion of the prompt, moving cached tokens into separatecache_read_input_tokens/cache_creation_input_tokensfields. Since the recent 5-point optimization PR (feat: 5-point token/latency optimization for the AI integration #78) put caching on nearly every request, the displayed session/stage token counters were silently undercounting real spend — sometimes drastically. Now folds both intoinputTokens, matching how OpenAI'sprompt_tokensalready reports the full total with the cached portion as a subset (cachedInputTokensstays available separately for the "N served from cache" tooltip)..ai-settings-closeis absolutely positioned in the Forge panel header and doesn't reserve any space, so a wide token badge (e.g. "25.9K tokens") ran underneath it. Addedpadding-rightto.forge-title-rowto clear it.Test plan
npm run typecheckcleannpm run test— 371 passing; updated Anthropic usage-parsing assertions to the corrected (larger, now-correct) totals, and added a case coveringcache_creation_input_tokensfolding specifically (a cache write, which happens on essentially every first request in a session)🤖 Generated with Claude Code