feat(tui): add /usage command and sidebar usage section
Summary
This PR adds the ability for users to view their AI provider quota usage directly within OpenCode. Users can now easily monitor how much of their rate limits they've consumed across different providers like OpenAI, Anthropic, GitHub Copilot, and Google/Antigravity.
With more and more people using plugins like GitHub Copilot and Antigravity (Google), having visibility into rate limits has become increasingly important. This feature helps users avoid hitting quota limits unexpectedly during their coding sessions.
What's New
/usage Command
A new dialog that shows detailed usage information for your current AI provider:
- Visual progress bars showing quota consumption
- Reset time countdowns (e.g., "Resets in 2h 30m")
- Toggle between "used" and "remaining" views with the Tab key
- Special handling for GitHub Copilot with built-in device flow authentication
- Shows "Unlimited" for pay-per-use providers like OpenCode Zen
Sidebar Usage Section A compact usage display in the sidebar that:
- Shows the current provider's quota at a glance
- Automatically refreshes after each assistant turn completes
- Refreshes when you switch to a different model/provider
- Can be hidden by clicking the ✕ button
- Can be restored by clicking "Show usage" in the Context section
- Only displays when usage data is available (no errors shown if provider doesn't support it)
Supported Providers
| Provider | API Endpoint | Notes |
|---|---|---|
| OpenAI | chatgpt.com/backend-api/wham/usage |
ChatGPT Plus/Pro quotas |
| Anthropic | api.anthropic.com/api/oauth/usage |
Claude rate limits |
| GitHub Copilot | api.github.com/copilot_internal/user |
Uses separate device flow auth |
| Google/Antigravity | Google cloudcode API | Vertex AI quotas |
GitHub Copilot
GitHub Copilot requires a separate authentication flow since usage data isn't accessible through the regular Copilot tokens. When you first try to view Copilot usage, you'll be prompted to authenticate with a device code flow using a Copilot-specific client ID. The token is stored separately at ~/.local/share/opencode/usage-copilot.json so it doesn't interfere with your regular Copilot authentication.
Antigravity (Google)
With Antigravity becoming a popular choice for accessing Google's models through OpenCode, this PR adds support for fetching usage data from Google's cloudcode API. This gives Antigravity users the same visibility into their quota consumption as other providers.
Screenshots
Usage Dialog

Sidebar Usage Section

Sidebar Usage (Copilot)

Toggle View (Remaining)

Copilot Authentication Flow

Implementation Details
- Created a new
@/usagemodule with provider-specific implementations - Each provider gracefully handles 401/403 errors without crashing
- Copilot uses its own client ID (
Iv1.b507a08c87ecfe98) and stores tokens separately - Sidebar usage can be dismissed and restored via KV store preference
- Sidebar usage refreshes when switching models/providers
Closes #9281
The following comment was made by an LLM, it may be inaccurate:
Found potential related PRs:
-
PR #6905 - feat: display Anthropic and OpenAI OAuth usage in status dialog and sidebar
- https://github.com/anomalyco/opencode/pull/6905
- This PR already implements similar functionality for displaying usage in a sidebar and dialog, specifically for Anthropic and OpenAI providers
-
PR #7837 - feat: add usage tracking API and /usage dialog
- https://github.com/anomalyco/opencode/pull/7837
- This PR appears to add usage tracking and a /usage dialog, which overlaps with the core feature of PR #9301
-
PR #9069 - feat: Multi-Account OAuth Rotation with Settings UI and CLI Enhancements
- https://github.com/anomalyco/opencode/pull/9069
- May be related to OAuth handling for provider authentication
Why they're related: PRs #6905 and #7837 appear to address the same core feature set - displaying AI provider usage information through both a /usage command dialog and sidebar integration. You may want to review these older PRs to understand if they were closed/abandoned, superseded, or if this PR is building upon them.
@thdxr hey Dax added /usage like in claude code for all major connectors please check it out man
tested github-copilot. banger
can someone test claude I dont have it lol
@improdead lol i created my issue in preparation of my own pr which i'm currently testing, because the previous prs didn't have linked issues. i'll check out your implementation
@improdead lol i created my issue in preparation of my own pr which i'm currently testing, because the previous prs didn't have linked issues. i'll check out your implementation
oh lol
Duplicate of #7837 . May need to be combined.
Duplicate of #7837 . May need to be combined. thanks for mentioning I took at look it shows the quota of all models at once all together while I show quota of the model user is currently using I think it is more convenient that way
Tried this on codex mode. Works great! Good job
Hey @improdead — I took a whack at my own implementation to close #9281 via an alternate approach in #9545.
Key differences:
-
/usageis server-side SSOT (GET /usage) vs client-driven fetchers - Config option
tui.show_usage_scopefor sidebar scope control -
/usage --current|--allflags to override config - Claude token auto-refresh on expiry (mirrors anthropic plugin behavior)
- Copilot usage token stored in
auth.jsonunderusagefield
Thanks for the initial exploration!
@rekram1-node Happy to accept and close if either PR covers the use case.