Skip to content

Show Claude prepaid balance - #2443

Merged
steipete merged 6 commits into
steipete:mainfrom
Zihao-Qi:codex/claude-extra-credit
Jul 28, 2026
Merged

Show Claude prepaid balance#2443
steipete merged 6 commits into
steipete:mainfrom
Zihao-Qi:codex/claude-extra-credit

Conversation

@Zihao-Qi

@Zihao-Qi Zihao-Qi commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • fetch Claude's remaining prepaid Usage credits balance from the web API
  • preserve Claude's existing Extra usage spent/cap display and show the prepaid balance right-aligned on the same header row
  • retain the compact Credits presentation when no monthly cap is configured, along with legacy-menu and CLI output
  • enrich OAuth and Auto/CLI results only when the Claude web account matches
  • keep balance-only enrichment bounded, cancellable, and independent of legacy web-extras fetching

Why

CodexBar could show Claude Extra usage spent/cap values but not the remaining prepaid balance. Claude exposes that balance separately in minor currency units, so this adds the missing field without treating it as another quota denominator.

Related: #975.

Validation

  • swift test --filter 'ClaudeWebCookieRenewalTests|ClaudeOAuthFetchStrategyAvailabilityTests|ClaudeOAuthTests|ClaudeWebFetchDeadlineTests|ClaudeWebUsageExtraWindowTests|ClaudeProviderImplementationTests|CLIOutputTests|ClaudeMenuCardCostTests|MenuCardHeightFingerprintTests|PreferencesPaneSmokeTests' — 136 tests passed across 11 suites
  • swift test --filter 'ClaudeMenuCardCostTests|ClaudeProviderImplementationTests' — 6 tests passed across 2 suites
  • make check
  • make test — stopped in three Keychain credential-store suites not modified by this PR; the focused feature tests pass separately

Screenshot

Screenshot 2026-07-25 at 10 56 11 AM

@Zihao-Qi
Zihao-Qi force-pushed the codex/claude-extra-credit branch from 7111416 to ea9d6b4 Compare July 24, 2026 21:33
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. labels Jul 24, 2026
@clawsweeper

clawsweeper Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codex review: needs changes before merge. Reviewed July 25, 2026, 12:53 PM ET / 16:53 UTC.

ClawSweeper review

What this changes

The PR fetches Claude prepaid Usage-credit balances from Claude web endpoints, merges a matched balance into Claude OAuth or CLI usage data, and renders it in the menu bar and CLI output.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

This PR adds a useful Claude balance view and includes a menu screenshot, but the current automatic web-enrichment path still appears able to delay an otherwise successful OAuth or CLI refresh while importing browser cookies. That conflicts with the repository’s cookie-import guidance and needs a narrow guard plus regression coverage before merge.

Priority: P2
Reviewed head: aebe9fd7557905757b99d9d8812615a43c255d67

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The feature has focused tests and direct UI proof, but a P1 compatibility/refresh-path concern remains before it is merge-ready.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (screenshot): The PR body now includes a menu screenshot that directly demonstrates the user-visible prepaid-balance presentation; the remaining blocker is refresh-path safety, not missing visual proof.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): The PR body now includes a menu screenshot that directly demonstrates the user-visible prepaid-balance presentation; the remaining blocker is refresh-path safety, not missing visual proof.
Evidence reviewed 5 items Automatic enrichment remains on the refresh path: The PR’s Claude descriptor enables prepaid-balance enrichment for app refreshes with optional usage enabled whenever web enrichment is available, while its fetcher configuration adds a separate prepaid-balance path. The prior review identified that the automatic cookie source can invoke browser-cookie import even when legacy web extras are disabled.
Repository policy against prompt-prone imports: The repository policy says cookie imports should default to Chrome-only where possible to avoid browser prompts, and advises using non-live seams rather than Keychain/browser paths for ordinary validation. The proposed automatic enrichment needs to preserve that boundary.
Focused coverage does not prove the automatic no-cookie path: The PR adds substantial OAuth-fetch-strategy and web-deadline coverage, including manual-cookie enrichment and prepaid-request cancellation, but the provided diff does not show a regression test that an automatic cookie source with no cached Claude session returns completed OAuth or CLI usage without starting a browser import.
Findings 1 actionable finding [P1] Avoid browser import on the normal OAuth/CLI refresh path
Security None None.

How this fits together

CodexBar gathers Claude usage from OAuth, the Claude CLI, and optional Claude web-session data. This change adds a prepaid-balance enrichment step before the merged usage snapshot is rendered in the menu card, provider details, and CLI.

flowchart LR
    A[Claude OAuth or CLI usage] --> C[Claude usage snapshot]
    B[Optional Claude web session] --> D[Prepaid balance request]
    D --> E[Account identity match]
    C --> E
    E --> F[Merged Claude usage]
    F --> G[Menu bar card]
    F --> H[CLI output]
Loading

Before merge

  • Avoid browser import on the normal OAuth/CLI refresh path (P1) - The current enrichment gate can enable prepaid-balance fetching for the automatic cookie source whenever optional usage is enabled, even if legacy web extras are disabled. That lets a successful OAuth or CLI refresh enter browser-cookie discovery/import and wait for its timeout or prompt path. Keep the completed primary result independent of automatic import; use a manual/already-cached session or an explicit opt-in, and cover the no-cached-cookie case. This is a follow-up to the earlier review concern, but targets the newer descriptor gating introduced after that review.
  • Resolve merge risk (P1) - With the default automatic cookie source, a completed Claude OAuth or CLI usage refresh may wait on browser-cookie discovery/import despite web extras being disabled; users can see delayed refreshes or browser/Keychain interaction for an optional balance field.
  • Resolve merge risk (P2) - The change spans 24 files and adds an OAuth profile request plus a Claude web prepaid-credit request, so the intended identity-matching and timeout boundary needs one explicit default-upgrade regression path before landing.

Findings

  • [P1] Avoid browser import on the normal OAuth/CLI refresh path — Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift:70-74
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Patch surface 24 files affected; 1,839 added, 221 removed The feature crosses Claude retrieval, identity matching, data snapshots, native menu rendering, CLI output, tests, and documentation.
New provider requests 2 added GET paths The OAuth profile request and Claude prepaid-credit request need to remain bounded and isolated from existing refresh behavior.

Merge-risk options

Maintainer options:

  1. Keep automatic refresh non-blocking (recommended)
    Restrict prepaid-balance enrichment to manual or already cached Claude web sessions, then add a regression test proving automatic-source OAuth and CLI refreshes return without browser import when web extras are disabled.
  2. Accept browser-import behavior explicitly
    Merge the current behavior only if maintainers intend optional balance visibility to permit browser-cookie discovery and its possible refresh delay under the automatic source.
  3. Pause balance enrichment
    Pause this PR if preserving the current automatic cookie-import behavior is necessary and no explicit product setting is wanted for the new balance request.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Restrict prepaid-balance enrichment to manual or already cached Claude web sessions; do not start browser-cookie import when legacy web extras are disabled, and add focused coverage for automatic source with no cached session.

Technical review

Best possible solution:

Keep the existing OAuth and CLI refresh result as the default fast path; enrich it with prepaid balance only from a manual or already cached Claude web session, or behind an explicit browser-import opt-in, with coverage for both the compatible default and the opt-in path.

Do we have a high-confidence way to reproduce the issue?

No live high-confidence reproduction was established in this read-only review. The source and the prior concrete review note provide a medium-confidence source reproduction: use the automatic Claude cookie source with optional usage enabled, no cached usable cookie, and web extras disabled, then refresh OAuth or CLI usage.

Is this the best way to solve the issue?

No. The separate balance field and identity match are reasonable, but automatic cookie import should not become a prerequisite or delay source for an existing OAuth or CLI refresh; cached/manual-only enrichment or an explicit opt-in is safer.

Full review comments:

  • [P1] Avoid browser import on the normal OAuth/CLI refresh path — Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift:70-74
    The current enrichment gate can enable prepaid-balance fetching for the automatic cookie source whenever optional usage is enabled, even if legacy web extras are disabled. That lets a successful OAuth or CLI refresh enter browser-cookie discovery/import and wait for its timeout or prompt path. Keep the completed primary result independent of automatic import; use a manual/already-cached session or an explicit opt-in, and cover the no-cached-cookie case. This is a follow-up to the earlier review concern, but targets the newer descriptor gating introduced after that review.
    Confidence: 0.82

Overall correctness: patch is incorrect
Overall confidence: 0.82

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cc8da27cec92.

Labels

Label changes:

  • add P2: This is a useful user-facing feature, but its remaining blocker is a bounded compatibility and refresh-latency risk rather than an already-shipped outage.
  • add merge-risk: 🚨 availability: A browser import can wait for the web timeout or prompt path, delaying otherwise completed usage refreshes.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body now includes a menu screenshot that directly demonstrates the user-visible prepaid-balance presentation; the remaining blocker is refresh-path safety, not missing visual proof.
  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR body now includes a menu screenshot that directly demonstrates the user-visible prepaid-balance presentation; the remaining blocker is refresh-path safety, not missing visual proof.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (screenshot): The PR body now includes a menu screenshot that directly demonstrates the user-visible prepaid-balance presentation; the remaining blocker is refresh-path safety, not missing visual proof.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: ⏳ waiting on author.
  • remove P3: Current review triage priority is P2, so this older priority label is no longer current.

Label justifications:

  • P2: This is a useful user-facing feature, but its remaining blocker is a bounded compatibility and refresh-latency risk rather than an already-shipped outage.
  • merge-risk: 🚨 compatibility: Automatic balance enrichment can change existing OAuth or CLI refresh behavior by initiating browser-cookie import for users who did not enable legacy web extras.
  • merge-risk: 🚨 availability: A browser import can wait for the web timeout or prompt path, delaying otherwise completed usage refreshes.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (screenshot): The PR body now includes a menu screenshot that directly demonstrates the user-visible prepaid-balance presentation; the remaining blocker is refresh-path safety, not missing visual proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body now includes a menu screenshot that directly demonstrates the user-visible prepaid-balance presentation; the remaining blocker is refresh-path safety, not missing visual proof.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR body now includes a menu screenshot that directly demonstrates the user-visible prepaid-balance presentation; the remaining blocker is refresh-path safety, not missing visual proof.

Evidence

Acceptance criteria:

  • [P1] swift test --filter 'ClaudeOAuthFetchStrategyAvailabilityTests|ClaudeWebFetchDeadlineTests|ClaudeWebCookieRenewalTests'.
  • [P1] swift test --filter 'ClaudeOAuthTests|ClaudeWebUsageExtraWindowTests|ClaudeProviderImplementationTests|ClaudeMenuCardCostTests|CLIOutputTests'.
  • [P1] make check.
  • [P1] make test.

What I checked:

  • Automatic enrichment remains on the refresh path: The PR’s Claude descriptor enables prepaid-balance enrichment for app refreshes with optional usage enabled whenever web enrichment is available, while its fetcher configuration adds a separate prepaid-balance path. The prior review identified that the automatic cookie source can invoke browser-cookie import even when legacy web extras are disabled. (Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift:70, aebe9fd75579)
  • Repository policy against prompt-prone imports: The repository policy says cookie imports should default to Chrome-only where possible to avoid browser prompts, and advises using non-live seams rather than Keychain/browser paths for ordinary validation. The proposed automatic enrichment needs to preserve that boundary. (AGENTS.md:48, cc8da27cec92)
  • Focused coverage does not prove the automatic no-cookie path: The PR adds substantial OAuth-fetch-strategy and web-deadline coverage, including manual-cookie enrichment and prepaid-request cancellation, but the provided diff does not show a regression test that an automatic cookie source with no cached Claude session returns completed OAuth or CLI usage without starting a browser import. (Tests/CodexBarTests/ClaudeOAuthFetchStrategyAvailabilityTests.swift:53, aebe9fd75579)
  • Visible behavior proof: The current PR body includes a compact CodexBar menu screenshot intended to show the new prepaid-balance presentation after the latest update; it is useful real UI proof for the rendered menu result, although it does not exercise the automatic-cookie fallback concern. (aebe9fd75579)
  • Related earlier report: The PR links Not detecting Claude credit usage correctly #975, which was closed after reporting confusing Claude credit/limit presentation. This PR overlaps that display area but adds a distinct remaining-balance value rather than reopening the prior report’s exact behavior.

Likely related people:

  • steipete: The repository owner is the strongest available routing candidate for the existing Claude provider and browser-session policy; local git provenance inspection could not run in this read-only environment. (role: likely follow-up owner; confidence: low; commits: cc8da27cec92; files: Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift, Sources/CodexBarCore/Providers/Claude/ClaudeUsageFetcher.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Prevent automatic browser-cookie import from delaying OAuth or CLI refreshes when only prepaid-balance enrichment is requested.
  • Add a focused regression test for automatic cookie source with no cached Claude web session.
  • Re-run the existing focused Claude strategy/deadline tests and make check after the guard is added.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-07-24T22:54:09.947Z sha 216d997 :: needs real behavior proof before merge. :: none

@Zihao-Qi
Zihao-Qi marked this pull request as ready for review July 24, 2026 23:24

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 216d9973d2

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +406 to +408
let includePrepaidBalance = context.runtime == .app &&
context.includeOptionalUsage &&
webEnrichmentAccess.isAvailable

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid blocking OAuth refreshes on automatic cookie import

With the default app settings (showOptionalCreditsAndExtraUsage enabled and Claude cookie source .auto), this makes every successful OAuth/Auto refresh await applyWebExtrasIfNeeded, even when web extras are disabled. That path invokes the generic browser-cookie importer and can wait for the 60-second context.webTimeout; therefore, when no cached Claude cookie exists or browser database/Keychain access stalls, an already-completed OAuth result is delayed and non-Chrome browsers may be probed or prompt. Restrict balance enrichment to cached/manual sessions or an explicit browser-import opt-in.

AGENTS.md reference: AGENTS.md:L48-L48

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. labels Jul 25, 2026
@steipete
steipete merged commit f4b3978 into steipete:main Jul 28, 2026
15 of 17 checks passed
@steipete

Copy link
Copy Markdown
Owner

Merged after full verification, with the owner-approved access contract enforced: prepaid-balance web enrichment uses only an already-cached or manually-configured web session — Auto can never initiate browser-cookie discovery during ordinary OAuth/CLI refresh, and a no-cache regression pins that (primary results publish undelayed). Identity matching keeps balances scoped to the matching Claude account. Focused suite 22/22; exact-head CI fully green after one unrelated temp-file-race rerun (https://github.com/steipete/CodexBar/actions/runs/30392441349). Autoreview clean. Thanks @Zihao-Qi!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants