[PR #9301] feat(tui): add /usage command and sidebar usage section #13061

Open
opened 2026-02-16 18:17:56 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9301

State: open
Merged: No


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)

Sidebar Documentation
Added documentation for the TUI sidebar feature with screenshot showing how to toggle it with ctrl+x b.

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)

This support was added because so many people use https://github.com/NoeFabris/opencode-antigravity-auth to connect to Antigravity

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
Usage dialog showing provider quota

Sidebar Usage
Sidebar with usage section

Sidebar Usage (Copilot)
Sidebar showing Copilot usage

Usage Remaining View
Usage dialog showing remaining quota

Copilot Auth Flow
Copilot device flow authentication

Sidebar Toggle
OpenCode TUI Sidebar

Implementation Details

  • Created a new @/usage module 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
Closes #768

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9301 **State:** open **Merged:** No --- ## 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) **Sidebar Documentation** Added documentation for the TUI sidebar feature with screenshot showing how to toggle it with `ctrl+x b`. ### 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) This support was added because so many people use https://github.com/NoeFabris/opencode-antigravity-auth to connect to Antigravity 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** ![Usage dialog showing provider quota](https://i.ibb.co/spmyNtPC/image-1.png) **Sidebar Usage** ![Sidebar with usage section](https://i.ibb.co/HDfW81tM/image-2.png) **Sidebar Usage (Copilot)** ![Sidebar showing Copilot usage](https://i.ibb.co/nNSnR50v/image-5.png) **Usage Remaining View** ![Usage dialog showing remaining quota](https://i.ibb.co/RkhYxKCM/image-3.png) **Copilot Auth Flow** ![Copilot device flow authentication](https://i.ibb.co/Pz3xN0bV/image.png) **Sidebar Toggle** ![OpenCode TUI Sidebar](https://i.ibb.co/tTfzf0cx/image-4.png) ### Implementation Details - Created a new `@/usage` module 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 Closes #768
yindo added the pull-request label 2026-02-16 18:17:56 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13061