Skip to content

Show the Claude usage-credit allowance in the agents panel - #12278

Open
kcarlson wants to merge 1 commit into
omacom:quattrofrom
kcarlson:agents-usage-credits
Open

kcarlson wants to merge 1 commit into
omacom:quattrofrom
kcarlson:agents-usage-credits

Conversation

@kcarlson

@kcarlson kcarlson commented Sep 17, 2026 •

Copy link
Copy Markdown

Anthropic's OAuth usage endpoint returns a spend object beside the rate limit windows. It is the monetary credit allowance Claude Code's own /usage screen draws, and it fills up the way a window does: a percentage of a cap, refilled with the billing month. The Claude collector already has that payload in hand when it reads the windows and dropped the object, so an account spending against its credits could sit at 100% of them with nothing in the panel to say so.

This reads it as one more window. The collector carries the amounts and the panel formats them, the way the prepaid balance section already splits that work.

The agents panel showing a Usage credits window under the rate limit windows

spend carries no reset stamp of its own; credits refill monthly, so the window resets on the first of the coming month, dated in the offset that day carries rather than today's.

Three ways it is not a rate limit window

  • The bar icon's alarm passes over it. Running credits down returns the account to its rate limit windows rather than stopping the next prompt, and a month-long window at 100% would hold the bar in alarm for weeks over money already spent. The screenshot above shows that: credits at 100%, the glyph calm, because the fullest rate limit window is the session at 10%.
  • The limits cache does not replay it. A cached percentage of a 5-hour or 7-day window is at worst hours old. A cached credit figure could misreport the account by weeks of spending, so it waits for a probe that reaches the endpoint.
  • An amount it cannot read is no window rather than a guess. A missing exponent is not assumed to mean cents, which would render a zero-decimal currency a hundredfold short, and two amounts in different currencies cannot be written as one line.

Accounts without credits are unchanged

A plan that never had credits carries no spend object, one with them switched off says so, and a prepaid ledger names credits rather than a money cap. None of those yield a window, and none of them cost the account the rate limit windows it does have.

Testing

test/shell.d/agent-usage-claude-limits-test.sh goes from 12 assertions to 40. The new ones cover the allowance being read, its reset date across a month end, a year end and a daylight-saving change, spending past the cap clamping the meter at full, a refund emptying it rather than dropping the row, every payload shape that means "no credits", the cache refusing to replay a money figure, the bar binding to a rate limit window instead of the fuller credit window, and the row's detail line in all four combinations of money and countdown.

Verification

  • test/shell.d/agent-usage-claude-limits-test.sh passes, as do the other agents suites: agents-panel, agent-usage-claude-scanner, agent-usage-update, agents-rename-migration, bar-widget-contract.
  • ./test/all: 8 of 244 files fail. Seven of them fail the same way on a clean quattro checkout and are unrelated — bar-icon-geometry, config, locate, omarchy-kernel-migration, runtime-smoke, snapper, unowned-system-paths (three of those want an omarchy-pkgs checkout this machine does not have). The eighth, manifest-entrypoints, failed under the full run but passes standalone on this branch and on quattro.
  • Each fix above was checked by reverting it and watching the matching assertion go red, so none of the new coverage is vacuous.
  • Verified in the running shell on Omarchy 4.0.4; the screenshot is this branch.

🤖 Generated with Claude Code

@llstrk

llstrk commented Sep 18, 2026

Copy link
Copy Markdown

Recommendation: preserve fresh cached credits; handle refunds consistently

Verified: all 40 supplied checks pass. With synthetic endpoint data, the PR adds the expected credit percentage, money detail and countdown; baseline displays only the rate window.

Finding 1: reopening the panel drops fresh credits

usable_cached_limits strips monetary entries before deciding whether to reuse the fresh successful response.

Successful fetch       Quick reopen (<15 seconds)
Session row            Session row
Credits + money   ->   [credits row missing]
                       No new endpoint probe

Impact: valid, recently fetched credit information disappears simply because the panel was reopened. This is not stale/error fallback behavior.

Requested change: retain the complete successful response during the reuse interval. Add a fresh mixed rate/credit-cache regression test.

After refresh: session and credit information visible

After quick reopen: credit information missing

Finding 2: refunds lose their money detail

The collector retains used: -5 with a zero meter, but the panel rejects the negative amount.

Impact: the row remains, but its monetary detail disappears.

Requested change: display the valid signed amount, or define a clamped display explicitly, rather than dropping monetary metadata.

Refund: zero-percent row remains without money detail

Test scope: actual UI with synthetic account data. Live billing/schema behavior, large-number layouts and other display sizes were not verified. Bar-alarm exclusion was checked through helper tests and source, not a dedicated visual test.

Automated AI review: Astra inspected the PR; Fable 5.1 and a separate Astra session produced independent initial assessments, then findings were checked against targeted tests and the running UI.

@kcarlson
kcarlson force-pushed the agents-usage-credits branch from c99ca6b to 8f4f7e4 Compare September 23, 2026 09:01
@kcarlson

Copy link
Copy Markdown
Author

Thanks, both fixed in 8f4f7e4.

  1. A reopen inside the reuse interval now returns the full cached answer, credits included. Credits are still left out when the cache is only a fallback. I added a test for a fresh cache with both kinds of window.
  2. The panel keeps a negative amount and shows it signed: -€5.00 / €500.00 spent.

@omarchybot omarchybot added the enhancement New feature or request label Sep 27, 2026
@jandrusk

Copy link
Copy Markdown

Credits next to the rate windows matches what Claude Code's own /usage shows — nice addition.

CONFLICTING against quattro (agents panel has moved a lot: #14040/#15110/#14563). Please rebase; if #15110 already covers weekly allowance UX, say whether this credit field is still distinct or can close.

@kcarlson
kcarlson force-pushed the agents-usage-credits branch from 8f4f7e4 to d6ba89a Compare October 13, 2026 16:47
@kcarlson

kcarlson commented Oct 13, 2026 •

Copy link
Copy Markdown
Author

Rebased onto quattro ("Show the Claude usage-credit allowance in the agents panel").

#15110 estimates a token allowance from local use. This PR shows the monetary credit allowance Anthropic reports, so they don't overlap.

Since the panel moved:

  • The credit row follows the compact layout, and the money spent is in its tooltip.
  • The new account autoswitch ignores credits, and so do the faster limit checks near the switch threshold. Running credits down doesn't stop a prompt.

@kcarlson
kcarlson force-pushed the agents-usage-credits branch from d6ba89a to 0aab099 Compare October 13, 2026 16:51
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found.

Summary

Adds Claude usage credits as a separate allowance row in the agents panel.

  • Claude accounts show monthly credits beside their usage limits.
  • Credit spending no longer drives the bar alarm or account switching.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Claude usage response] --> B[Rate-limit windows]
  A --> C[Enabled credits with readable amounts]
  C --> D[Usage credits row and money tooltip]
  B --> E[Bar alarm and account switching]
  C --> F[Cache]
  F --> G{Recent answer?}
  G -->|Yes| D
  G -->|No| H[Hide cached money]
Loading

Reviews (2) · Last reviewed commit: "Show the Claude usage-credit allowance i..." · Reviewed by Greptile

Anthropic's OAuth usage endpoint returns a `spend` object beside the rate
limit windows. It is the monetary credit allowance Claude Code's own
`/usage` screen draws, and it fills up the way a window does: a percentage
of a cap, refilled with the billing month. The collector already has that
payload in hand when it reads the windows and dropped the object, so an
account spending against its credits could sit at 97% of them with nothing
in the panel to say so.

Read it as one more window. The collector carries the amounts and the panel
formats them, the way the prepaid balance section already splits that work.
The window gets its own limit line, and hovering it reads:

  Usage credits: 97% used · resets in 13d 13h
  €487.15 / €500.00 spent

A refund can carry the spend below zero. The meter then reads empty and the
amount keeps its sign: "-€5.00 / €500.00 spent".

`spend` has no reset stamp of its own; credits refill monthly, so the window
resets on the first of the coming month, dated in the offset that day
carries rather than today's. A window past that reset drops its money with
its percentage, since the money belongs to the month that ended.

Ways this window is not a rate limit window:

  - Nothing that answers "what stops the next prompt" counts it: not the bar
    icon's alarm, not the account autoswitch, and not the faster limit
    checks that run while an account nears its switch threshold. Running
    credits down returns the account to its rate limit windows rather than
    stopping anything, and a month-long window at 100% would hold the bar in
    alarm, or an account over its threshold, for weeks over money already
    spent.
  - The limits cache is a fallback for it only while the cache is current.
    A cached percentage of a 5-hour or 7-day window is at worst hours old; a
    cached credit figure could misreport the account by weeks of spending.
    After a failed probe or a lapsed sign-in, money measured within the last
    15 minutes still comes back, the same span in which the panel counts
    numbers as live, so a refused re-check does not hide the row. Older
    money waits for a probe that reaches the endpoint.
  - An amount it cannot read is no window rather than a guess. A missing
    exponent is not assumed to mean cents, which would render a zero-decimal
    currency a hundredfold short, and two amounts in different currencies
    cannot be written as one line.

An account without credits gets no such window and is unchanged: a plan that
never had them carries no `spend` object, one with them switched off says so,
and a prepaid ledger names credits rather than a cap. None of those yield a
window, and none of them cost the account the rate limit windows it does have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kcarlson
kcarlson force-pushed the agents-usage-credits branch from 0aab099 to a564c4a Compare October 28, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants