Claude Code with Z.ai's GLM Coding Plan
Point Claude Code at Z.ai with the right key and model names, keep your Claude login side by side, and see how GLM credit pools differ from Claude limits.
What you need to run Claude Code with Z.ai's GLM Coding Plan
To run Claude Code with Z.ai's GLM Coding Plan, point Claude Code at Z.ai's Anthropic-compatible endpoint and give it a Coding Plan key. Six environment variables do the work: ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, API_TIMEOUT_MS and the three model variables. The Claude Code program stays the same. GLM is the model that answers, and Z.ai's meter counts your usage.
Everything below was checked against docs.z.ai and the Claude Code docs on 15 November 2026. Z.ai has changed this plan several times in 2026, so the dates matter.
One fact to accept before you start. With this setup, Claude Code sends your prompts, the files it reads and the output of the commands it runs to Z.ai's servers, not to Anthropic's. Read Z.ai's privacy policy yourself before you open a repository that holds client code or secrets.
Install Claude Code first
Z.ai's Claude Code page installs Claude Code with npm and asks for Node.js 18 or newer. Anthropic's own setup page now recommends a native installer, and its npm section asks for Node.js 22 or later. The native installer does not need Node.js at all, so the version question goes away.
curl -fsSL https://claude.ai/install.sh | bash
claude --versionA working install prints a version number such as 2.1.211 (Claude Code). If your shell says claude is not found, open a new terminal and try again. If it is still not found, the install directory is not on your PATH yet, and Anthropic's install troubleshooting page covers the fix. If Claude Code is already installed, run claude update instead.
Z.ai says it recommends the latest Claude Code and has "verified compatibility with Claude Code 2.0.14 and other versions." That tells you an old release worked. It does not tell you which current release they tested.
Get the right key: a Coding Plan key, not a standard API key
Z.ai has three kinds of key: Individual Coding Plan, Team Coding Plan, and the standard pay-as-you-go model API. You cannot swap one for another. Z.ai's key notice says "Changing the endpoint does not change the key's billing type." The key decides what you pay. The URL does not.
This is the mistake that costs money. A standard API key works in Claude Code, but it does not use your Coding Plan quota. Z.ai's notice says that using a standard key in a coding tool "does not consume your Coding Plan quota", so those calls may be charged pay-as-you-go instead.
Create the key in the right place:
- Individual plan (including trial card recipients): Personal Coding Plan, then Plan Overview.
- Team plan: Team Coding Plan, then My Plan.
Keys created on or after 16 October 2026 follow the type you chose when you created them. A legacy rule decides the type of older keys, so if you reuse an old key, check its type on the key page before you rely on it.
The settings Z.ai documents for Claude Code
Z.ai's manual configuration puts the variables in the env block of a Claude Code settings file. This is the core of it, with the model names from Z.ai's manual tab:
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "your_zai_coding_plan_key",
"ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
"API_TIMEOUT_MS": "3000000",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5.3[1m]",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5.3[1m]",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-5.3-flash[1m]",
"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1000000"
}
}What each line does:
ANTHROPIC_BASE_URLsends requests to Z.ai. Z.ai's FAQ giveshttps://api.z.ai/api/anthropicas the endpoint for Claude Code. The other URL,https://api.z.ai/api/coding/paas/v4, is the OpenAI-style endpoint for other tools. Do not use it here.ANTHROPIC_AUTH_TOKENis sent as theAuthorization: Bearerheader. In Claude Code's authentication order it sits aboveANTHROPIC_API_KEYand above the subscription login from/login. When it is set, Claude Code uses it instead of your Claude subscription.API_TIMEOUT_MSis how long each request attempt waits for the response headers. Claude Code's default is 600000 ms (10 minutes). Z.ai sets 3000000, which is 50 minutes. It does not limit how long a streaming answer runs after the headers arrive.CLAUDE_CODE_AUTO_COMPACT_WINDOWis set to 1000000 because Z.ai's model page asks for it together with the[1m]model names.
Z.ai's full example also sets CLAUDE_CODE_MAX_CONTEXT_TOKENS, CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC, DISABLE_TELEMETRY and CLAUDE_CODE_SIMPLE_SYSTEM_PROMPT. Routing and billing come from the base URL and the key, so this guide leaves those four out. Copy them from Z.ai's Claude Code page if you want the exact example.
Why you should set the three model variables yourself
Z.ai's docs give different model mappings in different places. On 15 November 2026 the docs had three versions, and old guides add a fourth:
- The default mapping table on the Claude Code page lists GLM-5.3-Flash for all three slots (Opus, Sonnet and Haiku).
- The manual settings example on the same page uses
glm-5.3[1m]for Opus and Sonnet, andglm-5.3-flash[1m]for Haiku. - The separate "How to Switch Models" page sets all three slots to
glm-5.3-flash[1m]. - Old guides written for GLM-5.2 set
glm-5.2. Z.ai's FAQ says only GLM-5.3 and GLM-5.3-Flash can be called on the plan, so change that name yourself (see the changes section below).
If you rely on a default, you cannot know which of these you get. Set all three variables, then confirm them in Claude Code. The mapping above is a reasonable start: full GLM-5.3 for the main slots, and Flash for the Haiku slot. If quota matters more to you than the strongest model, set all three to glm-5.3-flash[1m]. Z.ai's GLM-5.3-Flash page says Flash comes "with 3× the available quota compared with GLM-5.3" on the plan. GLM-5.3 accepts text input only. GLM-5.3-Flash also accepts images, video and files. Both have a 1M-token context window and 128K tokens of maximum output.
The [1m] suffix is how Z.ai turns on the 1M context window. Anthropic documents [1m] as a suffix for its own model names, so its behaviour on a GLM name is Z.ai's claim, not Anthropic's. If Claude Code reports that the model with the [1m] suffix does not exist, Z.ai's fix is to upgrade Claude Code with claude update and try again.
Keep your Claude login and Z.ai side by side
Z.ai's manual tab tells you to put these variables in ~/.claude/settings.json, and its install script writes them there. That file holds your user settings, so after this change every claude session in every project goes to Z.ai. If you also pay for Claude Pro or Max, you rarely want that.
There is a second reason to keep the variables out of that file. Claude Code's docs say that when the same variable is set in your shell and in a settings file env block, the settings file value applies in most sessions. An export in your shell will not undo a value in ~/.claude/settings.json. Use one of the two setups below instead. To learn why a token changes which account Claude Code bills, read using an API key instead of a subscription in Claude Code.
Option 1: a separate config directory and an alias
This is the setup most people should use. Each directory you name in CLAUDE_CONFIG_DIR has its own settings, session history and login, and Anthropic's authentication page uses this pattern to keep two accounts apart. Plain claude keeps using ~/.claude and your subscription. A second command, claude-zai, uses its own directory and your Z.ai key.
install -d -m 700 ~/.claude-zai
install -m 600 /dev/null ~/.claude-zai/settings.json
nano ~/.claude-zai/settings.jsonPaste the JSON from the section above into the file. Replace the placeholder with your real Coding Plan key, then save. Settings files are strict JSON. A trailing comma or a // comment makes Claude Code show a Settings Error at the next start. Then add the alias:
echo "alias claude-zai='CLAUDE_CONFIG_DIR=~/.claude-zai claude'" >> ~/.bashrc
source ~/.bashrcThe alias must live in your shell, because Claude Code's docs say project and local settings cannot set CLAUDE_CONFIG_DIR. The first launch of claude-zai walks through Claude Code's setup steps again, because the new directory has no saved state. Know two limits. Project files such as a repository's .claude/settings.json still apply in both modes, because they live in the project, not in the config directory. And mode 600 protects the key from other users on the machine. It does not protect it from programs running as you.
Option 2: a project-local settings file
Use this when one repository should always run on Z.ai. Claude Code reads .claude/settings.local.json inside the project. It applies only to you, in that project, and it overrides both the shared project file and your user settings.
mkdir -p .claude
nano .claude/settings.local.json
chmod 600 .claude/settings.local.json
echo '.claude/settings.local.json' >> .gitignore
git check-ignore -v .claude/settings.local.jsongit check-ignore -v should print the .gitignore line that matches the file. If it prints nothing, git will commit your key. When Claude Code itself creates this file, it adds the file to your global git excludes. A file you create by hand does not get that, so add the line yourself. The file may already exist and hold permission rules Claude Code saved for you. In that case, add the env block next to them instead of replacing the file.
Never put ANTHROPIC_AUTH_TOKEN in .claude/settings.json. That is the shared project file, and committing it publishes your key to everyone who can read the repository.
How to check that Claude Code is using Z.ai
Start a session with claude-zai, or with claude inside the project for Option 2. Z.ai notes that a new window is needed for changed settings to take effect, so close old sessions first.
- Run
/status. TheSetting sourcesline should list the file you edited: your user settings for Option 1,Project local settingsfor Option 2. The same screen shows which authentication method is active. It should be the token, with your subscription login marked as not in use. - Run
/model. The model should be one of the GLM names you set, not a Claude model name. - Send one short prompt. Then open the Coding Plan page in your Z.ai account and confirm that credits were used.
Do not skip step 1. Claude Code's model docs warn about one case: if ANTHROPIC_BASE_URL points at a gateway and your saved claude.ai login stays the active credential, Claude Code does not check your plan's usage credits. A missing or misspelled ANTHROPIC_AUTH_TOKEN puts you in exactly that case.
How to switch back to your Claude subscription
- Option 1: run plain
claude. It never reads~/.claude-zai, so nothing needs to change. - Option 2: delete the
envblock from.claude/settings.local.json, keep any permission rules, and start a new session. - Variables exported in your shell: run
unset ANTHROPIC_AUTH_TOKEN ANTHROPIC_BASE_URL API_TIMEOUT_MS ANTHROPIC_DEFAULT_OPUS_MODEL ANTHROPIC_DEFAULT_SONNET_MODEL ANTHROPIC_DEFAULT_HAIKU_MODEL, then relaunchclaude. Claude Code reads shell variables only at startup. - If you followed Z.ai's page or script: remove the same keys from the
envblock in~/.claude/settings.json.
Setting the token does not delete your subscription login. The login is lower in the order, so once the token is gone, Claude Code uses the login again. Run /status to confirm. If the subscription is still not active, run /login. /logout also works, but it resets the first-launch setup state too. Claude Desktop and cloud sessions do not read these variables, so they always use your Claude account.
How Z.ai's GLM Coding Plan meters usage compared with Claude
Z.ai counts credits. Each tier has two pools: one that refreshes over five hours, and one that resets weekly. These are the figures on Z.ai's overview page, checked on 15 November 2026.
The data behind this chart
[
{
"plan": "Lite",
"credits_5h": "2,000",
"credits_7d": "10,000"
},
{
"plan": "Pro",
"credits_5h": "12,000",
"credits_7d": "60,000"
},
{
"plan": "Max",
"credits_5h": "28,000",
"credits_7d": "140,000"
}
]Lite gets 2,000 credits per five hours and 10,000 per week. Pro gets 12,000 and 60,000. Max gets 28,000 and 140,000. Z.ai's overview says plans start at 18 USD per month. It does not list Pro or Max prices, so check the subscribe page for those.
The two pools refresh in different ways. Z.ai says five-hour credits are "dynamically refreshed": each use comes back five hours after you spend it. The weekly pool starts when you subscribe and resets every 7 days from then.
A credit is not a fixed number of tokens. Z.ai works out the credits for each request from its input tokens, cached input tokens and output tokens. Each count is multiplied by a per-model figure, and the total is divided by 10,000. A request that sends a large context costs more credits than a short one, even for the same question.
Time of day changes the price. Z.ai defines peak hours as Monday to Friday, 14:00 to 18:00 Singapore Standard Time (UTC+8). That is 06:00 to 10:00 UTC. Outside those hours, model usage is charged at 50% of the standard credit rate, and Z.ai's model pages say weekends count as off-peak all day. Z.ai's 30 July 2026 notice describes the same idea with per-model multipliers instead, and the two pages do not give the same discount. Treat the overview as current and watch your own usage.
If you bought before the credit system arrived, your numbers may differ. Z.ai's notice says existing subscriptions keep their price, limits and calculation method until the end of the current billing cycle.
What Claude's limits look like next to this
Anthropic's help article on usage limits describes a five-hour limit that starts with your first message and resets five hours later. Weekly limits apply on top of that, across all models. Usage on claude.ai, Claude Code and Claude Desktop counts towards the same limit. The article gives no credit or token figures, and it says Anthropic may adjust limits to manage capacity. So you cannot honestly put a Claude number next to a Z.ai number, because the two vendors do not publish their sizes in the same terms.
What you can compare is the shape. Claude's five-hour window opens with your first message. Z.ai's five-hour credits come back piece by piece, five hours after each use. Z.ai prices by time of day, and Claude's article describes no time-of-day rate. For how Claude's windows behave in practice, read how Claude's usage limits work and when the Claude Max limits reset.
The meters are separate. Z.ai counts the requests you send to it with a Z.ai key, and they do not count against your Claude plan. Running both gives you two budgets, which is the main reason to keep the setups side by side. If you are deciding whether to drop the Claude plan entirely, using an open model instead of a Claude plan covers that trade.
Z.ai also sets rules for how you use the plan. Its usage policy says you may use the Coding Plan only in officially supported tools, and "Account sharing or multi-user access is prohibited." Z.ai may ban accounts with more than three violations. The subscription terms say paid subscriptions renew automatically. They also say payments are non-refundable, except where the law requires a refund or the terms state one.
What changed since the GLM-5.2 guides
If you followed a guide written in mid-2026, several details are now different:
- On 30 July 2026, Z.ai announced that the GLM Coding Plan was moving to a credits-based system. Guides written before then describe the older plans.
- GLM-5.3 (released 18 August 2026) and GLM-5.3-Flash (26 August 2026) are now on every tier: Lite, Pro and Max.
- Z.ai's FAQ says "Only the following two models can be called: GLM-5.3, GLM-5.3-Flash." It lists calling any other model as one cause of error
1113 Insufficient Balance. An oldglm-5.2setting needs to be changed to one of those two names. - Z.ai's own Claude Code examples now use
[1m]model names. - Keys created on or after 16 October 2026 follow the type you chose when you created them.
The plan is one way to use GLM. The other is to run the open weights yourself, and running GLM-5.2 on your own VPS covers that route.
Running this on a VPS
Option 1 works the same on a Linux server. Put the config directory in your home directory there, keep the file at mode 600, and use the alias. You lose one feature: as of v2.1.196, Claude Code disables Remote Control when ANTHROPIC_BASE_URL points at a host other than api.anthropic.com. To keep a long session alive on the server, run it inside tmux instead, as in running Claude Code on a VPS with tmux.
Errors you will see, and what causes them
1113 Insufficient Balance. Z.ai's FAQ lists this error for people who have already bought a plan. It says the error, or a deduction from your account balance, can come from not meeting the usage conditions of the Coding Plan. The usual cause is a standard API key in place of a Coding Plan key. The second cause is the wrong base URL. Create a key on the Coding Plan page and use https://api.z.ai/api/anthropic. Because these calls can take money from your account balance, check that balance after you fix the setup.
Claude Code says the [1m] model does not exist. Z.ai's fix is to upgrade Claude Code. Run claude update, then start a new session.
Your Claude plan usage goes up instead of your Z.ai credits. The subscription login is the active credential. That happens when ANTHROPIC_AUTH_TOKEN is missing or the settings file did not load. Run /status and read the Setting sources line and the authentication method.
A change to the file has no effect. Claude Code reloads settings files while it runs, but Z.ai's docs say to close all Claude Code windows and start claude in a new terminal. Do that before you debug anything else. If the file has a JSON error, Claude Code shows a Settings Error at start, and claude doctor lists the details.
FAQ
Can I use a normal Z.ai API key with Claude Code?
It works, but it does not use your GLM Coding Plan quota. Z.ai bills by key type, and a standard key in a coding tool may be charged pay-as-you-go even if you also have a subscription. Changing the endpoint does not change that. Create a key on the Personal Coding Plan or Team Coding Plan page instead.
Does Z.ai usage count against my Claude Pro or Max limits?
No. When ANTHROPIC_BASE_URL points at Z.ai and ANTHROPIC_AUTH_TOKEN holds your Z.ai key, the requests go to Z.ai and use Z.ai credits. Make sure the token is really set. If your claude.ai login stays the active credential, Claude Code does not check your plan's usage credits. Run /status to see which credential is in use.
Which GLM model should I set for Opus, Sonnet and Haiku?
Set all three explicitly, because Z.ai's docs show different defaults on different pages. A good start is glm-5.3[1m] for ANTHROPIC_DEFAULT_OPUS_MODEL and ANTHROPIC_DEFAULT_SONNET_MODEL, and glm-5.3-flash[1m] for ANTHROPIC_DEFAULT_HAIKU_MODEL. To stretch your quota, set all three to glm-5.3-flash[1m]. Z.ai says Flash gives three times the available quota of GLM-5.3 on the plan. Confirm the result with /model.
When are Z.ai's peak hours in UTC?
Z.ai defines peak hours as Monday to Friday, 14:00 to 18:00 Singapore time (UTC+8). That is 06:00 to 10:00 UTC. Outside that window, and all day at weekends, Z.ai charges model usage at 50% of the standard credit rate. These figures were checked on 15 November 2026. Z.ai changes its terms, so check its overview page before you plan around them.
How do I switch Claude Code back to my Claude subscription?
Remove the Z.ai variables. Unset them in your shell, or delete the env block from the settings file that holds them, then start a new session. ANTHROPIC_AUTH_TOKEN outranks the subscription login, so once the token is gone, Claude Code uses your saved login again. Run /status to confirm, and run /login if the subscription is still not active. With the separate config directory setup, plain claude already uses your subscription.