feat(usage): unified usage tracking with auth refresh (#9281)#9545
Open
CasualDeveloper wants to merge 1 commit into
Open
feat(usage): unified usage tracking with auth refresh (#9281)#9545CasualDeveloper wants to merge 1 commit into
CasualDeveloper wants to merge 1 commit into
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicates Found:1. PR #9301: feat(tui): add /usage command and sidebar usage section
2. PR #6905: feat: display Anthropic and OpenAI OAuth usage in status dialog and sidebar
3. PR #9069: feat: Multi-Account OAuth Rotation with Settings UI and CLI Enhancements
|
ba7d89c to
9ce0a41
Compare
06731ef to
a396eca
Compare
f0e277d to
60f388a
Compare
bd214cc to
a7d1cc1
Compare
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
4089f14 to
824997e
Compare
824997e to
7cdb698
Compare
ca4c730 to
aa38024
Compare
3db7c0e to
2e5be67
Compare
6 tasks
6c9a249 to
b3616d6
Compare
6 tasks
b3a7965 to
c59711c
Compare
This was referenced May 3, 2026
70bcfac to
d98eb27
Compare
beb4f97 to
b97f7bd
Compare
Adds Usage.Service as the shared usage tracking layer for OAuth-authenticated providers, including cached snapshots, in-flight fetch dedupe, token-scoped cache entries, usage.updated events, and OAuth refresh persistence with actionable Claude reauth errors. Exposes /usage through both the default Hono route and Effect HttpApi adapter, with OpenAPI/SDK support for explicit provider, refresh, and showUsageValueMode query parameters. Adds provider OAuth follow-up authorize/callback support for optional Copilot usage tracking, plus TUI /usage command parsing, usage dialog/sidebar display, idle refreshes, threshold toasts, and provider-specific usage formatting. Covers usage fetching, Copilot/OpenAI/Claude auth behavior, HttpApi parity, and TUI usage command/format/toast behavior.
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.
Summary
Adds built-in usage tracking for OAuth-authenticated providers: Anthropic Claude, GitHub Copilot, and OpenAI ChatGPT.
This PR implements
Usage.Serviceas the shared usage orchestration layer, exposesGET /usagethrough both the default Hono route and Effect HttpApi adapter, regenerates SDK/OpenAPI support, and adds terminal TUI surfaces. In the terminal TUI, users can view usage through a/usagedetail dialog and a sidebar Usage section./usageis the detailed all-provider view, while the sidebar remains configurable as a glance view.Web/app UI is intentionally left for a follow-up;
client.usage.get(...)is available for that future integration.Closes #9281
Related: #768
Supersedes #6905, #7837
Alternate implementation to #9301
Behavior
/usagerefreshes all authenticated usage providers and opens the detail dialog./usage --used//usage --remainingselect the display mode for that dialog invocation./usage --backgroundrefreshes all provider usage data and updates the shared sidebar resource without opening the dialog.tui.show_usage_provider_scopeapplies to the sidebar only (current/all).tui.show_usage_value_modecontrols the initial used/remaining display mode./usagefetches by explicitly refetching the shared usage resource.Core
Usage.Serviceas the source of truth for usage orchestration, storage, cache reads/writes,usage.updatedevents, in-flight fetch dedupe, and response assembly.GET /usageunder bothpackages/opencode/src/server/routes/instance/usage.tsand the Effect HttpApi usage group/handler.packages/opencode/src/usage/providers/for Anthropic Claude, GitHub Copilot, and OpenAI ChatGPT.Auth
AuthOAuthFollowup).provider.oauth.followup.authorize/provider.oauth.followup.callbackserver endpoints in both route adapters.copilot_internal/userusage data.TUI
/usagedialog with provider-specific windows, progress bars, reset labels, and credits/quota details.Follow-up
GET /usageendpoint, likely as a Usage tab in the existing top-right status popover rather than a custom side panel.Verification
bun typecheckfrompackages/opencodebun typecheckfrompackages/sdk/jsgit diff --checkbun test --timeout 120000 test/server/usage.test.ts test/server/usage-copilot.test.ts test/cli/tui/usage-command.test.ts test/cli/tui/usage-format.test.ts test/cli/tui/usage-toast.test.ts test/plugin/copilot-auth.test.ts test/server/httpapi-bridge.test.ts test/server/httpapi-provider.test.ts test/server/httpapi-sdk.test.ts test/cli/tui/editor-context.test.tsx94 tests pass in the targeted usage/HttpApi/TUI suite.
Push hook:
bun turbo typecheckpassed, 12/12 tasks.AI Assistance