From f77fe871e6e2a29f94cdfad37b6bf2b99adab134 Mon Sep 17 00:00:00 2001 From: Apoorv Darshan Date: Sun, 25 Jan 2026 10:32:06 +0530 Subject: [PATCH 1/2] fix: exclude cache_read tokens from totalTokens count: -Cache read tokens are served from Anthropic's prompt cache (10% rate). -Including them inflated the displayed token count by 10-90x. -Fixes steipete/CodexBar#92 --- .../Vendored/CostUsage/CostUsageScanner+Claude.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift b/Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift index 5e32060b..3d3a37bd 100644 --- a/Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift +++ b/Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift @@ -538,7 +538,9 @@ extension CostUsageScanner { breakdown.sort { lhs, rhs in (rhs.costUSD ?? -1) < (lhs.costUSD ?? -1) } let top = Array(breakdown.prefix(3)) - let dayTotal = dayInput + dayCacheRead + dayCacheCreate + dayOutput + // Exclude cache read tokens from totalTokens since they're served from cache + // (not fresh computation). Include cache creation as those tokens are processed. + let dayTotal = dayInput + dayCacheCreate + dayOutput let entryCost = dayCostSeen ? dayCost : nil entries.append(CostUsageDailyReport.Entry( date: day, From c55463b6edf700519047397bf0a426080c1ba474 Mon Sep 17 00:00:00 2001 From: Apoorv Darshan Date: Sun, 25 Jan 2026 10:44:11 +0530 Subject: [PATCH 2/2] test: update expected totalTokens to exclude cache_read --- Tests/CodexBarTests/CostUsageScannerTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/CodexBarTests/CostUsageScannerTests.swift b/Tests/CodexBarTests/CostUsageScannerTests.swift index 558b9f53..7153cf68 100644 --- a/Tests/CodexBarTests/CostUsageScannerTests.swift +++ b/Tests/CodexBarTests/CostUsageScannerTests.swift @@ -204,7 +204,7 @@ struct CostUsageScannerTests { #expect(report.data[0].cacheCreationTokens == 50) #expect(report.data[0].cacheReadTokens == 25) #expect(report.data[0].outputTokens == 80) - #expect(report.data[0].totalTokens == 355) + #expect(report.data[0].totalTokens == 330) #expect((report.data[0].costUSD ?? 0) > 0) }