GLM 5.4 Claude Code Setup for 1M Context
Updated November 27, 2026
Z.ai and Claude Code documentation · AICodeKing cache measurements
Connect with a Z.ai Coding Plan key and launch Claude Code with glm-5.4[1m]. Verify the context window with /context before starting a repository-wide task.
- Context profile
- 1M tokens
- Claude Code model selection
- glm-5.4[1m]
- Off-peak credit rate
- 50% of standard
GLM 5.4 Claude Code setup starts with a Z.ai Coding Plan key, the Anthropic-compatible base URL and the explicit glm-5.4[1m] model selection. Use the commands below to open a long-context session, then verify the model and context window before loading a large repository.

Connect Claude Code to your Z.ai Coding Plan
Install Claude Code and run claude --version to verify the CLI is available. Z.ai’s Windows instructions also call for Git for Windows. Retrieve the API key for your active plan, then load it as ZAI_API_KEY in the terminal using your usual secret manager. Run one of the following examples from your project directory. Use the Anthropic Messages base URL as shown so the client can append its own request path. Z.ai’s Claude Code setup guide.
macOS and Linux with Bash
export ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic
export ANTHROPIC_AUTH_TOKEN="$ZAI_API_KEY"
claude --model 'glm-5.4[1m]'Windows PowerShell
$env:ANTHROPIC_BASE_URL = 'https://api.z.ai/api/anthropic'
$env:ANTHROPIC_AUTH_TOKEN = $env:ZAI_API_KEY
claude --model 'glm-5.4[1m]'Save the settings for future sessions
For a persistent configuration, merge this env block into ~/.claude/settings.json. On Windows, that is the .claude folder under your user profile. The alias mappings send Opus and Sonnet selections to GLM 5.4 and Haiku selections to GLM 5.3 Flash. Replace the placeholder locally if you store the token in this file, and keep the file out of shared repositories. If a secret manager already supplies the token, omit the token entry.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
"ANTHROPIC_AUTH_TOKEN": "YOUR_ZAI_API_KEY",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5.4[1m]",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5.4[1m]",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-5.3-flash[1m]"
}
}
Open a fresh terminal, launch with the same model flag and send a short prompt. If you also use Codex CLI or OpenCode, find the protocol-specific URL in the GLM 5.4 API setup guide.
Verify the 1M context window
Z.ai’s [1m] suffix tells Claude Code to use the long-context profile explicitly. Claude Code strips the suffix before sending the model ID to the provider. Versions before 2.1.323 assumed a 200K window for unrecognized model IDs without the suffix. Newer versions can assume 1M. Use the explicit spelling in both shell examples and run /context to check the window shown by Claude Code. If it still shows 200K, inspect your active settings for CLAUDE_CODE_DISABLE_1M_CONTEXT=1 or a context override. Claude Code gateway context and model configuration.
A larger window gives you room for related files, tool output and prior decisions. Narrow the first request to the paths and logs that matter, especially when testing the connection. The GLM 5.4 token counter estimates credits based on the input you send, the portion served from cache and the output generated.
Choose effort by task and measure cache reuse
For a quick fix, give the model a specific file or failing test, one acceptance condition and a stopping point. Start with --effort medium on a gateway that honors Claude Code’s effort flag. For a multi-file change, start with --permission-mode plan, review the proposed files and tests, then move to editing with normal approvals. Use GLM 5.4 for the plan and final diff review. A faster model such as GLM 5.3 Flash can handle well-scoped edits in between. Pass the reviewed plan and test list at the handoff. If the model gets stuck exploring alternatives, stop and restart from the last useful checkpoint with a smaller decision to make. For a longer build, agree on checkpoints by subsystem and ask for a passing test at each one. Compare elapsed time and test results across tasks before making high effort your default.
Z.ai’s setup example sets API_TIMEOUT_MS to 3000000 (50 minutes). Increase it for slow API requests only after confirming a timeout. In streaming sessions this setting governs how long a request attempt waits for response headers. Give long builds a separate elapsed-time budget and checkpoint work before retrying. Claude Code timeout settings.
Keep repository instructions and tool definitions stable at the start of the request. AICodeKing reported 90–92% cache hits on warm turns and 98.4% across KingBench 4. Measure your own workload across several turns. Compare a cold turn with subsequent turns in the same session and keep the model and tool set fixed during the comparison. Compare input token counts using the same measurement method. In Claude Code telemetry, divide cacheRead by input + cacheRead + cacheCreation from claude_code.token.usage when those counters are available. AICodeKing’s benchmark run and Claude Code token metrics.
Fix endpoint and concurrency errors
If you see 1113, check for a missing balance or resource package, then confirm the gateway and plan key. The metered base URL can route a request outside your subscription. If subagent bursts trigger 1302, pause the queue and resume with fewer simultaneous requests. Use the GLM 5.4 rate limits and 429 guide to distinguish these errors from exhausted credits. Compare GLM 5.4 Coding Plan tiers for sustained workloads and GLM 5.4 vs Claude Opus 5.5 for a planning or review workflow.
Related pages
Frequently asked questions
Which base URL does GLM 5.4 Claude Code use?
Use https://api.z.ai/api/anthropic as ANTHROPIC_BASE_URL, with the Z.ai Coding Plan key in ANTHROPIC_AUTH_TOKEN.
Why add [1m] to glm-5.4 in Claude Code?
The suffix explicitly selects Claude Code’s 1M context profile. Older clients assumed 200K for unrecognized model IDs without it.
Where do I save the Claude Code environment settings?
Merge the variables into the env object in ~/.claude/settings.json. Open a fresh session after changing the gateway or model mappings.
How can I confirm prompt cache hits?
If your Claude Code telemetry exposes token usage, compare cacheRead to total input tokens across successive turns in the same session.