Skip to content

Show Claude weekly usage by product - #5170

Open
Lemelson wants to merge 2 commits into
steipete:mainfrom
Lemelson:feat/claude-weekly-product-breakdown
Open

Lemelson wants to merge 2 commits into
steipete:mainfrom
Lemelson:feat/claude-weekly-product-breakdown

Conversation

@Lemelson

@Lemelson Lemelson commented Nov 23, 2026 •

Copy link
Copy Markdown

Summary

The claude.ai usage response that CodexBar's Claude web source already fetches (GET /api/organizations/{org}/usage) includes a seven_day_breakdown block that splits the week's usage across products. CodexBar has ignored it so far. This PR decodes it and shows the nonzero shares, largest first, as plain rows in the existing provider detail section ("Usage breakdown") beneath the weekly bar. It uses the same seam and style as Grok's product breakdown (#3988, #4041). There are no new requests, no new UI components, no menu code changes, and no new localization keys: the section title reuses the existing localized "Usage breakdown" string, and row labels come from the response's display_name.

  • ClaudeWeeklyProductBreakdown (new, 75 lines) decodes rows[].key, display_name (falls back to key) and percent. It ignores unknown keys. A missing block, any malformed row (missing or blank key, non-numeric/boolean/out-of-range percent) or shares that do not add up to 100 ± 2 (integer rounding across four rows) drop the whole breakdown. The weekly window is left as is.
  • The value travels WebUsageData → ClaudeUsageSnapshot → UsageSnapshot.details. It is only added when the same snapshot has the weekly window, so shares never appear without the bar they split. The OAuth response type decodes the same key with the same decoder, in the same way iguana_necktie cloud credits already work.
  • Values are shares of this week's usage (percent). They are not separate quotas and never change the weekly percentage.

Why the API does expose a breakdown

#4123 was closed on the premise that the Claude usage API reports only combined weekly windows. That holds for the windows themselves, but the web usage response also returns this block beside seven_day. Redacted from a Max account today:

"seven_day": { "utilization": 71, "resets_at": "…" },
"seven_day_breakdown": {
  "as_of": "2026-11-23T21:18:29.513999+00:00",
  "window_started_at": "2026-11-17T10:00:00.494918+00:00",
  "rows": [
    {"key": "claude_code", "display_name": "Claude Code", "percent": 96, "percent_of_limit": 68},
    {"key": "chat",        "display_name": "Chats",       "percent": 1,  "percent_of_limit": 1},
    {"key": "cowork",      "display_name": "Cowork",      "percent": 3,  "percent_of_limit": 2},
    {"key": "other",       "display_name": "Other",       "percent": 0,  "percent_of_limit": 0}
  ]
}

The field was present in all 208 stored responses over the last ~19 hours (2026-11-23), across three accounts. The reporter's September sample in #4123 has the same shape without percent_of_limit. That is why this PR keys on percent, the field both shapes have. percent_of_limit (points of the weekly limit, which sum to seven_day.utilization) would be a one-line switch if you would rather have the rows add up to the bar, the way Grok's do.

Screenshot

Synthetic render of the production UsageMenuCardView from the redacted fixture. It is rendered offscreen to PNG by ClaudeWeeklyProductBreakdownRenderTests (skipped unless CODEXBAR_CLAUDE_PRODUCT_PROOF_DIR is set). No app launch, account, network request or credential access is involved.

Before After
Before, light After, light
Before, dark After, dark

Live run against claude.ai

CodexBarCLI built from this branch (e59c964) and run on a Max account on 2026-11-24, fetching the real claude.ai usage response with the user's existing browser session. Only the account line is redacted:

$ .build/debug/CodexBarCLI usage --provider claude --source web --no-color
== Claude (web) ==
Session: 97% left [===========-]
Pace: 47% in reserve | Expected 50% used | Lasts until reset
Resets in 2h 30m
Weekly: 96% left [===========-]
Pace: 4% in reserve | Expected 8% used | Lasts until reset
Resets in 6d 10h
Limit Reset Credits: 2 available · Expires Dec 10 at 11:00 PM
Claude Code: 65%
Cowork: 22%
Chats: 13%
Account: <redacted>
Plan: Claude Max 5x

The last three usage rows are the new breakdown: decoded from the live seven_day_breakdown, nonzero shares only, largest first, and they sum to 100. They are shares of this week's 4% usage, so the weekly bar is unchanged. One caveat about the build: this machine runs the macOS 27.2 beta (26B5091g), whose Foundation lacks the Date >=/<= symbols that Xcode 27.2 links against, so the local build carried an uncommitted shim that defines those two operators with the same semantics. The shim is not part of this PR.

Verification

Swift commands ran with CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1, CODEXBAR_TEST_CODEX_FILE_ISOLATION=1 and CODEXBAR_TEST_SESSION_FILE_ISOLATION=1.

  • swift test --filter ClaudeWeeklyProductBreakdown: 6 Swift Testing tests passed, including 15 absent/malformed cases. The XCTest render test was skipped (no proof dir set).
  • CODEXBAR_CLAUDE_PRODUCT_PROOF_DIR=… swift test --filter ClaudeWeeklyProductBreakdownRenderTests: passed and wrote before/after light/dark PNGs.
  • swift test --filter 'ClaudeCloudCredits|ClaudeWeb|ClaudeOAuthUsage|ClaudeUsage|ClaudeMenuCard|ProviderDetailSection|ClaudeWeeklyProductBreakdownTests': 186 tests in 23 suites passed.
  • make check: passed (0 SwiftLint violations in 3262 files; app locales, widget catalogs and provider docs OK).
  • Full suite: left to CI.

Not verified: whether api.anthropic.com/api/oauth/usage also returns seven_day_breakdown. The OAuth path decodes it if present, and nothing changes if it is absent. The live run above used the web source only.

Refs #4123

🤖 Generated with Claude Code

Decode the seven_day_breakdown block of the Claude usage response and list
nonzero product shares in a Usage breakdown detail section beneath the
weekly bar. Malformed rows or shares that do not compose 100% drop the
breakdown without touching the weekly window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clawsweeper

clawsweeper Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-05T00:42:11.056817Z dcf48a5 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 23, 2026
@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. 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. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 23, 2026
@clawsweeper

clawsweeper Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codex review: ready, awaiting a maintainer decision.

What this changes

This PR displays Claude’s weekly usage shares by product through existing menu and CLI detail rows.

Example: Claude reports 4% weekly usage split between Claude Code 65%, Cowork 22%, and Chats 13%.

  • Before: The CLI shows the weekly allowance without its product split.
  • After: The CLI adds the three product shares while preserving the weekly allowance.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused implementation with live CLI proof and supporting parser/render coverage; overall readiness is capped by the unresolved product decision.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Lemelson’s added terminal capture exercises the changed Web parser, snapshot mapping, and shipped CLI renderer against a real Max account at the reviewed head, resolving the prior proof gap; OAuth availability remains expressly unverified and optional.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Users can see their combined weekly usage but cannot identify which Claude product consumed it.
Reason: The feature has concrete user value and reuses an established presentation, but its direction has no recorded owner approval on this PR or the linked issue.

Merge readiness

⏳ Ready, awaiting maintainer decision

Keep open for a product decision: current main omits the reported Claude product split, and this focused implementation has no identified correctness blocker.

Reviewed head: e59c964f0300c2a439360e1875729e349c6ff194
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should Claude display product shares of weekly consumption as default detail rows?
  • Recommendation: Approve consumption shares: Accept the proposed percentages summing to approximately 100%, preserving the weekly quota percentage.
  • Why: The linked owner response deferred the feature pending available data; the new samples establish availability, but do not record approval of this display or its percentage denominator.

Before merge

None.

Findings

None.

Agent review details

How this fits together

Claude Web and OAuth response parsers feed a shared usage snapshot, whose detail sections reach the native menu and CLI renderers.

flowchart LR
  A[Claude usage response] --> B[Web or OAuth parser]
  B --> C[Validated product shares]
  C --> D[Claude usage snapshot]
  D --> E[Provider detail sections]
  E --> F[Native menu]
  E --> G[CLI output]
Loading

Technical review

Best possible solution:

Retain the shared optional decoder and existing renderers if the owner approves showing shares of weekly consumption.

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

This is an additional display capability; source inspection confirms main ignores the field, and the supplied live CLI output demonstrates the proposed behavior.

Is this the best way to solve the issue?

A shared decoder feeding existing detail sections is a focused implementation that preserves quota calculations and isolates malformed optional data.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a26ca57b5186.

Provenance checked

  • Claude optional response data and shared detail construction keeps the original intent (745bf89: Expose cloud-session credits from existing responses while preserving ordinary quotas and tolerating malformed optional data.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned change: The introduced diff adds one shared decoder and threads its optional result through both provider sources into existing detail sections. (Sources/CodexBarCore/Providers/Claude/ClaudeWeeklyProductBreakdown.swift:5, e59c964f0300)
  • Current main lacks the display: Main’s Web parser does not read seven_day_breakdown, and its shared snapshot builder publishes reset inventory, model notices, and cloud credits without product shares. (Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift:818, a26ca57b5186)
  • Owner discussion and new API evidence: In Claude: show weekly usage breakdown by product #4123 (comment), steipete closed the request because no product breakdown was available; floriankilian’s original report and Lemelson’s subsequent sample document the seven_day_breakdown field.
  • Live shipped-entry-point proof: The PR body records a real Max-account Web fetch through CodexBarCLI at the reviewed head, producing Claude Code 65%, Cowork 22%, and Chats 13%; it discloses an uncommitted Date comparison compatibility shim. Captured body sourceRevision: 1bd6c7b1619cf923fae71ce85be25365d805b1d496e4280884a539bd858fceca. (e59c964f0300)
  • Inspected visual evidence: All four prepared images were inspected locally: the synthetic light and dark after-images add correctly ordered product rows beneath the unchanged weekly bar.
  • Existing storage compatibility: The change uses the existing Codable details array and row shape; absent details already decode as an empty array, so no stored-format migration or preference rewrite is introduced. (Sources/CodexBarCore/UsageFetcher.swift:406, e59c964f0300)

Likely related people:

  • Peter Steinberger: Raw commit 85607bb adds Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift:819 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 85607bbd4c39; files: Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift)
  • dylanstieri: Raw commit 745bf89 adds Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift:757 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 745bf89a3fc3; files: Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Change allocation Production +91/-2 lines; tests +182; documentation +13 Production growth is concentrated in one decoder reused by both provider sources.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #4123
Summary: This PR implements the product-share display requested in the closed issue with additional response and runtime evidence.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • 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 maintainer.
  • remove proof: 📸 screenshot: Current real behavior proof evidence kind is terminal.

Label justifications:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rank-up moves

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

  • Record the owner’s decision on displaying consumption shares.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-23T21:57:00.382Z sha e59c964 :: needs real behavior proof before merge. :: none

Reviewed November 28, 2026, 7:16 AM ET / 12:16 UTC (Revision 2).

@Lemelson

Copy link
Copy Markdown
Author

Added a live run against claude.ai to the description (CLI from this branch, real seven_day_breakdown, account redacted).

@clawsweeper re-review

@Lemelson

Copy link
Copy Markdown
Author

@clawsweeper re-review

The description now has a live run against claude.ai: CodexBarCLI built from this branch fetched the real seven_day_breakdown and printed the new rows (account redacted).

@Lemelson

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. 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. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. labels Nov 28, 2026

This branch has not been deployed

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

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants