You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE] Add unified usage tracking via /usage (#9545) #9281
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.
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.
Reacted by Dmitry Gordienko, Salloxy and Wiktor Golicz
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
Reacted by Stephen Collings, Dekai Li and Benoit de Chezelles
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.
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. :)
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).
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.
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.
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)
Activity
github-actions commentedon Jan 18, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
CasualDeveloper commentedon Jan 18, 2026
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.
improdead commentedon Jan 18, 2026
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
41 remaining items
slkiser commentedon Apr 18, 2026
Workaround: my plugin solves this for most providers: https://github.com/slkiser/opencode-quota
CasualDeveloper commentedon Apr 18, 2026
Rebased
#9545onto the latestdevagain.Still applies on current
server/routes/instance/server layout andtui.json-backed TUI config architecture. Verified locally withbun run typecheck,bun turbo typecheck, andbun --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.
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. :)CasualDeveloper commentedon Apr 26, 2026
Fork updated to sync with
dev(as of5a5a2e5fa) and pushed at3db7c0eb8.Recent behavior cleanup:
/usagenow always fetches all authenticated usage providers and opens the detail dialog./usage --used//usage --remainingonly select display mode./usage --refreshrefreshes all provider caches and updates the sidebar without opening the dialog.tui.show_usage_provider_scopeis sidebar-only now; the dialog is the detailed all-provider view.usage.updatedevent/SSE refresh./usageand 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).m13v commentedon Apr 30, 2026
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.
CasualDeveloper commentedon Jun 6, 2026
Quick update: the fork branch has been refreshed and synced to origin/dev at 4519a1d.
CasualDeveloper commentedon Jul 27, 2026
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_usedAI-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.
github-actions commentedon Sep 26, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.
NicHub commentedon Sep 28, 2026
Still reproducible in OpenCode v2.0.18 on macOS 26.6 (arm64), using Ghostty and zsh.
With OpenAI ChatGPT OAuth, OpenCode’s
/statusdoes not show the subscription usage windows available in Codex. Codex’s/statusreports the consumed allowance and reset times for the rolling and weekly limits, while OpenCode provides no equivalent information.opencode stats --costis 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
/statusor/usage, clearly separated from session context usage and local cost estimates. This would let users anticipate rate limits without leaving the TUI.Environment:
herdr-agent-state.js(unrelated)