glm-plan-usage
v0.0.1
Published
GLM usage status plugin for Claude Code
Maintainers
Readme
GLM Usage Status Plugin
A Claude Code plugin that displays GLM (ZHIPU/ZAI) coding plan usage statistics in the status bar.
Features
- Real-time Usage Tracking: Displays token and MCP usage percentages
- Color-coded Warnings:
- Green (0-79%): Normal usage
- Yellow (80-94%): High usage
- Red (95-100%): Critical usage
- Smart Caching: 5-minute cache to reduce API calls
- Automatic Platform Detection: Supports both ZAI and ZHIPU platforms
- Graceful Degradation: Silently fails on API errors
Installation
Method 1: Via npm (Recommended ⭐)
The easiest way to install and manage the plugin:
npm install -g glm-plan-usageThis installs the plugin globally and makes it available as glm-plan-usage in your terminal.
Initialize Configuration:
glm-plan-usage --initVerify Installation:
glm-plan-usage --helpSupported Platforms:
- ✅ Linux (x64, arm64)
- ✅ macOS (Intel, Apple Silicon)
- ✅ Windows (x64)
Method 2: Manual Installation from Source
Build from source if you prefer or need customization:
1. Build
cd glm-plan-usage
cargo build --release2. Install
mkdir -p ~/.claude/glm-plan-usage
cp target/release/glm-plan-usage ~/.claude/glm-plan-usage/
chmod +x ~/.claude/glm-plan-usage/glm-plan-usage3. Initialize Configuration
~/.claude/glm-plan-usage/glm-plan-usage --initThis creates a default config at ~/.claude/glm-plan-usage/config.toml:
[style]
mode = "plain"
separator = " | "
[[segments]]
id = "glm_usage"
enabled = true
[segments.colors]
text = { c256 = 109 } # Default green
[segments.styles]
text_bold = true
[api]
timeout_ms = 5000
retry_attempts = 2
[cache]
enabled = true
ttl_seconds = 3004. Configure Claude Code
If installed via npm:
Edit ~/.config/claude-code/settings.json:
{
"statusLine": {
"type": "command",
"command": "glm-plan-usage",
"padding": 0
}
}If installed manually:
{
"statusLine": {
"type": "command",
"command": "~/.claude/glm-plan-usage/glm-plan-usage",
"padding": 0
}
}5. Set Environment Variables
Add to your ~/.bashrc or ~/.zshrc:
export ANTHROPIC_AUTH_TOKEN="your-token-here"
export ANTHROPIC_BASE_URL="https://open.bigmodel.cn/api/anthropic"Usage
The plugin automatically displays usage in the format:
T:42% M:15%Where:
T:42%= Token usage (5-hour window)M:15%= MCP usage (30-day window)
Using the npm-installed Version
Initialize config:
glm-plan-usage --initTest the plugin:
# Set environment variables
export ANTHROPIC_AUTH_TOKEN="your-token"
export ANTHROPIC_BASE_URL="https://open.bigmodel.cn/api/anthropic"
# Test with sample input
echo '{"model":{"id":"test"}}' | glm-plan-usageUpdate config manually (if needed):
# Edit config directly
nano ~/.claude/glm-plan-usage/config.toml
# Or reinitialize
glm-plan-usage --initCLI Options
glm-plan-usage [OPTIONS]
Options:
--init Initialize configuration file
--verbose Enable verbose output
--no-cache Disable cache
-h, --help Print helpConfiguration
Style Settings
[style]
mode = "plain" # plain, nerd_font, powerline
separator = " | "Segment Colors
[[segments]]
id = "glm_usage"
enabled = true
[segments.colors]
text = { c256 = 109 } # 256-color palette
# OR RGB:
# text = { r = 34, g = 197, b = 94 }API Settings
[api]
timeout_ms = 5000 # HTTP timeout
retry_attempts = 2 # Number of retriesCache Settings
[cache]
enabled = true
ttl_seconds = 300 # 5 minutesAPI Endpoints
The plugin queries the GLM API:
- Quota Limits:
GET /api/monitor/usage/quota/limit - Token Usage:
GET /api/monitor/usage/model-usage - MCP Usage:
GET /api/monitor/usage/tool-usage
Error Handling
The plugin gracefully handles errors:
- Missing environment variables → No output
- API timeout → Uses cached data (if available)
- API errors → Uses cached data (if available)
- No cache → Silent failure
Use --verbose to debug issues:
# If installed via npm
glm-plan-usage --verbose < input.json
# If installed manually
~/.claude/glm-plan-usage/glm-plan-usage --verbose < input.jsonUpdating
Via npm
# Update to the latest version
npm update -g glm-plan-usage
# Or reinstall
npm install -g glm-plan-usage@latestManual Installation
# Rebuild from source
cd glm-plan-usage
cargo build --release
# Reinstall
cp target/release/glm-plan-usage ~/.claude/glm-plan-usage/Development
Project Structure
glm-plan-usage/
├── Cargo.toml
├── README.md
└── src/
├── main.rs # Entry point
├── cli.rs # CLI parsing
├── lib.rs # Library root
├── config/
│ ├── mod.rs
│ ├── types.rs # Config types
│ └── loader.rs # Config loading
├── core/
│ ├── mod.rs
│ ├── statusline.rs # ANSI rendering
│ └── segments/
│ ├── mod.rs
│ └── glm_usage.rs # GLM usage segment
└── api/
├── mod.rs
├── client.rs # HTTP client
└── types.rs # API typesBuild Release
cargo build --releaseThe binary is stripped and optimized for size.
License
MIT
