npm package: @mdrv/opencode-quota
Description: OpenCode plugin for querying Z.AI GLM Coding Plan and GitHub Copilot usage statistics
Author: Umar Alfarouk
Latest version: 262.1.0

# opencode-quota

## [![npm version](https://img.shields.io/npm/v/opencode-glm-quota.svg)](https://www.npmjs.com/package/opencode-glm-quota) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Build Status](https://github.com/guyinwonder168/opencode-glm-quota/workflows/CI/badge.svg)](https://github.com/guyinwonder168/opencode-glm-quota/actions) [![SonarQube Cloud](https://sonarcloud.io/images/project_badges/sonarcloud-light.svg)](https://sonarcloud.io/summary/new_code?id=guyinwonder168_opencode-glm-quota)

[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=guyinwonder168_opencode-glm-quota&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=guyinwonder168_opencode-glm-quota)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=guyinwonder168_opencode-glm-quota&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=guyinwonder168_opencode-glm-quota)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=guyinwonder168_opencode-glm-quota&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=guyinwonder168_opencode-glm-quota)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=guyinwonder168_opencode-glm-quota&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=guyinwonder168_opencode-glm-quota)

OpenCode plugin for querying Z.ai GLM, GitHub Copilot, and Kimi usage statistics. Check quota limits, model usage, and MCP tool usage with manual commands.

## Features

- 📊 **Multi-Platform Support**: Query GLM, GitHub Copilot, and Kimi Coding Plans.
- 🖱️ **Manual-Only**: Plugin only runs when you ask (no periodic background checks).
- ⏱️ **Human Durations**: Clear reset timers (e.g., `24d 13h 6m 12s`), hiding zero values.
- 🔐 **Secure Credential Discovery**: Automatically fetches tokens from OpenCode auth context.
- 📈 **Visual Progress**: Plain text progress bars and usage percentages.
- ⚡ **Fail-Fast**: Direct reporting without hidden retry loops.

## Installation

### Option 1: npm (Recommended)

```bash
# Install package
npm install opencode-glm-quota

# Run installer to configure OpenCode
npx opencode-glm-quota install
```

**What the installer does:**

- Copies `/glm_quota`, `/copilot_quota`, and `/kimi_quota` commands to your OpenCode config.
- Configures skill documentation in `~/.config/opencode/skills/`.
- Automatically adds the plugin to your OpenCode configuration.

### Uninstall

```bash
npx opencode-glm-quota uninstall
```

## Quick Start

Run any of the following commands in OpenCode:

```bash
/glm_quota      # Z.AI GLM Coding Plan statistics
/copilot_quota  # GitHub Copilot usage statistics
/kimi_quota    # Kimi Coding Plan usage statistics
```

## CLI Usage

Check your quota directly from the terminal using the provided binaries:

```bash
# Check GLM quota
bun run bin/glm-quota.ts

# Check GitHub Copilot quota
bun run bin/copilot-quota.ts

# Check Kimi quota
bun run bin/kimi-quota.ts
```

### CLI Flags

| Flag      | Shorthand | Description                              |
| --------- | --------- | ---------------------------------------- |
| `--debug` | `-d`      | Enable debug logging (hidden by default) |
| `--raw`   |           | Output raw JSON (useful for scripting)   |
| `--help`  | `-h`      | Show help message                        |

## Platform Features

### Z.AI GLM

- Shows **TIME_LIMIT** (1-month) and **TOKENS_LIMIT** (5-hour rolling window).
- Detailed model usage counts and MCP tool usage statistics.

### GitHub Copilot

- Displays user login, subscription plan, and reset dates.
- Shows usage for Chat, Completions, and Premium features.
- Indicates if usage is "Unlimited".

### Kimi

- Shows total usage and 5-hour rolling window usage.
- Displays specific "Time to Reset" for each quota window.

## Output Example

```text
--------------------------------------------------------
           Z.ai GLM Coding Plan Usage Statistics
--------------------------------------------------------
  Platform: Z.AI
  Period:   2026-02-22 09:00:00 -> 2026-02-23 08:59:59
--------------------------------------------------------
  QUOTA LIMITS
  - Token usage(5 Hour)      [###################--------]  40.5%
  - MCP usage(1 Month)       [####-----------------------]  12.3%
       Used: 123/1,000
       Reset in: 12d 4h 15m
--------------------------------------------------------
  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
--------------------------------------------------------
```

## Error Handling

The plugin uses fail-fast error handling. If an API request fails or credentials are missing, it displays a plain text error message immediately.

```text
--------------------------------------------------------
  ERROR: Z.ai Credentials Not Found
--------------------------------------------------------
  Please authenticate first:
  1. Run /connect in OpenCode TUI
  2. Select "Z.AI Coding Plan" or "Z.AI"
--------------------------------------------------------
```

## API Reference

| Platform           | Endpoint                                       |
| ------------------ | ---------------------------------------------- |
| **Z.AI GLM**       | `https://api.z.ai/api/monitor/usage/*`         |
| **GitHub Copilot** | `https://api.github.com/copilot_internal/user` |
| **Kimi**           | `https://api.kimi.com/coding/v1/usages`        |

## Development

### Build & Test

```bash
# Build TypeScript
bun run build

# Run all tests
bun run test

# Format code
bun run fmt
```

### Project Structure

```text
src/
  index.ts              # Main plugin entry point
  api/
    client.ts           # Shared HTTPS client
    endpoints.ts        # Endpoint definitions
  utils/
    duration.ts         # d h m s formatting logic
    progress-bar.ts     # Plain text bar rendering
bin/
  glm-quota.ts          # CLI binary for GLM
  copilot-quota.ts      # CLI binary for Copilot
  kimi-quota.ts         # CLI binary for Kimi
  install.js            # Installation script
integration/
  command/              # /command slash commands
  skills/               # OpenCode skill docs
```

## License

MIT © 2026

## Changelog

See [CHANGELOG.md](CHANGELOG.md) for version history.

- **v2.62.0**: Removed auto quota features; Added Copilot & Kimi support; Plain text output; CLI binaries.