Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"source": "./plugins/glm-plan-bug",
"category": "development",
"description": "Submit case feedback and bug reports for GLM Coding Plan service."
},
{
"name": "zai-quota-hud",
"source": "./plugins/zai-quota-hud",
"category": "monitoring",
"description": "Display ZAI/GLM Coding Plan quota usage in the Claude Code statusline with a color-coded progress bar, automatic color changes, and reset countdown."
}
]
}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A collection of plugins to enhance coding productivity and provide GLM Coding Pl
|----------------------|-----------------------------------------------------------------------|
| **glm-plan-usage** | Query quota and usage statistics for GLM Coding Plan |
| **glm-plan-bug** | Submit case feedback and bug reports for GLM Coding Plan |
| **zai-quota-hud** | Display quota usage in the statusline with color-coded progress bar |

**Attention:** **glm-plan-bug** will summarize your current conversation context to help identify issues. If you do not want to report this information, please do not actively use this plugin.

Expand Down Expand Up @@ -42,6 +43,10 @@ claude plugin install glm-plan-usage@zai-coding-plugins
claude plugin install glm-plan-bug@zai-coding-plugins
```

```shell
claude plugin install zai-quota-hud@zai-coding-plugins
```

### Method B

Run the `npx @z_ai/coding-helper` tool to manage and install the plugins directly.
Expand All @@ -66,6 +71,14 @@ claude
/glm-plan-bug:case-feedback Your feedback message here
```

```bash
/zai-quota-hud:setup
```

```bash
/zai-quota-hud:quota
```

**Attention:** **glm-plan-bug** will summarize your current conversation context to help identify issues. If you do not want to report this information, please do not actively use this plugin.

## Contributing
Expand Down
13 changes: 13 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Claude Code 插件集合,旨在提升编程效率和提供 GLM Coding Plan 相
|---------------------|------------------------------------|
| **glm-plan-usage** | 查询 GLM Coding Plan 的配额和使用统计 |
| **glm-plan-bug** | 提交 GLM Coding Plan 的反馈和问题报告 |
| **zai-quota-hud** | 在状态栏显示配额使用量,带颜色编码进度条 |

**注意:** **glm-plan-bug** 会总结您当前对话的上下文信息以帮助定位问题,若不想上报信息,请勿主动使用此插件。

Expand Down Expand Up @@ -42,6 +43,10 @@ claude plugin install glm-plan-usage@zai-coding-plugins
claude plugin install glm-plan-bug@zai-coding-plugins
```

```shell
claude plugin install zai-quota-hud@zai-coding-plugins
```

### 方式二

运行 `npx @z_ai/coding-helper` 工具直接管理和安装插件。
Expand All @@ -66,6 +71,14 @@ claude
/glm-plan-bug:case-feedback 在此输入你的反馈
```

```bash
/zai-quota-hud:setup
```

```bash
/zai-quota-hud:quota
```

**注意:** **glm-plan-bug** 会总结您当前对话的上下文信息以帮助定位问题,若不想上报信息,请勿主动使用此插件。

## 贡献
Expand Down
15 changes: 15 additions & 0 deletions plugins/zai-quota-hud/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "zai-quota-hud",
"description": "Display ZAI/GLM Coding Plan quota usage in the Claude Code statusline with a color-coded progress bar",
"version": "1.0.0",
"author": {
"name": "n1majne3",
"url": "https://github.com/n1majne3"
},
"commands": [
"./commands/setup.md",
"./commands/quota.md"
],
"license": "MIT",
"keywords": ["zai", "zhipu", "glm", "quota", "statusline", "claude-code"]
}
40 changes: 40 additions & 0 deletions plugins/zai-quota-hud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ZAI Quota HUD

[中文](README.zh-CN.md)

A Claude Code plugin that displays your ZAI/GLM Coding Plan token quota usage in the statusline.

![ZAI ██░░░ 37%](https://img.shields.io/badge/statusline-quota-brightgreen) ![License](https://img.shields.io/github/license/n1majne3/zai-quota-hud)

## What you see

Below the input bar:

```
ZAI ██░░░ 37%
```

Color changes automatically: green (< 50%), yellow (50-80%), red (> 80%).

At 100% usage, a countdown timer shows time until reset:

```
ZAI █████ 100% ⏳ 1h 23m
```

## Commands

| Command | Description |
|---------|-------------|
| `/zai-quota-hud:setup` | Configure the statusline in Claude Code settings |
| `/zai-quota-hud:quota` | Show detailed quota breakdown (per-model) |

## Requirements

- Claude Code v1.0.80+
- Node.js 18+
- `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN` environment variables set (ZAI or Zhipu endpoint)

## License

MIT
89 changes: 89 additions & 0 deletions plugins/zai-quota-hud/commands/quota.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
description: Query detailed ZAI/GLM Coding Plan quota and usage breakdown
allowed-tools: Bash, Read
---

# Query ZAI Quota Details

Run a detailed quota query and show the full breakdown to the user.

## Execution

### Step 1: Run the query script

Execute the statusline script to get fresh data (bust cache by removing the cache file first):

```bash
rm -f /tmp/zai-quota-cache.json && echo '{}' | node "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/plugins/cache/zai-quota-hud/zai-quota-hud/$(ls "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/plugins/cache/zai-quota-hud/zai-quota-hud/ | sort | tail -1)/scripts/statusline.mjs"
```

If the plugin is loaded via `--plugin-dir`, adjust the path accordingly. You can find the plugin root by looking for `scripts/statusline.mjs` relative to the plugin directory.

If that fails, try:
```bash
rm -f /tmp/zai-quota-cache.json && ANTHROPIC_BASE_URL="$ANTHROPIC_BASE_URL" ANTHROPIC_AUTH_TOKEN="$ANTHROPIC_AUTH_TOKEN" node -e "
const https = require('https');
const { URL } = require('url');
const baseUrl = process.env.ANTHROPIC_BASE_URL || '';
const authToken = process.env.ANTHROPIC_AUTH_TOKEN || '';
if (!baseUrl || !authToken) { console.error('Set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN'); process.exit(1); }
const parsed = new URL(baseUrl);
const base = parsed.protocol + '//' + parsed.host;
const url = new URL(base + '/api/monitor/usage/quota/limit');
const req = https.request({ hostname: url.hostname, port: url.port || 443, path: url.pathname, method: 'GET', headers: { 'Authorization': authToken, 'Accept-Language': 'en-US,en', 'Content-Type': 'application/json' } }, (res) => {
let d = ''; res.on('data', c => d += c); res.on('end', () => { console.log(JSON.stringify(JSON.parse(d), null, 2)); });
});
req.on('error', e => { console.error(e.message); process.exit(1); });
req.end();
"
```

### Step 2: Format the output

Parse the JSON response and present it clearly:

**If platform is ZHIPU** (ANTHROPIC_BASE_URL contains `open.bigmodel.cn`), present in Chinese:

```
## ZAI 配额使用情况

**账号等级:** {level}

### Token 使用 (5小时窗口)
- 使用率: {percentage}%
- 下次重置: {nextResetTime formatted}

### MCP 使用 (月度)
- 当前用量: {currentValue} / {usage}
- 剩余: {remaining}
- 使用率: {percentage}%
- 下次重置: {nextResetTime formatted}

#### 模型明细:
- {modelCode}: {usage}
```

**If platform is ZAI** (ANTHROPIC_BASE_URL contains `api.z.ai`), present in English:

```
## ZAI Quota Usage

**Account Level:** {level}

### Token Usage (5-hour window)
- Usage: {percentage}%
- Resets at: {nextResetTime formatted}

### MCP Usage (Monthly)
- Current: {currentValue} / {usage}
- Remaining: {remaining}
- Usage: {percentage}%
- Resets at: {nextResetTime formatted}

#### Per-model breakdown:
- {modelCode}: {usage}
```

### Constraint

**Run the query exactly once.** Do not retry on failure. Show the error if it fails.
68 changes: 68 additions & 0 deletions plugins/zai-quota-hud/commands/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
description: Configure the ZAI Quota HUD statusline in Claude Code settings
allowed-tools: Bash, Read, Write, Edit
---

# Setup ZAI Quota HUD Statusline

Configure the ZAI Quota HUD to display quota information below the Claude Code input bar.

## Steps

### 1. Detect the plugin directory

Find where the zai-quota-hud plugin is installed. Check in order:
1. `${CLAUDE_CONFIG_DIR:-$HOME/.claude}/plugins/cache/zai-quota-hud/` (marketplace install)
2. Look for a `--plugin-dir` loaded copy
3. Ask the user for the plugin path

Run: `ls -d "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/plugins/cache/zai-quota-hud/zai-quota-hud/*/ 2>/dev/null | sort | tail -1`

If that returns a path, use it. If not, ask the user for the absolute path to the `zai-usage-claude-code-plugin` directory.

### 2. Generate the statusline command

For a marketplace-installed plugin:
```
bash -c 'plugin_dir=$(ls -d "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/plugins/cache/zai-quota-hud/zai-quota-hud/*/ 2>/dev/null | sort | tail -1); exec node "${plugin_dir}scripts/statusline.mjs"'
```

For a local plugin-dir install:
```
bash -c 'exec node "<PLUGIN_PATH>/scripts/statusline.mjs"'
```

Where `<PLUGIN_PATH>` is the absolute path from step 1.

### 3. Write the statusLine config

Read the current `${CLAUDE_CONFIG_DIR:-$HOME/.claude}/settings.json` (create it if it doesn't exist).

Merge in the `statusLine` field while preserving all existing settings:

```json
{
"statusLine": {
"type": "command",
"command": "<generated command from step 2>"
}
}
```

If a `statusLine` already exists, confirm with the user before overwriting.

### 4. Verify

Run the generated command to confirm it produces output:

```bash
echo '{}' | bash -c '<the generated command>'
```

### 5. Inform the user

Tell the user:
- The statusline has been configured
- They need to **restart Claude Code** for the statusLine config to take effect
- After restart, they should see quota info below the input bar
- If they don't see it, run `/zai-quota-hud:setup` again or check that `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN` are set in their environment
Loading
Loading