feat: Add (z.ai) plan usage tracking in the sidebar#6298
Open
albu wants to merge 1 commit intoanomalyco:devfrom
Open
feat: Add (z.ai) plan usage tracking in the sidebar#6298albu wants to merge 1 commit intoanomalyco:devfrom
albu wants to merge 1 commit intoanomalyco:devfrom
Conversation
phj1081
added a commit
to phj1081/opencode
that referenced
this pull request
Jan 5, 2026
…idebar - Add usage/anthropic.ts: fetch usage from Anthropic OAuth API - Add usage/openai.ts: fetch usage from OpenAI/ChatGPT backend API - Update dialog-status.tsx: show usage bars with reset times - Update sidebar.tsx: show compact usage display with progress bars Shows rate limit utilization percentages and reset times for: - Anthropic: 5-hour and 7-day windows - OpenAI: primary/secondary windows with plan type and credits Related to anomalyco#6298 (plan usage tracking)
CasualDeveloper
pushed a commit
to CasualDeveloper/opencode
that referenced
this pull request
Jan 16, 2026
…idebar - Add usage/anthropic.ts: fetch usage from Anthropic OAuth API - Add usage/openai.ts: fetch usage from OpenAI/ChatGPT backend API - Update dialog-status.tsx: show usage bars with reset times - Update sidebar.tsx: show compact usage display with progress bars - Add negative time handling in formatResetTime (return 'refreshing') - Add clamp for percent values in usage bars (0-100) - Add 10s timeout to fetch calls (AbortSignal.timeout) - Add NaN handling in formatCredits - Extract shared utils (getUsageColor, clampPercent, usageBarString) - Add refetch on message change for sidebar usage display - Remove unused refetch destructuring in dialog-status - Resolve infinite recursion in colorFor function - Correct function name to getUsageColor in dialog-status Shows rate limit utilization percentages and reset times for: - Anthropic: 5-hour and 7-day windows - OpenAI: primary/secondary windows with plan type and credits Related to anomalyco#6298 (plan usage tracking)
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
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.
Problem
When using LLM providers with quota limits (like zai-coding-plan), users have no visibility into their remaining quota or when it resets. This makes it difficult to track usage and avoid unexpected service interruptions.
Solution
Added plan usage display to the TUI sidebar that shows:
Implementation
Core abstraction (
src/provider/plan-usage.ts)Generic
PlanUsageinterface that all providers implement:Features:
registerProvider(id, handler)getPercentage(),formatResetTime()Provider implementation (
src/provider/plan-usage/zai.ts)/api/monitor/usage/quota/limitendpointTOKENS_LIMIT(ignores time-based limits)zai-coding-planhandlerUI integration (
sidebar.tsx)Adding support for other providers
The pattern uses side-effect imports. The core module imports provider modules, which register themselves on load.
Step 1: Add import to
src/provider/plan-usage.ts:Step 2: Create
src/provider/plan-usage/your-provider.ts:The handler receives:
token- API key from authbaseURL- Provider's base URL from configtimeout- Request timeout in ms (default 5000)And returns: