OpenCode plugin to query Z.ai GLM Coding Plan usage statistics including quota limits, model usage, and MCP tool usage
npm install opencode-glm-quota



---




OpenCode plugin to query Z.ai GLM Coding Plan usage statistics with real-time quota monitoring, model usage tracking, and MCP tool usage.
- š Query current quota limits (5-hour token cycle, monthly MCP usage)
- š¤ View model usage statistics (24-hour rolling window)
- š§ View MCP tool usage (web_search, web_reader, etc.)
- š Supports both Global (api.z.ai) and CN (open.bigmodel.cn) platforms
- š Automatic credential discovery via OpenCode authentication context
- š Visual progress bars for quota percentages (ASCII for terminal alignment)
- ā” Fail-fast error handling (no retry logic - user controls when to retry)
``bashInstall plugin
npm install opencode-glm-quota
What the installer does:
- Copies
/glm_quota command to ~/.config/opencode/command/glm_quota.md
- Copies skill documentation to ~/.config/opencode/skills/glm-quota/SKILL.md
- Automatically adds plugin to your OpenCode config
- Copies agent to ~/.config/opencode/agents/
- Supports --force flag to overwrite existing files$3
`bash
Remove OpenCode integration files and config
npx opencode-glm-quota uninstallIf installed globally
npx opencode-glm-quota uninstall --global
`What the uninstaller does:
- Removes
/glm_quota command
- Deletes skills/glm-quota/SKILL.md
- Removes plugin entry from OpenCode config
- Removes agent file and legacy config
- Runs npm remove opencode-glm-quota (or --global)$3
`bash
npm install github:guyinwonder168/opencode-glm-quota
`$3
`bash
Clone and build
git clone https://github.com/guyinwonder168/opencode-glm-quota.git
cd opencode-glm-quota
npm install
npm run buildLink for local testing
npm linkRun the installer for local testing
node bin/install.js
`Quick Start
Once installed, simply run the plugin command in OpenCode:
`bash
/glm_quota
`The plugin will automatically detect your credentials (from OpenCode authentication) and display your usage statistics.
Usage
$3
This plugin uses OpenCode's built-in authentication system. No manual configuration required.
Primary Method (Recommended):
`bash
In OpenCode TUI
/connect
Select: Z.AI Coding Plan or Z.AI
Enter your API key
`Fallback (Development/Testing Only):
`bash
For Global platform (api.z.ai)
export ZAI_API_KEY="your-api-key"For CN platform (open.bigmodel.cn)
export ZHIPU_API_KEY="your-api-key"
`$3
After authentication, simply run:
`bash
/glm_quota
`$3
`
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā
ā Z.ai GLM Coding Plan Usage Statistics ā
ā ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā£
ā Platform: Z.AI ā
ā Period: 2026-01-17 21:00:00 ā 2026-01-18 20:59:59 ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā£
ā QUOTA LIMITS ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¢
ā Token usage(5 Hour) [###################--------] 40.5% ā
ā MCP usage(1 Month) [####-----------------------] 12.3% ā
ā Used: 123/1,000 ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā£
ā MODEL USAGE (24h) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¢
ā Total Tokens (24h): 12,500,000 (31% of 5h limit) ā
ā 5h Window Usage: 40.5% of 40,000,000 ā
ā Total Calls: 1,234 ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā£
ā TOOL/MCP USAGE (24h) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¢
ā Network Searches: 5,678 ā
ā Web Reads: 2,345 ā
ā ZRead Calls: 890 ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
`$3
The plugin uses fail-fast error handling. If any API request fails, it will display the error and stop (no automatic retries). This gives you full control over when to retry.
Example Error Output:
`
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā
ā ā Z.ai Credentials Not Found ā
ā ā
ā Please authenticate first: ā
ā ā
ā 1. Run /connect command in OpenCode TUI ā
ā 2. Select "Z.AI Coding Plan" or "Z.AI" ā
ā 3. Or "Zhipu" (for China region) ā
ā ā
ā For dev/testing, set environment: ā
ā - ZAI_API_KEY (global) ā
ā - ZHIPU_API_KEY (China) ā
ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
`API Reference
This plugin queries three Z.ai monitoring endpoints:
| Endpoint | Purpose | Query Params |
|----------|---------|--------------|
|
/api/monitor/usage/quota/limit | Current quota percentages | None |
| /api/monitor/usage/model-usage | Model usage (24h window) | startTime, endTime |
| /api/monitor/usage/tool-usage | MCP tool usage (24h window) | startTime, endTime |$3
The plugin automatically detects the platform based on the provider ID used during authentication:
| Provider ID | Platform | API Base URL |
|-------------|----------|---------------|
|
zai-coding-plan | ZAI | https://api.z.ai |
| zai | ZAI | https://api.z.ai |
| zhipu | ZHIPU | https://open.bigmodel.cn |$3
The plugin discovers credentials in this order:
1. OpenCode authentication context (managed by OpenCode) - PRIMARY
2. Environment variable
ZAI_API_KEY (Global) or ZHIPU_API_KEY (CN) - FALLBACK (dev/testing only)$3
Usage statistics are queried for a 24-hour rolling window:
- Start: Yesterday at current hour (e.g., 14:00:00)
- End: Today at current hour end (e.g., 14:59:59)
$3
Critical: The plugin does NOT use "Bearer" prefix in the Authorization header. The token is passed directly:
`http
Authorization: {token}
Accept-Language: en-US,en
Content-Type: application/json
`Development
$3
`bash
Build TypeScript to JavaScript
npm run buildClean build artifacts
npm run cleanRun all tests
npm run testRun test suite with coverage
npm run test:coverageRun specific test file
npm run test -- path/to/test.test.tsWatch mode during development
npm run test -- --watchLint source code
npm run lintPrepare for npm publish
npm run prepublishOnly
`$3
`
src/
index.ts # Main plugin entry point
api/
client.ts # HTTPS client with timeout and error handling
endpoints.ts # Platform-specific API endpoints
platforms.ts # Platform detection and naming
utils/
date-formatter.ts # Date/time formatting utilities
progress-bar.ts # ASCII progress bar rendering
time-window.ts # Rolling window calculation
integration/
agents/glm-quota-exec.md # Minimal executor agent (Markdown)
command/glm_quota.md # /glm_quota slash command
skills/glm-quota/SKILL.md # Skill documentation
bin/
install.js # Installation script
dist/ # Compiled JavaScript (generated)
tests/ # Test suite
package.json # Dependencies and scripts
tsconfig.json # TypeScript configuration
`$3
- Target: ES2022
- Module: NodeNext
- Strict mode enabled
- Always use type annotations for function returns
- Use
as const` for immutable constantsFor detailed coding conventions, see AGENTS.md.
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
MIT Ā© 2026
- Adaptation from zai-org/zai-coding-plugins - This plugin is an OpenCode adaptation of the original Z.ai coding plugins repository
- Built for OpenCode
See CHANGELOG.md for version history and detailed changes.