glm-mcp — GLM as a cheap delegate for your AI coding agent
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
**GLM** (Zhipu / Z.ai) as a **~10x cheaper** delegate for your AI coding agent. Your expensive
main model — **Claude Opus**, **Copilot's** default, or **Codex** — orchestrates and reviews; **GLM** does
the actual work, billed on cheap GLM tokens. GLM exposes an Anthropic-compatible /v1/messages
endpoint, so it drops into anything that already speaks Anthropic. This repo wraps it as an
**MCP server** with four tools, plus one-command installers for **Claude Code**, **GitHub Copilot**,
and **Codex**. The same server powers every edition.
How it works
Plain-English walkthrough:
1. **You ask** the main agent for work.
2. The **main agent delegates** via glm_agent — it passes a goal plus an absolute workdir.
3. The server's **router** picks a GLM model (peak-aware) and calls the **Z.ai** /v1/messages
endpoint; the **cost bias** keeps GLM the default.
4. GLM runs **its own agent loop** (read_file / write_file / edit_file / list_dir /
run_bash) directly against your repo, then stops with a summary.
5. The server returns a **concise summary + a GLM STATS block** (model, tokens, est. cost) to
the main agent.
6. The main agent **reviews**; every GLM call is also appended to the usage.jsonl **ledger**.
**Token economics.** Delegated work bills **GLM tokens** (~10x cheaper). The main model only
pays for orchestration + review. A **near-100% GLM share** requires the full-GLM launcher
(claude/glm-code.mjs), because a hybrid main agent always carries
per-turn session context — that context is the floor on its token share.
The four tools
| Tool | Cost | What it does |
|---|---|---|
| glm_agent | GLM tokens | GLM as a real coding agent in your repo (read/write/edit/run). dry_run: true previews a diff and writes nothing; after a real run a **git-checkpoint revert line** is printed. |
| glm_delegate | GLM tokens (opt-in) | Pure text generation — text in, text out. **Hidden by default** (glm_agent handles text-only tasks too); set GLM_DELEGATE=on to expose it. |
| glm_recommend | free (local) | GLM-vs-main-model advisory: which engine, which GLM model, confidence, and reasons. No GLM call. |
| glm_status | free (local) | Peak window, active model, **usage-ledger totals** (proof of GLM spend), and config health. No GLM call. |
**Live progress.** glm_agent streams MCP **progress notifications** while it runs —
current iteration, token count, and **tok/s** — shown live in Claude Code and mapped to
tool.execution_progress in VS Code Copilot. This heartbeat also keeps long calls alive on clients that
reset their timeout on progress, and cancelling a run stops GLM **promptly** (partial changes are shown
and revertable). max_tokens defaults to **auto** (uncapped/generous; the orchestrating agent may
pass a number to cap a call). The server uses an **idle/stall timeout** (GLM_STALL_TIMEOUT_MS, 2 min),
so an actively-streaming turn is never cut off. If a very long run is still cancelled by your client's
tool-call timeout, raise it with MCP_TOOL_TIMEOUT / CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUT.
Install
(a) Claude Code
Installs **globally by default** (user-scoped): the MCP server, a full-tool **glm subagent**, a
**PreToolUse auto-routing hook**, and an optional **glm-code** full-GLM launcher. Restart
Claude Code, then run glm_status to confirm api_key_loaded: true.
Full details: claude/README.md.
(b) GitHub Copilot / VS Code
Installs the MCP server in **agent mode**, a **GLM custom agent (subagent)**, a **PreToolUse
auto-routing hook**, and delegation **instructions files**. Reload the VS Code window, open
Copilot Chat in Agent mode, start the glm server.
Full details: copilot/README.md.
(c) Codex
Install the published Codex package:
Installs a Codex MCP registration, a glm custom agent, the glm-delegate skill, and an advisory