Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2209a9b
feat(cursor): add token cost report with Cursor-metered total
EClinick Jun 24, 2026
a3aaa75
style(cursor): wrap long Preferences subtitle to satisfy swiftformat
EClinick Jun 24, 2026
891c2fe
fix(cursor): default TokenUsageSection.meteredLine to keep call sites…
EClinick Jun 24, 2026
070ec1b
fix(cursor): honor cookie-source setting when fetching cost
EClinick Jun 24, 2026
8f650d9
fix(cursor): correct lenient count decoding and fetcher test day-grou…
EClinick Jun 24, 2026
baacfb5
fix(cursor): render cost inline with a windowed history chart
EClinick Jun 24, 2026
6729df8
fix(cursor): tie cost session line to the current local day
EClinick Jun 25, 2026
f92c3d6
fix(cursor): show dashboard cost hint on the menu and inline cards
EClinick Jun 25, 2026
8632505
fix(cursor): honor cookie source in CLI cost and gate to macOS
EClinick Jun 25, 2026
51c8bab
fix(cursor): snap cost window start to the local day boundary
EClinick Jun 25, 2026
9a8c8e9
fix(cursor): key cost cache on the manual cookie header
EClinick Jun 25, 2026
05fd50b
test(cursor): cover the cost window day-boundary snap
EClinick Jun 25, 2026
51dd178
refactor(cursor): extract shared cost cookie-gating helpers
EClinick Jun 25, 2026
933e16d
fix(cursor): honor cookie source in serve /cost route
EClinick Jun 25, 2026
02bcded
Merge origin/main into feat/cursor-token-cost
EClinick Jun 29, 2026
43c8755
fix: report disabled Cursor cost source
steipete Jul 1, 2026
6bdb63a
Merge origin/main into feat/cursor-token-cost
EClinick Jul 6, 2026
718963b
Include Cursor auto session identity in cost cache scope
EClinick Jul 6, 2026
613342a
docs: describe Cursor dashboard cost source and CLI output
EClinick Jul 6, 2026
fb5c0b4
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
EClinick Jul 10, 2026
079da53
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
EClinick Jul 11, 2026
6343b1a
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
EClinick Jul 11, 2026
413e91f
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
steipete Jul 17, 2026
c0f0ac1
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
steipete Jul 17, 2026
2a421d6
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
steipete Jul 17, 2026
a0365e2
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
steipete Jul 17, 2026
d8e8696
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
steipete Jul 17, 2026
6be538d
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
steipete Jul 17, 2026
3eac7e2
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
steipete Jul 17, 2026
275626f
test: include Cursor in spend dashboard contract
steipete Jul 17, 2026
4ba8cb1
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
steipete Jul 17, 2026
5a1a873
Merge remote-tracking branch 'origin/main' into feat/cursor-token-cost
steipete Jul 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/CodexBar/MenuCardHeightFingerprint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ extension UsageMenuCardView.Model.TokenUsageSection {
MenuCardHeightFingerprint.join([
MenuCardHeightFingerprint.field("session", self.sessionLine),
MenuCardHeightFingerprint.field("month", self.monthLine),
MenuCardHeightFingerprint.field("metered", self.meteredLine),
MenuCardHeightFingerprint.field("hint", self.hintLine),
MenuCardHeightFingerprint.field("error", self.errorLine),
MenuCardHeightFingerprint.field("errorCopy", self.errorCopyText),
Expand Down
7 changes: 7 additions & 0 deletions Sources/CodexBar/MenuCardView+Costs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,17 @@ extension UsageMenuCardView.Model {
}
return "\(windowLabel): \(monthCost)"
}()
// Plan-metered spend over the same window (what the provider actually deducts);
// only providers that report it (currently Cursor) populate `meteredCostUSD`.
let meteredLine: String? = snapshot.meteredCostUSD.map {
let amount = UsageFormatter.currencyString($0, currencyCode: snapshot.currencyCode)
return String(format: L("Cursor-metered: %@ (%@)"), amount, windowLabel.lowercased())
}
let err = (error?.isEmpty ?? true) ? nil : error
return TokenUsageSection(
sessionLine: sessionLine,
monthLine: monthLine,
meteredLine: meteredLine,
hintLine: Self.tokenUsageHint(provider: provider),
errorLine: err,
errorCopyText: (error?.isEmpty ?? true) ? nil : error)
Expand Down
3 changes: 2 additions & 1 deletion Sources/CodexBar/MenuCardView+ModelHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ extension UsageMenuCardView.Model {
true
case let (current?, candidate?):
current.hintLine == candidate.hintLine &&
current.errorLine == candidate.errorLine
current.errorLine == candidate.errorLine &&
(current.meteredLine == nil) == (candidate.meteredLine == nil)
default:
false
}
Expand Down
11 changes: 11 additions & 0 deletions Sources/CodexBar/MenuCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct UsageMenuCardView: View {
struct TokenUsageSection {
let sessionLine: String
let monthLine: String
let meteredLine: String?
Comment thread
EClinick marked this conversation as resolved.
Resolved
let hintLine: String?
let errorLine: String?
let errorCopyText: String?
Expand Down Expand Up @@ -197,6 +198,11 @@ struct UsageMenuCardView: View {
Text(tokenUsage.monthLine)
.font(.footnote)
.lineLimit(1)
if let metered = tokenUsage.meteredLine, !metered.isEmpty {
Text(metered)
.font(.footnote)
.lineLimit(1)
}
if let hint = tokenUsage.hintLine, !hint.isEmpty {
Text(hint)
.font(.footnote)
Expand Down Expand Up @@ -712,6 +718,11 @@ struct UsageMenuCardCostSectionView: View {
Text(tokenUsage.monthLine)
.font(.caption)
.lineLimit(1)
if let metered = tokenUsage.meteredLine, !metered.isEmpty {
Text(metered)
.font(.caption)
.lineLimit(1)
}
if let hint = tokenUsage.hintLine, !hint.isEmpty {
Text(hint)
.font(.footnote)
Expand Down
12 changes: 12 additions & 0 deletions Sources/CodexBar/PreferencesGeneralPane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,20 @@ struct GeneralPane: View {
.font(.footnote)
.foregroundStyle(.tertiary)

Toggle(isOn: self.$settings.cursorFetchAllCostHistory) {
Text(L("Fetch full Cursor cost history"))
.font(.footnote)
}
.toggleStyle(.checkbox)

Text(L("Cursor only: total all-time spend instead of the window above. Slower to load."))
.font(.footnote)
.foregroundStyle(.tertiary)
.fixedSize(horizontal: false, vertical: true)

self.costStatusLine(provider: .claude)
self.costStatusLine(provider: .codex)
self.costStatusLine(provider: .cursor)
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/CodexBar/SettingsStore+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,16 @@ extension SettingsStore {
}
}

/// When enabled, Cursor cost fetches the full account history (all-time) instead of the
/// `costUsageHistoryDays` window. Cursor-only; other providers ignore it.
var cursorFetchAllCostHistory: Bool {
get { self.defaultsState.cursorFetchAllCostHistory }
set {
self.defaultsState.cursorFetchAllCostHistory = newValue
self.userDefaults.set(newValue, forKey: "cursorFetchAllCostHistory")
}
}

var hidePersonalInfo: Bool {
get { self.defaultsState.hidePersonalInfo }
set {
Expand Down
1 change: 1 addition & 0 deletions Sources/CodexBar/SettingsStore+MenuObservation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extension SettingsStore {
_ = self.copilotIconSecondaryWindowIDRaw
_ = self.costUsageEnabled
_ = self.costUsageHistoryDays
_ = self.cursorFetchAllCostHistory
_ = self.appLanguage
_ = self.hidePersonalInfo
_ = self.randomBlinkEnabled
Expand Down
2 changes: 2 additions & 0 deletions Sources/CodexBar/SettingsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ extension SettingsStore {
let costUsageEnabled = userDefaults.object(forKey: "tokenCostUsageEnabled") as? Bool ?? false
let rawCostUsageHistoryDays = userDefaults.object(forKey: "tokenCostUsageHistoryDays") as? Int ?? 30
let costUsageHistoryDays = max(1, min(365, rawCostUsageHistoryDays))
let cursorFetchAllCostHistory = userDefaults.object(forKey: "cursorFetchAllCostHistory") as? Bool ?? false
let hidePersonalInfo = userDefaults.object(forKey: "hidePersonalInfo") as? Bool ?? false
let randomBlinkEnabled = userDefaults.object(forKey: "randomBlinkEnabled") as? Bool ?? false
let confettiOnWeeklyLimitResetsEnabled = userDefaults.object(
Expand Down Expand Up @@ -451,6 +452,7 @@ extension SettingsStore {
copilotIconSecondaryWindowIDRaw: copilotIconSecondaryWindowIDRaw,
costUsageEnabled: costUsageEnabled,
costUsageHistoryDays: costUsageHistoryDays,
cursorFetchAllCostHistory: cursorFetchAllCostHistory,
hidePersonalInfo: hidePersonalInfo,
randomBlinkEnabled: randomBlinkEnabled,
confettiOnWeeklyLimitResetsEnabled: confettiOnWeeklyLimitResetsEnabled,
Expand Down
1 change: 1 addition & 0 deletions Sources/CodexBar/SettingsStoreState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct SettingsDefaultsState {
var copilotIconSecondaryWindowIDRaw: String
var costUsageEnabled: Bool
var costUsageHistoryDays: Int
var cursorFetchAllCostHistory: Bool
var hidePersonalInfo: Bool
var randomBlinkEnabled: Bool
var confettiOnWeeklyLimitResetsEnabled: Bool
Expand Down
2 changes: 2 additions & 0 deletions Sources/CodexBar/StatusItemController+CostMenuCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ extension StatusItemController {
[
tokenUsage?.sessionLine,
tokenUsage?.monthLine,
tokenUsage?.meteredLine,
tokenUsage?.hintLine,
tokenUsage?.errorLine,
]
Expand All @@ -106,6 +107,7 @@ extension StatusItemController {
let primaryLines = [
tokenUsage?.sessionLine,
tokenUsage?.monthLine,
tokenUsage?.meteredLine,
tokenUsage?.errorLine,
]
.compactMap(\.self)
Expand Down
8 changes: 6 additions & 2 deletions Sources/CodexBar/UsageStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ extension UsageStore {
_ = self.settings.usageBarsShowUsed
_ = self.settings.costUsageEnabled
_ = self.settings.costUsageHistoryDays
_ = self.settings.cursorFetchAllCostHistory
_ = self.settings.randomBlinkEnabled
_ = self.settings.configRevision
for implementation in ProviderCatalog.all {
Expand Down Expand Up @@ -1493,8 +1494,10 @@ extension UsageStore {

let now = Date()
let historyDays = self.settings.costUsageHistoryDays
// Cursor can pull its full account history (all-time) instead of the rolling window.
let fetchAllHistory = provider == .cursor && self.settings.cursorFetchAllCostHistory
let costScope = self.tokenCostScope(for: provider)
let costScopeSignature = "\(costScope.signature)|historyDays=\(historyDays)"
let costScopeSignature = "\(costScope.signature)|historyDays=\(historyDays)|fetchAll=\(fetchAllHistory)"
if !force,
let last = self.lastTokenFetchAt[provider],
self.lastTokenFetchScope[provider] == costScopeSignature,
Expand Down Expand Up @@ -1545,7 +1548,8 @@ extension UsageStore {
forceRefresh: force,
allowVertexClaudeFallback: !self.isEnabled(.claude),
codexHomePath: costScope.codexHomePath,
historyDays: historyDays)
historyDays: historyDays,
fetchAllHistory: fetchAllHistory)
}
group.addTask {
try await Task.sleep(nanoseconds: UInt64(timeoutSeconds * 1_000_000_000))
Expand Down
33 changes: 28 additions & 5 deletions Sources/CodexBarCLI/CLICostCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Commander
import Foundation

extension CodexBarCLI {
private static let costSupportedProviders: Set<UsageProvider> = [.claude, .codex]
private static let costSupportedProviders: Set<UsageProvider> = [.claude, .codex, .cursor]

static func runCost(_ values: ParsedValues) async {
let output = CLIOutputPreferences.from(values: values)
Expand All @@ -21,9 +21,13 @@ extension CodexBarCLI {
}
}
guard !providers.isEmpty else {
let supportedNames = Self.costSupportedProviders
.map { ProviderDescriptorRegistry.descriptor(for: $0).metadata.displayName }
.sorted()
.joined(separator: ", ")
Self.exit(
code: .failure,
message: "Error: cost is only supported for Claude and Codex.",
message: "Error: cost is only supported for \(supportedNames).",
output: output,
kind: .args)
}
Expand All @@ -32,6 +36,7 @@ extension CodexBarCLI {
let forceRefresh = values.flags.contains("refresh")
let useColor = Self.shouldUseColor(noColor: values.flags.contains("noColor"), format: format)
let historyDays = Self.decodeCostHistoryDays(from: values)
let fetchAllHistory = values.flags.contains("all")

let fetcher = CostUsageFetcher()
var sections: [String] = []
Expand All @@ -40,11 +45,13 @@ extension CodexBarCLI {

for provider in providers {
do {
// Cost usage is local-only; it does not require web/CLI provider fetches.
// Claude/Codex cost comes from local logs; Cursor cost is fetched from its
// cookie-authenticated dashboard API via the shared session resolution.
let snapshot = try await fetcher.loadTokenSnapshot(
provider: provider,
forceRefresh: forceRefresh,
historyDays: historyDays,
fetchAllHistory: fetchAllHistory,
refreshPricingInBackground: false)
switch format {
case .text:
Expand Down Expand Up @@ -98,8 +105,17 @@ extension CodexBarCLI {
"\(historyLabel): \(monthCost) · \($0) tokens"
} ?? "\(historyLabel): \(monthCost)"

// Plan-metered spend over the same window (what Cursor actually deducts), shown
// alongside the API-rate estimate. Only providers like Cursor report it.
let meteredLine: String? = snapshot.meteredCostUSD.map {
let amount = UsageFormatter.currencyString($0, currencyCode: snapshot.currencyCode)
return "Cursor-metered: \(amount) (\(historyLabel.lowercased()))"
}

let hintLine = UsageFormatter.costEstimateHint(provider: provider)
return [header, todayLine, monthLine, hintLine].joined(separator: "\n")
return [header, todayLine, monthLine, meteredLine, hintLine]
.compactMap(\.self)
.joined(separator: "\n")
}

private static func costHeaderLine(_ header: String, useColor: Bool) -> String {
Expand Down Expand Up @@ -136,14 +152,15 @@ extension CodexBarCLI {

return CostPayload(
provider: provider.rawValue,
source: "local",
source: provider == .cursor ? "web" : "local",
updatedAt: snapshot?.updatedAt ?? (error == nil ? nil : Date()),
currencyCode: snapshot?.currencyCode,
sessionTokens: snapshot?.sessionTokens,
sessionCostUSD: snapshot?.sessionCostUSD,
historyDays: snapshot?.historyDays,
last30DaysTokens: snapshot?.last30DaysTokens,
last30DaysCostUSD: snapshot?.last30DaysCostUSD,
meteredCostUSD: snapshot?.meteredCostUSD,
daily: daily,
totals: snapshot.flatMap(Self.costTotals(from:)),
error: error.map { Self.makeErrorPayload($0) })
Expand Down Expand Up @@ -255,6 +272,9 @@ struct CostOptions: CommanderParsable {

@Option(name: .long("days"), help: "Cost history window in days (1...365)")
var days: Int?

@Flag(name: .long("all"), help: "Fetch full cost history instead of the --days window (Cursor only)")
var all: Bool = false
}

struct CostPayload: Encodable {
Expand All @@ -267,6 +287,7 @@ struct CostPayload: Encodable {
let historyDays: Int?
let last30DaysTokens: Int?
let last30DaysCostUSD: Double?
let meteredCostUSD: Double?
let daily: [CostDailyEntryPayload]
let totals: CostTotalsPayload?
let error: ProviderErrorPayload?
Expand All @@ -281,6 +302,7 @@ struct CostPayload: Encodable {
historyDays: Int?,
last30DaysTokens: Int?,
last30DaysCostUSD: Double?,
meteredCostUSD: Double? = nil,
daily: [CostDailyEntryPayload],
totals: CostTotalsPayload?,
error: ProviderErrorPayload?)
Expand All @@ -294,6 +316,7 @@ struct CostPayload: Encodable {
self.historyDays = historyDays
self.last30DaysTokens = last30DaysTokens
self.last30DaysCostUSD = last30DaysCostUSD
self.meteredCostUSD = meteredCostUSD
self.daily = daily
self.totals = totals
self.error = error
Expand Down
Loading