fix: exclude cache_read tokens from totalTokens count#244
fix: exclude cache_read tokens from totalTokens count#244apoorvdarshan wants to merge 6 commits intosteipete:mainfrom
Conversation
apoorvdarshan
commented
Jan 25, 2026
- Cache read tokens are served from Anthropic's prompt cache (10% rate).
- Including them inflated the displayed token count by 10-90x.
- Fixes API expense incorrect #92
-Cache read tokens are served from Anthropic's prompt cache (10% rate). -Including them inflated the displayed token count by 10-90x. -Fixes steipete#92
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f77fe871e6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift
Outdated
Show resolved
Hide resolved
|
I investigated this and found the root cause. The BugIn let dayTotal = dayInput + dayCacheRead + dayCacheCreate + dayOutputThis sums ALL token types including ExampleFor a typical cached API response:
Old formula: 10 + 15,000 + 500 + 100 = 15,610 tokens (inflated) Fix// Exclude cache reads - they're served from cache, not re-processed
let dayTotal = dayInput + dayCacheCreate + dayOutputVerified
Cost staying the same confirms pricing logic was already correct - only the token count display was inflated. I'll submit a PR with this fix. |
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
Thanks for the detailed root-cause writeup. Your before/after numbers are very helpful. I recommend we preserve Why this direction:
Required follow-ups before merge:
Once this is in place, we should be merge ready. |
Revert totalTokens to include cache_read_input_tokens (Anthropic-aligned). Add separate processedTokens field (excluding cache_read) for UI display so users see only freshly computed tokens. Updates menu card, widget, and fetcher to prefer processedTokens with fallback to totalTokens. Fixes steipete#92
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 598897bb1b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Use processedTokens ?? totalTokens in CostHistoryChartMenuView so the chart matches the menu summary. Also resolve MiniMax merge conflict.
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@ratulsarna changes done, please review, edit (if required), and merge the same regards |