Add local session cost ledger#2172
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 17, 2026, 4:08 AM ET / 08:08 UTC. Summary Reproducibility: not applicable. as a bug reproduction: this PR adds a new opt-in capability. The submitted screenshot and claimed live CLI/app runs provide high-confidence behavioral validation of that capability. Review metrics: 2 noteworthy metrics.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the opt-in, default-off implementation once the exact head passes required checks, then let the linked feature issue close through the PR relationship. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this PR adds a new opt-in capability. The submitted screenshot and claimed live CLI/app runs provide high-confidence behavioral validation of that capability. Is this the best way to solve the issue? Yes. Reusing the existing cost scanner behind a Codex-specific, default-off preference is narrower and safer than changing managed-account quota behavior or adding another billing integration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0f27d0e3f686. Label changesLabel changes:
Label justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (5 earlier review cycles)
|
…sion-costs # Conflicts: # Sources/CodexBarCore/Generated/CodexParserHash.generated.swift
…sion-costs # Conflicts: # Sources/CodexBarCore/Generated/CodexParserHash.generated.swift
…sion-costs # Conflicts: # Sources/CodexBarCore/Generated/CodexParserHash.generated.swift
…sion-costs # Conflicts: # Sources/CodexBarCore/Generated/CodexParserHash.generated.swift
…sion-costs # Conflicts: # Sources/CodexBar/UsageStore+TokenCost.swift # Sources/CodexBar/UsageStore.swift # Sources/CodexBarCore/CostUsageFetcher.swift
|
Maintainer verification
|
Summary
Adds a local Codex session cost ledger that works alongside a managed Codex account. It exposes a clear Settings toggle for local session cost estimates, keeps the local scanner independent from the selected managed account, and avoids showing an account quota failure as a failure of valid local cost data.
Problem
Developers using organization-provided OpenAI API keys can run Codex but often do not have OpenAI organization billing or administrator access. The existing account-level quota paths cannot provide a useful spend view in that situation.
The local session ledger is the appropriate source for this case. It reads the token records Codex already writes locally and produces an API-rate estimate without calling the OpenAI billing API.
How it works
CodexBar scans JSONL session files under
$CODEX_HOME/sessionswhenCODEX_HOMEis set, otherwise~/.codex/sessions. It takes the finaltoken_countrecord from each session. For example:The record provides total input, cached input, and output token counts. Cost calculation separates cached and uncached input:
Rates are per token in the calculation. The price catalog refreshes from models.dev when available and uses bundled pricing offline. The result is an API-rate estimate, not an organization invoice. Negotiated discounts, credits, taxes, and platform-side accounting can differ.
Behavior
Validation
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer swift test --filter ProviderSettingsDescriptorTestsDEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer swift test --filter MenuCardModelCodexDegradedQuotaTestsCodexBarCLI cost --provider codex --refresh --no-coloragainst real local session logsCloses #2174