OpenCode plugin to display quota and costs for AI providers
npm install @mattdef/opencode-quotaA plugin for OpenCode that displays quota and cost information for your AI providers directly in the terminal.
- Real-time quota monitoring for configured AI providers
- Parallel fetching - All providers queried simultaneously
- Beautiful table output with color-coded usage indicators
- Error handling - Graceful degradation when providers are unavailable
- Zero configuration - Automatically reads OpenCode's auth.json
- ✅ Claude (Anthropic) - Quota-based
- ✅ GitHub Copilot - Quota-based
- ✅ OpenRouter - Pay-as-you-go
- ✅ Codex (OpenAI) - Quota-based
- ✅ Gemini CLI - Quota-based
- ✅ Kimi - Quota-based
- ✅ OpenCode Zen - Pay-as-you-go
- ✅ Antigravity - Quota-based
Add to your opencode.json:
``json`
{
"plugin": ["@mattdef/opencode-quota"]
}
That's it! OpenCode will automatically install the plugin on next startup.
If you prefer to install manually:
`bashCreate the plugin directory
mkdir -p ~/.config/opencode/plugins/opencode-quota
Usage
In OpenCode, simply type:
`
/quota
`The plugin will fetch and display quota information for all configured providers.
$3
-
/quota --all - Show all providers, including non-configured ones$3
`
Provider Type Usage Key Metrics
──────────────────────────────────────────────────────────────────────
Claude Quota-based 23% 77/100 remaining
GitHub Copilot Quota-based 45% 55/100 remaining
OpenRouter Pay-as-you-go - $12.34 spent
──────────────────────────────────────────────────────────────────────
Quota providers: 2 | Pay-as-you-go: $12.34
`$3
- 🟢 Green - Usage < 50%
- 🟡 Yellow - Usage 50-80%
- 🔴 Red - Usage > 80%
Configuration
No configuration required! The plugin automatically:
1. Reads authentication tokens from OpenCode's
auth.json
2. Searches multiple locations:
- $XDG_DATA_HOME/opencode/auth.json
- ~/.local/share/opencode/auth.json
- ~/Library/Application Support/opencode/auth.jsonTroubleshooting
$3
Make sure you have connected your providers in OpenCode:
`
/connect
`$3
If you see authentication errors, try reconnecting the provider:
`
/connect claude
/connect github_copilot
/connect openrouter
`$3
Check OpenCode logs for plugin loading errors:
`
opencode --verbose
`Development
$3
`
opencode-quota/
├── src/
│ ├── index.ts # Plugin entry point
│ ├── types/
│ │ └── index.ts # TypeScript interfaces
│ ├── providers/
│ │ ├── ClaudeProvider.ts # Claude implementation
│ │ ├── CopilotProvider.ts # Copilot implementation
│ │ ├── OpenRouterProvider.ts # OpenRouter implementation
│ │ ├── CodexProvider.ts # Codex implementation
│ │ ├── GeminiCLIProvider.ts # Gemini CLI implementation
│ │ ├── KimiProvider.ts # Kimi implementation
│ │ ├── OpenCodeZenProvider.ts # OpenCode Zen implementation
│ │ └── AntigravityProvider.ts # Antigravity implementation
│ ├── services/
│ │ ├── TokenManager.ts # Auth token management
│ │ ├── ProviderManager.ts # Parallel fetching
│ │ └── TableFormatter.ts # Output formatting
│ └── utils/
│ └── colors.ts # Terminal colors
├── package.json
└── tsconfig.json
`$3
`bash
npm install
npm run build
`$3
`bash
npm login
npm publish --access public
`$3
1. Create a new provider class in
src/providers/:`typescript
import { ProviderProtocol, ProviderIdentifier, ProviderType, ProviderResult } from '../types/index.js';export class MyProvider implements ProviderProtocol {
readonly identifier = ProviderIdentifier.MY_PROVIDER;
readonly type = ProviderType.QUOTA_BASED; // or PAY_AS_YOU_GO
readonly fetchTimeout = 10000;
isConfigured(): boolean {
// Check if provider is configured
return true;
}
async fetch(): Promise {
// Implementation here
}
}
`2. Register in
ProviderManager.initializeProviders():`typescript
this.providers.set(ProviderIdentifier.MY_PROVIDER, new MyProvider());
`3. Add display name in
TableFormatter.getProviderDisplayName()`MIT License - See LICENSE file for details.
Based on the OpenCode Bar project by kargnas.