feat(usage): track model-scoped limits from the API's limits array - #32
Open
mpecan wants to merge 2 commits into
Open
feat(usage): track model-scoped limits from the API's limits array#32mpecan wants to merge 2 commits into
mpecan wants to merge 2 commits into
Conversation
The claude.ai usage endpoint no longer populates the flat per-model fields. seven_day_sonnet, seven_day_opus and friends return null, and no new ones are added — a model-specific cap now appears only as an entry in the `limits` array, which names its own scope (scope.model.display_name, e.g. "Fable"). ClaudeMeter read seven_day_sonnet, so a model-specific cap showed nothing at all. Read `limits` instead and render a card per scoped entry. Because the API names its own scopes, a model released after this build surfaces with no code change. The flat five_hour/seven_day fields are kept as a fallback. - Replace UsageData.sonnetUsage with a ScopedUsageLimit list - Settings renders one toggle per reported model, stored as an opt-out set so a new model appears rather than hiding behind a switch nobody knows to flip - Migrate saved settings: show_sonnet_usage=false becomes hidden=["Sonnet"], which does not suppress other models - Move the ~/.claudemeter/usage.json contract into a UsageExportPayload owned by the repository layer; sonnet_usage stays as a deprecated alias so existing statusline scripts keep working Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Store shown_scoped_models rather than hidden_scoped_models, defaulting to empty. Opt-out meant a model the API started reporting would appear in the popover on its own, which is the app deciding for the user. Opt-in keeps the popover to what the user actually asked for; Settings still lists every model the API reports, so a new one stays discoverable without an app update. Migration follows the same rule: show_sonnet_usage=true becomes ["Sonnet"], and false (or absent) opts into nothing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 13, 2026
mpecan
added a commit
to mpecan/rusted-claude-meter
that referenced
this pull request
Jul 18, 2026
Write ~/.claudemeter/usage.json after every successful fetch, atomically (temp file + rename), so existing statusline integrations built against the Swift ClaudeMeter keep working when a user switches to this app. The typed UsageExportPayload mirrors ClaudeMeter's schema (eddmann/ClaudeMeter#32): scoped_usage is the general per-model form, and sonnet_usage stays as a deprecated alias for the scoped "Sonnet" entry when one exists. Export write failures are logged (eprintln!) but never fail the refresh itself. Bundles the disk-cache and export paths into a new PersistPaths struct so run_loop stays within the workspace's too-many-arguments lint threshold. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
guys can we pls merge this and release a new build? Would be very helpful for newer subscription plans. |
Author
|
@mohitakahalo FYI: I gave up and built a new one: https://github.com/mpecan/rusted-claude-meter/ |
|
Thanks @mpecan you are a life saver! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The usage endpoint no longer populates the flat per-model fields —
seven_day_sonnet,seven_day_opusand the rest returnnull, and no new ones are added. Model-specific caps now appear only as entries in thelimitsarray, which name their own scope:{ "kind": "weekly_scoped", "percent": 50, "resets_at": "...", "is_active": true, "scope": { "model": { "id": null, "display_name": "Fable" }, "surface": null } }ClaudeMeter reads
seven_day_sonnet, so it shows nothing for a model-specific cap.Change
Read
limitsand render a card per scoped entry. The API supplies the display name, so a model released after this build needs no code change. The flatfive_hour/seven_dayfields remain as a fallback.UsageData.sonnetUsagebecomes aScopedUsageLimitlistshown_scoped_models, empty by default): a new model is listed in Settings but stays out of the popover until switched onCompatibility
show_sonnet_usage: truemigrates toshown_scoped_models: ["Sonnet"];falseor absent opts into nothingusage.jsonmoves to aUsageExportPayloadowned by the repository layer.sonnet_usageis still emitted when a Sonnet limit exists;scoped_usageis the general formVerification
Run against the live API: fetches, decodes
limits, renders the card, writesscoped_usageto~/.claudemeter/usage.json.70 tests pass. The 8
MenuBarIconSnapshotTestsfailures are pre-existing, unrelated to this change, and fixed separately in #31.Not covered
spendobject (extra-usage credits) is unsurfacedscope.model.idis currentlynull🤖 Generated with Claude Code