You like the Claude Code loop — the terminal, the file edits, the agent that plans and runs tests — but the per-token bill on a long session makes you flinch. Here's the good news: the loop is client-side. The model is just an endpoint the client calls, and Claude Code will happily call a different one. In five minutes you can keep the entire workflow and run it on GLM-5.2, an open-weight, MIT-licensed model with a 1M-token context window, billed as a flat monthly plan instead of by the token. (For the strategic version of this decision — whether to adopt the open-weight stack at all — see our three-way breakdown of ZCode vs Cursor 3 vs Claude Code.)
The whole trick is two environment variables and one endpoint path. Here it is up front.
The fast path (30 seconds)#
Get a key from your Z.ai GLM Coding Plan, then run the helper:
npx @z_ai/coding-helper
Paste your key when prompted; it writes the endpoint, credential, and model mappings into ~/.claude/settings.json for you. Restart your terminal, start claude, and you're on GLM-5.2. If that's all you wanted, you're done — skip to Verify below.
The manual path (see every value)#
If you'd rather understand what changed, set three variables yourself. Export them in your shell profile (~/.zshrc or ~/.bashrc):
export ANTHROPIC_BASE_URL="https://api.z.ai/api/anthropic"
export ANTHROPIC_AUTH_TOKEN="your_zai_key_here"
export API_TIMEOUT_MS=3000000 # long agentic runs need a generous timeout
Use https://api.z.ai/api/anthropic for USD billing and access outside mainland China; use the open.bigmodel.cn equivalent for CNY billing and mainland access. The two endpoints speak the identical protocol — pick by currency and location.
Then map the tiers Claude Code expects onto Z.ai model IDs in ~/.claude/settings.json:
{
"env": {
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5.2",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5.2",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air"
}
}
The main and reasoning tiers go to glm-5.2; the fast "Haiku" tier goes to a smaller model like glm-4.5-air. Z.ai's Claude Code doc lists the current IDs — check it, because model IDs churn faster than the setup does. Restart the terminal so the new environment is picked up.
The three mistakes that break it#
Almost every failed setup is one of these:
- Wrong URL path. The endpoint is
/api/anthropic, not the general/api/paas/v4URL. The general path speaks a different protocol and Claude Code will 404 or return malformed responses against it. - Wrong variable name. Z.ai's key goes in
ANTHROPIC_AUTH_TOKEN, notANTHROPIC_API_KEY. Put it in the wrong one and the client may reach for a different credential path and throw auth errors. SetAUTH_TOKEN, and leaveAPI_KEYempty to remove the ambiguity. - No restart. Editing
settings.jsonor exporting variables does nothing until the shell reloads. Close the terminal and reopen it — don't just re-runclaude.
Verify#
Start a session and give it something trivial so you can watch the model line, not the answer:
claude
> what model are you and what's your context window?
If it responds as GLM-5.2 with a large context, the swap worked. Now stress it on a real task — a multi-file refactor with tests — and watch the loop run end to end.
The billing you just switched to#
You didn't only change models; you changed the shape of the bill. The GLM Coding Plan is flat: $18/month (Lite), $72/month (Pro), and $160/month (Max), with a launch discount around 30%. Each tier caps prompts per 5-hour window — roughly 80, 400, and 1,600 — rather than metering tokens. A long agentic session that would rack up token charges elsewhere just draws down a window here. Predictable spend is the real product.
Keep both, and A/B the hard stuff#
Because this is all environment variables, you can keep your normal Anthropic account live in a second shell. Run high-volume everyday coding on the flat-rate GLM-5.2 open-weight profile; when you hit a genuinely hard problem, drop into the other terminal and let a frontier tier take it. Same client, same muscle memory, two engines — and now the choice of which one runs your next task is a one-window decision instead of a billing commitment.



