Skip to content

[FEATURE] Add unified usage tracking via /usage (#9545) #9281

Description

@CasualDeveloper
  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

When you sign in to opencode with an OAuth provider, there's no built-in way to see how much of your plan or rate limit you've used. You have to open each provider's dashboard. I'd like usage to be visible inside opencode for the providers it already authenticates.

The feature now covers:

  • Usage for four OAuth providers: Anthropic Claude, GitHub Copilot, OpenAI ChatGPT, and Google Antigravity.
  • A GET /usage endpoint that returns a normalized snapshot per provider (rate-limit windows, reset times, credits or quota, and plan type), each with a status such as ok, stale, or unauthenticated.
  • A /usage TUI dialog and a sidebar Usage section, with config for provider scope and whether to show used or remaining. End-of-turn refresh is throttled and only warns at 80/90/95%.
  • Copilot usage reads quota with the same GitHub device token the normal Copilot login already stores, so it needs no extra setup.

Activity

  1. github-actions commented on Jan 18, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. CasualDeveloper commented on Jan 18, 2026

    @CasualDeveloper
    ContributorAuthor

    Thanks for the pointer. Related to #768 for Copilot quota visibility, but this issue is broader: adds a unified /usage API + TUI surfaces for codex/copilot/claude (including 5h/7d/Opus 7d windows) and is not limited to Copilot premium requests. I'll keep #768 referenced here.

    AI Assistance: OpenCode + openai/gpt-5.2-codex; human reviewed.

  3. improdead commented on Jan 18, 2026

    @improdead

    Hey made an pr about this with images check it out :)
    so copilot we need a separate authentication flow since uage data is is not accessible through the one in auth.json and also added antigravity for the plugin Antigravity + Gemini CLI OAuth Plugin for Opencode due to large popularity

  4. 41 remaining items

  5. slkiser commented on Apr 18, 2026

    @slkiser

    Workaround: my plugin solves this for most providers: https://github.com/slkiser/opencode-quota

  6. CasualDeveloper commented on Apr 18, 2026

    @CasualDeveloper
    ContributorAuthor

    Rebased #9545 onto the latest dev again.

    Still applies on current server/routes/instance/ server layout and tui.json-backed TUI config architecture. Verified locally with bun run typecheck, bun turbo typecheck, and bun --cwd packages/opencode test --timeout 600000 test/plugin/copilot-auth.test.ts 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 (48 tests pass).

    If maintainers want a different direction, happy to rework it.


    Workaround: my plugin solves this for most providers: slkiser/opencode-quota

    also, whoa @slkiser - good work, that provider coverage is wide! lol

    IMO our approaches are complementary - users can pick either: the broader coverage your plugin offers (13+ providers), or mine which covers a narrower set (OpenAI/Anthropic/GitHub) as a built-in with first-party OAuth flows only (no PATs / CLI shell-outs / scraping), so those three work out-of-box with no separate install step :P

    Structure's provider-based too (one file per provider under src/usage/providers/ + a central registry), so the core set can grow, or maybe expose a plugin hook later that lets plugins like yours register their own providers into the same sidebar / /usage / toast pipeline. :)

  7. CasualDeveloper commented on Apr 26, 2026

    @CasualDeveloper
    ContributorAuthor

    Fork updated to sync with dev (as of 5a5a2e5fa) and pushed at 3db7c0eb8.

    Recent behavior cleanup:

    • /usage now always fetches all authenticated usage providers and opens the detail dialog.
    • /usage --used / /usage --remaining only select display mode.
    • /usage --refresh refreshes all provider caches and updates the sidebar without opening the dialog.
    • tui.show_usage_provider_scope is sidebar-only now; the dialog is the detailed all-provider view.
    • The sidebar no longer relies on usage.updated event/SSE refresh. /usage and end-of-turn refresh explicitly refetch the shared sidebar resource to avoid the previous feedback-loop risk.

    Scope clarification: this PR adds shared backend/API + SDK support and terminal TUI surfaces. Web/app UI is intentionally left for a follow-up, likely as a Usage tab in the existing top-right status popover rather than a custom side panel.

    Verified with ./script/generate.ts, bun turbo typecheck, and the targeted usage suite (48 tests pass).

  8. m13v commented on Apr 30, 2026

    @m13v

    the /usage endpoint being the single source of truth is the right call. the trap people fall into is parsing rate-limit headers or counting local tokens, then their numbers drift from what claude.ai actually shows. ccusage reads jsonl logs, claude-code-usage-monitor estimates, neither sees the server quota anthropic actually enforces. only the internal endpoint that powers claude.ai/settings/usage gives you the real 5h and weekly windows. one note on the 401 question, claude's session cookie expires silently and you wont know until the next fetch returns nothing useful, surfacing a reauth hint inline beats a refresh loop because the cookie path is browser-bound anyway.

  9. CasualDeveloper commented on Jun 6, 2026

    @CasualDeveloper
    ContributorAuthor

    Quick update: the fork branch has been refreshed and synced to origin/dev at 4519a1d.

  10. CasualDeveloper commented on Jul 27, 2026

    @CasualDeveloper
    ContributorAuthor

    Refreshed #9545 to 805bc10ce4.

    The latest follow-up removes persistent usage cache files in favor of a process-local active-credential cache. Cache writes recheck current auth before replacing a superseded identity, so late requests cannot displace current data. Copilot now reports GitHub's independent credits_used AI-credit meter separately from entitlement-based quota percentages.

    Verification: workspace typecheck 30/30, focused server/API tests 100/100, TUI 223 passed with 1 skip, and HttpApi coverage/auth/effect modes 209/209 each. The PR body has the current scope and commands.

  11. github-actions commented on Sep 26, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  12. NicHub commented on Sep 28, 2026

    @NicHub

    Still reproducible in OpenCode v2.0.18 on macOS 26.6 (arm64), using Ghostty and zsh.

    With OpenAI ChatGPT OAuth, OpenCode’s /status does not show the subscription usage windows available in Codex. Codex’s /status reports the consumed allowance and reset times for the rolling and weekly limits, while OpenCode provides no equivalent information.

    opencode stats --cost is not a workaround: it reports locally recorded token and cost statistics, not the remaining provider-side subscription allowance or its reset times.

    It would be useful to expose these provider-reported limits through /status or /usage, clearly separated from session context usage and local cost estimates. This would let users anticipate rate limits without leaving the TUI.

    Environment:

    • OpenCode: v2.0.18, latest release
    • OS: Darwin 25.6.0, arm64
    • Terminal: Ghostty, xterm-256color, truecolor
    • Shell: zsh
    • Active local plugin: herdr-agent-state.js (unrelated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions