Use Claude Code with GLM or Kimi models: setup and limits
Point Claude Code at GLM or Kimi with the provider's base URL, key and model names. Most of it works; your Claude plan no longer applies.
Contents
To use Claude Code with GLM or Kimi, point it at the provider's Anthropic-compatible endpoint: set ANTHROPIC_BASE_URL to Z.ai's or Moonshot's address, ANTHROPIC_AUTH_TOKEN to that provider's key, and the model variables to its model names. Claude Code then sends every request there instead of to Anthropic. Most of it works; some features don't, and your Claude plan no longer applies.
People do this for a cheaper model, a second set of limits, or a fallback when their Claude limit runs out. The setup below is each provider's own, as their docs gave it on 22 October 2026.
How an Anthropic-compatible endpoint works#
Claude Code talks to Anthropic's Messages API. A provider that serves the same API shape at its own address can stand in for it. Three settings do it.
ANTHROPIC_BASE_URLis where requests go.ANTHROPIC_AUTH_TOKENis the key sent with them. Anthropic's gateway docs say that while a gateway credential is set, requests carry it "in place of a developer's claude.ai subscription login, and the subscription's usage limits don't apply to them". Setting only the base URL, without a token, keeps your claude.ai sign-in as the credential.- The model variables (
ANTHROPIC_MODELandANTHROPIC_DEFAULT_OPUS_MODEL,_SONNET_MODELand_HAIKU_MODEL) say which of the provider's models answers when Claude Code asks for each tier. Once you set the Haiku one, Claude Code also uses it for background tasks.
Anthropic says it "doesn't support routing Claude Code to non-Claude models through any gateway". It works, but support comes from the provider, not Anthropic. The same settings can point Claude Code at a model on your own computer, which our guide to Claude Code with Ollama covers.
Setup for GLM (Z.ai)#
From Z.ai's Claude Code page, as of 22 October 2026. You need a GLM Coding Plan and a key from the Z.ai platform.
| Setting | Value |
|---|---|
ANTHROPIC_BASE_URL |
https://api.z.ai/api/anthropic |
ANTHROPIC_AUTH_TOKEN |
your Z.ai API key |
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] |
API_TIMEOUT_MS |
3000000 |
Z.ai's plan overview says plans start at $18 a month (Lite, Pro and Max tiers) and, like Claude's, each has a 5-hour limit and a weekly limit, counted in credits: 2,000 credits per 5 hours and 10,000 a week on Lite, 12,000 and 60,000 on Pro, 28,000 and 140,000 on Max. Usage outside its weekday peak hours (14:00 to 18:00 Singapore time) costs half the credits.
Setup for Kimi (Moonshot)#
From the Kimi platform's Claude Code guide, as of 22 October 2026:
| Setting | Value |
|---|---|
ANTHROPIC_BASE_URL |
https://api.moonshot.ai/anthropic |
ANTHROPIC_AUTH_TOKEN |
your Moonshot API key |
ANTHROPIC_MODEL |
kimi-k3[1m] |
ANTHROPIC_DEFAULT_OPUS_MODEL and _SONNET_MODEL |
kimi-k3[1m] |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
kimi-k2.7-code |
CLAUDE_CODE_SUBAGENT_MODEL |
kimi-k3[1m] |
Moonshot warns to remove ANTHROPIC_API_KEY if you have it set, because it conflicts with ANTHROPIC_AUTH_TOKEN. It also notes that kimi-k2.7-code has thinking forced on: with thinking off it answers 400 invalid thinking, so turn thinking on (Option+T on a Mac, Alt+T elsewhere) before you use it.
Where to put the settings#
Both providers' guides put these in the env block of ~/.claude/settings.json. That works, but it switches every Claude Code session on the machine to that provider. We prefer one shell alias per provider, so plain claude stays on Anthropic:
# ~/.zshrc or ~/.bashrc. Keep the keys in your keychain or secret store, not in this file.
alias claude-glm='ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic \
ANTHROPIC_AUTH_TOKEN="$ZAI_API_KEY" \
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]" \
API_TIMEOUT_MS=3000000 claude'
alias claude-kimi='ANTHROPIC_BASE_URL=https://api.moonshot.ai/anthropic \
ANTHROPIC_AUTH_TOKEN="$MOONSHOT_API_KEY" \
ANTHROPIC_MODEL="kimi-k3[1m]" \
ANTHROPIC_DEFAULT_OPUS_MODEL="kimi-k3[1m]" \
ANTHROPIC_DEFAULT_SONNET_MODEL="kimi-k3[1m]" \
ANTHROPIC_DEFAULT_HAIKU_MODEL="kimi-k2.7-code" \
CLAUDE_CODE_SUBAGENT_MODEL="kimi-k3[1m]" claude'
Send a short prompt and check that it shows up on the provider's usage page before you start real work.
What breaks, and why#
Anthropic's gateway compatibility guide is written for gateway operators, but it explains what to expect when the model behind the address isn't Claude:
- Context size is a guess. For a model ID Claude Code doesn't recognise, it assumes 200K tokens, or 1M "when the ID carries
[1m]". That's why both providers' model names end in[1m]. If the real window is smaller, compaction comes late and requests fail as too long. - Thinking and effort. Claude Code sends unrecognised models the same fields as current Claude models, adaptive thinking and effort included. When the endpoint rejects the thinking type, Claude Code retries once with the other type; when it rejects effort, it drops it.
- Beta features. Claude Code sends its full set of beta headers and fields. If the endpoint turns some down with
400errors,CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1stops the pre-release ones, MCP tool search included. - Prompt caching. Claude Code marks what to cache. If the endpoint ignores the markers, "the conversation bills as uncached input on every turn". Check the provider's usage page after a session.
- Token counts are estimates when the endpoint has no token-counting route, so
/contextshows approximate numbers. - The model picker. Claude Code's model discovery keeps only IDs that contain
claudeoranthropic, so GLM and Kimi models won't appear in/modelthat way. Set them with the variables above. - Some calls still go to Anthropic. Fast mode's availability check and the WebFetch domain safety check call
api.anthropic.comdirectly.
Quality is the other half. Claude Code's prompts and tools are tuned for Claude. Another model may follow them well or less well, and that varies by task; try it on real work before you depend on it.
Terms to check#
- The provider's terms. Z.ai's plan page lists Claude Code among the agent tools its Coding Plan can be used with. Read Moonshot's and Z.ai's terms for what counts as allowed use, and where your data is processed.
- Your code goes to that provider. Every prompt, file Claude reads and command output now goes to Z.ai or Moonshot instead of Anthropic. Make sure that's acceptable for the repository.
- Anthropic's support ends at the address. Problems with the model's answers are the provider's to fix.
How Shuriken does it#
In Shuriken, a GLM or Kimi endpoint is a source like any of your Claude accounts. Add it under Sources › Add source › Custom endpoint, with the address and its key, and press Test. You set which of its models answers when Claude asks for each tier, and Shuriken recognises the endpoint as Zhipu or Moonshot. The key sits in your encrypted vault, not in a shell file.
An endpoint never goes ahead of your Claude subscriptions. It takes chats when you pick it (Use), and once every Claude source you added is out, a Claude Code chat can carry on there between turns. Our post on what a source is explains the order, and API keys as a last resort covers the setting for keys. Shuriken doesn't bill model usage: the endpoint's provider bills you, as with any API key. If you'd like a second provider ready for when your Claude limits run out, download Shuriken.
Try the free tool: Claude limit reset tracker
Sources
- Claude Code setup (Z.ai developer docs) (accessed 22 October 2026)
- GLM Coding Plan overview (Z.ai developer docs) (accessed 22 October 2026)
- Use Kimi in Claude Code (Kimi API platform docs) (accessed 22 October 2026)
- Other LLM gateways (Claude Code docs) (accessed 22 October 2026)
- Claude Code gateway compatibility guide (Claude Code docs) (accessed 22 October 2026)
Frequently asked questions
Can Claude Code use other models than Claude?
Yes, through any endpoint that speaks Anthropic's Messages API, such as Z.ai's for GLM or Moonshot's for Kimi. Anthropic says it doesn't support routing Claude Code to non-Claude models, so you're on the provider's support.
Does my Claude subscription still apply when I use GLM or Kimi?
No. With ANTHROPIC_AUTH_TOKEN set, requests carry that provider's key instead of your claude.ai sign-in, so the provider's plan or billing applies and your Claude limits don't.
Why does Claude Code show the wrong context size for GLM or Kimi?
Claude Code assumes 200K tokens for a model ID it doesn't recognise, or 1M when the ID ends in [1m]. That's why both providers' setup uses model IDs with the [1m] suffix.
How do I switch back to Claude?
Start Claude Code without those variables. If you put them in ~/.claude/settings.json, remove the env block; a shell alias per provider avoids that.