{"id":39809387,"url":"https://github.com/guyinwonder168/opencode-glm-quota","last_synced_at":"2026-01-31T10:08:53.292Z","repository":{"id":333145481,"uuid":"1136330472","full_name":"guyinwonder168/opencode-glm-quota","owner":"guyinwonder168","description":"Opencode plugin to query Z.ai GLM Coding Plan usage statistics with real-time quota monitoring, model usage tracking, and MCP Tools usage","archived":false,"fork":false,"pushed_at":"2026-01-25T17:34:14.000Z","size":303,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-26T01:55:21.961Z","etag":null,"topics":["ci-cd","github-actions","glm","opencode","plugin","quota-monitoring","typescript","zai"],"latest_commit_sha":null,"homepage":"https://github.com/guyinwonder168/opencode-glm-quota","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guyinwonder168.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-01-17T13:50:55.000Z","updated_at":"2026-01-25T17:34:17.000Z","dependencies_parsed_at":"2026-01-25T13:00:30.162Z","dependency_job_id":null,"html_url":"https://github.com/guyinwonder168/opencode-glm-quota","commit_stats":null,"previous_names":["guyinwonder168/opencode-glm-quota"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/guyinwonder168/opencode-glm-quota","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guyinwonder168%2Fopencode-glm-quota","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guyinwonder168%2Fopencode-glm-quota/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guyinwonder168%2Fopencode-glm-quota/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guyinwonder168%2Fopencode-glm-quota/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guyinwonder168","download_url":"https://codeload.github.com/guyinwonder168/opencode-glm-quota/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guyinwonder168%2Fopencode-glm-quota/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28937868,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T08:53:31.997Z","status":"ssl_error","status_checked_at":"2026-01-31T08:51:38.521Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci-cd","github-actions","glm","opencode","plugin","quota-monitoring","typescript","zai"],"created_at":"2026-01-18T12:42:02.957Z","updated_at":"2026-01-31T10:08:53.284Z","avatar_url":"https://github.com/guyinwonder168.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# opencode-glm-quota\n\n[![npm version](https://img.shields.io/npm/v/opencode-glm-quota.svg)](https://www.npmjs.com/package/opencode-glm-quota)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Build Status](https://github.com/guyinwonder168/opencode-glm-quota/workflows/CI/badge.svg)](https://github.com/guyinwonder168/opencode-glm-quota/actions)\n[![SonarQube Cloud](https://sonarcloud.io/images/project_badges/sonarcloud-light.svg)](https://sonarcloud.io/summary/new_code?id=guyinwonder168_opencode-glm-quota)\n---\n[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=guyinwonder168_opencode-glm-quota\u0026metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=guyinwonder168_opencode-glm-quota)\n[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=guyinwonder168_opencode-glm-quota\u0026metric=security_rating)](https://sonarcloud.io/summary/new_code?id=guyinwonder168_opencode-glm-quota)\n[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=guyinwonder168_opencode-glm-quota\u0026metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=guyinwonder168_opencode-glm-quota)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=guyinwonder168_opencode-glm-quota\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=guyinwonder168_opencode-glm-quota)\n\nOpenCode plugin to query Z.ai GLM Coding Plan usage statistics with real-time quota monitoring, model usage tracking, and MCP tool usage.\n\n## Features\n\n- 📊 Query current quota limits (5-hour token cycle, monthly MCP usage)\n- 🤖 View model usage statistics (24-hour rolling window)\n- 🔧 View MCP tool usage (web_search, web_reader, etc.)\n- 🌍 Supports both Global (api.z.ai) and CN (open.bigmodel.cn) platforms\n- 🔐 Automatic credential discovery from OpenCode auth.json\n- 📈 Visual progress bars for quota percentages (ASCII for terminal alignment)\n- ⚡ Fail-fast error handling (no retry logic - user controls when to retry)\n\n## Installation\n\n### Option 1: npm (Recommended)\n\n```bash\n# Install plugin\nnpm install opencode-glm-quota\n\n# Run installer to configure OpenCode\nnpx opencode-glm-quota install\n```\n\n**What the installer does:**\n- Copies `/glm_quota` command to `~/.config/opencode/command/glm_quota.md`\n- Copies skill documentation to `~/.config/opencode/skills/glm-quota/SKILL.md`\n- Automatically adds plugin to your OpenCode config\n- Copies agent to `~/.config/opencode/agents/`\n- Supports `--force` flag to overwrite existing files\n\n### Uninstall\n\n```bash\n# Remove OpenCode integration files and config\nnpx opencode-glm-quota uninstall\n\n# If installed globally\nnpx opencode-glm-quota uninstall --global\n```\n\n**What the uninstaller does:**\n- Removes `/glm_quota` command\n- Deletes `skills/glm-quota/SKILL.md`\n- Removes plugin entry from OpenCode config\n- Removes agent file and legacy config\n- Runs `npm remove opencode-glm-quota` (or `--global`)\n\n### Option 2: From GitHub\n\n```bash\nnpm install github:guyinwonder168/opencode-glm-quota\n```\n\n### Option 3: Local Development\n\n```bash\n# Clone and build\ngit clone https://github.com/guyinwonder168/opencode-glm-quota.git\ncd opencode-glm-quota\nnpm install\nnpm run build\n\n# Link for local testing\nnpm link\n\n# Run the installer for local testing\nnode bin/install.js\n```\n\n## Quick Start\n\nOnce installed, simply run the plugin command in OpenCode:\n\n```bash\n/glm_quota\n```\n\nThe plugin will automatically detect your credentials (from OpenCode authentication) and display your usage statistics.\n\n## Usage\n\n### Authentication Setup\n\nThis plugin uses OpenCode's built-in authentication system. No manual configuration required.\n\n**Primary Method (Recommended):**\n\n```bash\n# In OpenCode TUI\n/connect\n# Select: Z.AI Coding Plan or Z.AI\n# Enter your API key\n```\n\n**Fallback (Development/Testing Only):**\n\n```bash\n# For Global platform (api.z.ai)\nexport ZAI_API_KEY=\"your-api-key\"\n\n# For CN platform (open.bigmodel.cn)\nexport ZHIPU_API_KEY=\"your-api-key\"\n```\n\n### Running the Plugin\n\nAfter authentication, simply run:\n\n```bash\n/glm_quota\n```\n\n### Output Example\n\n```\n╔══════════════════════════════════════════════════════════════════╗\n║                                                                  ║\n║           Z.ai GLM Coding Plan Usage Statistics                  ║\n║                                                                  ║\n╠══════════════════════════════════════════════════════════════════╣\n║  Platform: Z.AI                                                  ║\n║  Period:   2026-01-17 21:00:00 → 2026-01-18 20:59:59             ║\n╠══════════════════════════════════════════════════════════════════╣\n║  QUOTA LIMITS                                                    ║\n╟──────────────────────────────────────────────────────────────────╢\n║  Token usage(5 Hour)      [###################--------]  40.5%   ║\n║  MCP usage(1 Month)       [####-----------------------]  12.3%   ║\n║       Used: 123/1,000                                            ║\n╠══════════════════════════════════════════════════════════════════╣\n║  MODEL USAGE (24h)                                               ║\n╟──────────────────────────────────────────────────────────────────╢\n║  Total Tokens (24h): 12,500,000 (31% of 5h limit)                ║\n║  5h Window Usage: 40.5% of 40,000,000                            ║\n║  Total Calls: 1,234                                              ║\n╠══════════════════════════════════════════════════════════════════╣\n║  TOOL/MCP USAGE (24h)                                            ║\n╟──────────────────────────────────────────────────────────────────╢\n║  Network Searches: 5,678                                         ║\n║  Web Reads: 2,345                                                ║\n║  ZRead Calls: 890                                                ║\n╚══════════════════════════════════════════════════════════════════╝\n```\n\n### Error Handling\n\nThe 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.\n\n**Example Error Output:**\n\n```\n╔══════════════════════════════════════════════════════════════════╗\n║                                                                  ║\n║  ❌ Z.ai Credentials Not Found                                   ║\n║                                                                  ║\n║  Please authenticate first:                                      ║\n║                                                                  ║\n║  1. Run /connect command in OpenCode TUI                         ║\n║  2. Select \"Z.AI Coding Plan\" or \"Z.AI\"                          ║\n║  3. Or \"Zhipu\" (for China region)                                ║\n║                                                                  ║\n║  For dev/testing, set environment:                               ║\n║  - ZAI_API_KEY (global)                                          ║\n║  - ZHIPU_API_KEY (China)                                         ║\n║                                                                  ║\n╚══════════════════════════════════════════════════════════════════╝\n```\n\n## API Reference\n\nThis plugin queries three Z.ai monitoring endpoints:\n\n| Endpoint | Purpose | Query Params |\n|----------|---------|--------------|\n| `/api/monitor/usage/quota/limit` | Current quota percentages | None |\n| `/api/monitor/usage/model-usage` | Model usage (24h window) | `startTime`, `endTime` |\n| `/api/monitor/usage/tool-usage` | MCP tool usage (24h window) | `startTime`, `endTime` |\n\n### Platform Detection\n\nThe plugin automatically detects the platform based on the provider ID used during authentication:\n\n| Provider ID | Platform | API Base URL |\n|-------------|----------|---------------|\n| `zai-coding-plan` | ZAI | `https://api.z.ai` |\n| `zai` | ZAI | `https://api.z.ai` |\n| `zhipu` | ZHIPU | `https://open.bigmodel.cn` |\n\n### Credential Priority\n\nThe plugin discovers credentials in this order:\n\n1. **OpenCode auth.json** (`~/.local/share/opencode/auth.json`) - PRIMARY\n2. **Environment variable** `ZAI_API_KEY` (Global) or `ZHIPU_API_KEY` (CN) - FALLBACK (dev/testing only)\n\n### Time Window\n\nUsage statistics are queried for a 24-hour rolling window:\n- **Start**: Yesterday at current hour (e.g., 14:00:00)\n- **End**: Today at current hour end (e.g., 14:59:59)\n\n### Authentication\n\n**Critical**: The plugin does NOT use \"Bearer\" prefix in the Authorization header. The token is passed directly:\n\n```http\nAuthorization: {token}\nAccept-Language: en-US,en\nContent-Type: application/json\n```\n\n## Development\n\n### Build Commands\n\n```bash\n# Build TypeScript to JavaScript\nnpm run build\n\n# Clean build artifacts\nnpm run clean\n\n# Run all tests\nnpm run test\n\n# Run specific test file\nnpm run test -- path/to/test.test.ts\n\n# Watch mode during development\nnpm run test -- --watch\n\n# Lint source code\nnpm run lint\n\n# Prepare for npm publish\nnpm run prepublishOnly\n```\n\n### Project Structure\n\n```\nsrc/\n  index.ts              # Main plugin entry point\n  api/\n    client.ts           # HTTPS client with timeout and error handling\n    endpoints.ts        # Platform-specific API endpoints\n    platforms.ts        # Platform detection and naming\n  utils/\n    date-formatter.ts   # Date/time formatting utilities\n    progress-bar.ts     # ASCII progress bar rendering\n    time-window.ts      # Rolling window calculation\n  integration/\n    agents/glm-quota-exec.md      # Minimal executor agent (Markdown)\n    command/glm_quota.md          # /glm_quota slash command\n    skills/glm-quota/SKILL.md      # Skill documentation\n  bin/\n    install.js                     # Installation script\n  dist/                   # Compiled JavaScript (generated)\n  tests/                  # Test suite\n  package.json            # Dependencies and scripts\n  tsconfig.json           # TypeScript configuration\n```\n\n### Code Style Guidelines\n\n- Target: ES2022\n- Module: NodeNext\n- Strict mode enabled\n- Always use type annotations for function returns\n- Use `as const` for immutable constants\n\nFor detailed coding conventions, see [AGENTS.md](AGENTS.md).\n\n## Contributing\n\nWe welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n\n## License\n\nMIT © 2026\n\n## Acknowledgments\n\n- **Adaptation from [zai-org/zai-coding-plugins](https://github.com/zai-org/zai-coding-plugins)** - This plugin is an OpenCode adaptation of the original Z.ai coding plugins repository\n- Built for [OpenCode](https://opencode.ai)\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for version history and detailed changes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguyinwonder168%2Fopencode-glm-quota","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguyinwonder168%2Fopencode-glm-quota","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguyinwonder168%2Fopencode-glm-quota/lists"}