A Claude Code plugin that makes your coding agent token-efficient by delegating code generation, review, testing, and refactoring to Z.ai non-agentic models (GLM-4, CodeGeeX) via MCP.
Claude is great at reasoning but expensive when writing large amounts of code. This plugin offloads the heavy lifting:
- Save tokens — Code generation, test writing, and boilerplate go to cheap GLM/CodeGeeX models instead of consuming Claude context
- Non-agentic models only — Uses glm-4-plus, glm-4-flash, codegeex-4 — fast, cheap, no reasoning overhead
- Claude stays in control — Claude reads, plans, and orchestrates; Z.ai writes the code
- Parallel agentic delegation — Orchestrator fans out independent units to multiple GLM workers concurrently, cutting wall-clock time
- Auto-routing hooks — Session-start guidance + prompt router that nudges Claude toward delegation when it detects heavy code-gen verbs
- 7 skills + 3 agents — Ready-to-use workflows for generate, review, explain, refactor, test, delegate, and parallel orchestration
Open Claude Code Settings > Plugins > Add Marketplace, paste:
kemalabuteliyte/zai-mcp-server
Click Sync, then install the plugin from the marketplace. Set your ZAI_API_KEY when prompted.
claude mcp add zai-mcp-server -- npx -y github:kemalabuteliyte/zai-mcp-serverexport ZAI_API_KEY="your-z-ai-api-key"Add to your ~/.claude/settings.json:
{
"mcpServers": {
"zai-mcp-server": {
"command": "npx",
"args": ["-y", "github:kemalabuteliyte/zai-mcp-server"],
"env": {
"ZAI_API_KEY": "your-z-ai-api-key"
}
}
}
}| Tool | Description |
|---|---|
zai_chat_complete |
Chat completion via Z.ai general endpoint |
zai_code_complete |
Code completion via Z.ai coding endpoint (with optional language hint) |
zai_list_models |
List all available Z.ai models |
zai_stream_complete |
Streaming chat completion (collected into a single response) |
zai_set_config |
Update runtime config (API key, default model, temperature, max tokens) |
zai_estimate_cost |
Estimate cost for a given model and token count |
Skills are invoked with /zai-mcp-server:<skill> or triggered automatically when Claude detects a matching request.
| Skill | Trigger | Model Used |
|---|---|---|
zai-generate |
"generate code", "write a function", "implement this" | glm-4.5-air (default) / glm-5-turbo (complex) |
zai-review |
"review code", "find bugs", "audit this" | glm-4.5-air / glm-5-turbo |
zai-explain |
"explain this code", "what does this do" | glm-4.5-air |
zai-refactor |
"refactor this", "clean up", "simplify" | glm-4.5-air / glm-4.5 |
zai-test |
"write tests", "add test coverage" | glm-4.5-air |
zai-delegate |
"delegate this", "send to GLM", "save tokens on this" | glm-4.5-air |
zai-parallel-tasks |
"build in parallel", "fan out", "do these concurrently" | glm-4.5-air × N concurrent |
Instead of Claude generating code in its response (expensive), skills instruct Claude to:
- Read the relevant code locally (cheap — file reads don't cost output tokens)
- Send a targeted prompt to Z.ai via MCP tool call (cheap — GLM models cost ~10-50x less)
- Apply the Z.ai response directly to files (cheap — Edit/Write tools, minimal Claude output)
| Agent | Purpose | Model |
|---|---|---|
zai-coder |
End-to-end feature implementation. Claude plans, Z.ai writes all code. | sonnet (orchestrator) + glm-4.5-air/glm-5-turbo (code) |
zai-reviewer |
Code review and security audit. Reads locally, analyzes via Z.ai. | haiku (orchestrator) + glm-4.5-air/glm-5-turbo (analysis) |
zai-orchestrator |
Decomposes multi-file features into independent units and dispatches them in parallel to GLM workers. | sonnet (conductor) + N × glm-4.5-air (parallel workers) |
Use for substantial coding tasks — multi-file features, scaffolding, migrations. The agent:
- Reads and understands the codebase (using Claude)
- Generates ALL code via
zai_code_complete(using Z.ai glm-4.5-air or glm-5-turbo) - Applies and verifies the results
- Never writes code in its own response
Use for code review, PR review, security audit. The agent:
- Gathers diffs and reads changed files locally
- Sends code to
zai_chat_completewith a structured review prompt - Presents findings sorted by severity (CRITICAL > WARNING > INFO)
Use for any feature that decomposes into independent units across multiple files. The agent:
- Reads the codebase, splits the request into independent subtasks
- Generates any shared dependency once (e.g. types), then dispatches the rest as a single parallel batch of
zai_code_completecalls - Writes results, runs typecheck/tests once, and dispatches a parallel fix-batch if anything fails
- Wall-clock time becomes
max(unit)instead ofsum(units)— typically 3–5× faster than sequential
Example: "Use the zai-orchestrator agent to scaffold a User CRUD API — model, repository, controller, routes, and tests in parallel."
The plugin ships two hooks that activate automatically when installed:
| Hook | Event | Behavior |
|---|---|---|
session-start.sh |
SessionStart |
Verifies ZAI_API_KEY is configured and injects a one-paragraph reminder of available delegation paths |
user-prompt-router.sh |
UserPromptSubmit |
Detects heavy-codegen verbs ("scaffold", "in parallel", "write tests", "review", "refactor", etc.) and injects a hint pointing Claude at the matching zai-* skill or agent |
Hooks are non-blocking — they only add context. Disable them by removing "hooks": "./hooks/hooks.json" from plugin.json.
Models available from Z.ai API (tested with live key):
| Model | Type | Best for | Token behavior |
|---|---|---|---|
glm-4.5-air |
Non-reasoning | All general tasks, code gen, tests, review | All output tokens = content. Cheapest. |
glm-5-turbo |
Reasoning | Complex logic, algorithms, deep analysis | ~80% tokens = reasoning overhead. Set max_tokens >= 2000. |
glm-4.5 |
Reasoning | Quality code, alternative to glm-5-turbo | ~50% tokens = reasoning. |
glm-4.6 |
Reasoning | General purpose | Reasoning overhead varies. |
glm-4.7 |
Reasoning | General purpose | Reasoning overhead varies. |
glm-5 |
Reasoning | Advanced tasks | High reasoning overhead. |
glm-5.1 |
Reasoning | Most capable | ~95% tokens = reasoning. Very expensive per visible token. |
Default model: glm-4.5-air — non-reasoning, every token goes to actual output. Override per-call or globally via zai_set_config.
Important: Reasoning models need
max_tokens >= 2000even for short outputs. They spend most tokens on internal chain-of-thought that isn't visible in the response.
Send a chat completion request to Z.ai.
{
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Explain closures in JavaScript." }
],
"model": "glm-4.5-air",
"temperature": 0.7,
"max_tokens": 2048
}Optimized for code generation. Uses Z.ai's dedicated coding endpoint (/api/coding/paas/v4). Pass a language hint to prepend a system prompt automatically.
{
"messages": [
{ "role": "user", "content": "Write a binary search function" }
],
"language": "typescript",
"model": "glm-4.5-air"
}No parameters. Returns all available models with their IDs.
Same interface as zai_chat_complete but uses streaming internally. Useful when you want the server to handle chunked responses and return the full result.
Update any combination of runtime settings without restarting the server:
{
"api_key": "new-key",
"default_model": "glm-5-turbo",
"temperature": 0.5,
"max_tokens": 8192
}Estimate the cost before making a call:
{
"model": "glm-4.5-air",
"input_tokens": 1000,
"output_tokens": 500
}Returns a breakdown of input/output/total cost in USD.
Once installed, Claude automatically uses Z.ai via skills and agents:
/zai-mcp-server:zai-generate → "Write a REST API for user management in Express"
/zai-mcp-server:zai-review → "Review src/auth.ts for security issues"
/zai-mcp-server:zai-test → "Write tests for the UserService class"
/zai-mcp-server:zai-refactor → "Refactor this to reduce duplication"
/zai-mcp-server:zai-explain → "Explain how the caching layer works"
/zai-mcp-server:zai-delegate → "Delegate this to GLM — summarize the last 200 log lines"
/zai-mcp-server:zai-parallel-tasks → "Scaffold these 6 components in parallel"
Or use agents for larger tasks:
"Use the zai-coder agent to implement a full CRUD API for products with validation and tests."
"Use the zai-reviewer agent to review all changes on this branch."
"Use the zai-orchestrator agent to scaffold these 8 React components in parallel from the Figma spec."
Skills also trigger automatically when Claude detects matching requests — no slash command needed.
git clone https://github.com/kemalabuteliyte/zai-mcp-server.git
cd zai-mcp-server
npm install
npm run buildRun directly:
ZAI_API_KEY="your-key" node dist/index.js| Endpoint | Used by |
|---|---|
https://api.z.ai/api/paas/v4 |
zai_chat_complete, zai_stream_complete, zai_list_models |
https://api.z.ai/api/coding/paas/v4 |
zai_code_complete |
ISC