Use Chinese LLMs in Claude Code: DeepSeek and GLM Setup Guide
A practical guide to running Claude Code with Anthropic-compatible endpoints from DeepSeek and Zhipu GLM, including environment variables, model routing, verification, and safety notes.
Claude Code is useful because it works directly inside a terminal: it can read a repository, propose edits, run commands, and keep code changes close to the developer workflow. For developers in China, one practical setup is to keep Claude Code as the coding interface while routing model calls to Chinese LLM providers that expose Anthropic-compatible endpoints.
This guide compares two official paths: DeepSeek's Claude Code integration and Zhipu AI's GLM Coding Plan integration. The goal is not to hide which model is being used. The goal is to make the model routing explicit, reproducible, and safe enough for daily engineering work.
1. What This Setup Actually Changes
Claude Code itself is still the terminal coding agent. The provider change happens at the API layer.
Instead of sending requests to Anthropic's default endpoint, Claude Code reads Anthropic-compatible environment variables or settings and sends model calls to another base URL. DeepSeek documents this through environment variables such as ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, and model variables. Zhipu documents a similar path through the Claude settings file, pointing ANTHROPIC_BASE_URL to the GLM Anthropic-compatible endpoint.
That means the local workflow stays familiar: install Claude Code, enter a codebase, run claude, inspect diffs, and run tests. The important differences are model names, endpoint URL, quota behavior, and provider-specific compatibility notes.
2. Prerequisites
Install Node.js 18 or newer. On macOS and Linux, using a version manager such as nvm is usually cleaner than installing Node globally with system permissions. On Windows, install Git for Windows as well.
Then install Claude Code:
npm install -g @anthropic-ai/claude-code
Verify the installation:
claude --version
Do not put API keys into source code, shell history shared with teammates, screenshots, or public issue comments. Treat the provider key as a secret even when it is only used locally.
3. Option A: DeepSeek With Claude Code
DeepSeek's official guide uses the Anthropic-compatible endpoint:
https://api.deepseek.com/anthropic
For macOS or Linux, export these variables in the terminal where you will run Claude Code:
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic export ANTHROPIC_AUTH_TOKEN=your_deepseek_api_key export ANTHROPIC_MODEL=deepseek-v4-pro[1m] export ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-v4-pro[1m] export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-v4-pro[1m] export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v4-flash export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-v4-flash export CLAUDE_CODE_EFFORT_LEVEL=max
For Windows PowerShell, use the same values through $env variables.
The practical model split is straightforward: route heavier planning and code-editing work to the pro model, and route lighter subagent work to the flash model. After setting the variables, open a project directory and start Claude Code:
cd /path/to/my-project claude
Use a small repository first. Ask Claude Code to inspect files, explain the project, or make a low-risk documentation edit. Then check the diff and run the project's tests before trusting it with larger refactors.
4. Option B: Zhipu GLM Coding Plan With Claude Code
Zhipu's official guide points Claude Code to this Anthropic-compatible endpoint:
https://open.bigmodel.cn/api/anthropic
Zhipu recommends configuring Claude Code through the settings file. On macOS and Linux, edit ~/.claude/settings.json. On Windows, edit the corresponding .claude/settings.json under the user directory.
A minimal manual configuration looks like this:
{ "env": { "ANTHROPIC_AUTH_TOKEN": "your_zhipu_api_key", "ANTHROPIC_BASE_URL": "https://open.bigmodel.cn/api/anthropic", "API_TIMEOUT_MS": "3000000", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": 1 } }
Zhipu also documents setting ~/.claude.json with hasCompletedOnboarding true, which avoids repeating Claude Code onboarding steps in some setups:
{ "hasCompletedOnboarding": true }
By default, Zhipu describes a server-side model mapping where Claude Code may show Claude model labels while the actual backend model is GLM. The documented default mapping includes GLM-4.7 for Opus and Sonnet style routes, and GLM-4.5-Air for Haiku style routes.
If your plan supports GLM-5.1 or GLM-5-Turbo and you want to route higher-end work there, add or replace model variables in ~/.claude/settings.json:
{ "env": { "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air", "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5-turbo", "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5.1" } }
After changing settings, close the old terminal window and open a new one. Then run claude inside your project. In Claude Code, use /status to confirm the current model state.
5. Which Provider Path Should You Choose?
Choose DeepSeek when you want a simple shell-variable setup, explicit model names, and a quick way to test Claude Code without modifying settings files. This is convenient for temporary experiments, project-specific terminals, and scripts that intentionally set provider variables per session.
Choose GLM Coding Plan when you prefer a persistent Claude Code configuration under ~/.claude/settings.json, or when your team already uses Zhipu's coding plan and wants centralized quota behavior. This is convenient for developers who want Claude Code to start with the same provider configuration every time.
In both cases, do not judge the setup only by whether the first prompt works. Test it with the work you actually care about: reading a medium-sized codebase, editing multiple files, running a test command, recovering from a failed test, and explaining the final diff.
6. Verification Checklist
First, verify that claude --version works.
Second, verify the provider route. For DeepSeek, print the relevant environment variables in the current terminal and confirm the base URL and model names. For GLM, inspect ~/.claude/settings.json and make sure the JSON is valid.
Third, start Claude Code in a disposable or low-risk project. Ask it to read the README, summarize the architecture, and make a small documentation-only change.
Fourth, inspect the diff manually. A coding agent can move quickly, but it can still misunderstand local conventions, delete useful context, or choose a broad refactor when a small change is enough.
Fifth, run the project's normal checks: lint, typecheck, test, and build. If the project does not have those scripts, add or document a smaller verification command before using the agent for larger changes.
7. Common Failure Modes
If Claude Code ignores a manual GLM settings change, restart all Claude Code sessions and open a new terminal. Also validate that settings.json is valid JSON: a missing comma is enough to make the configuration fail.
If requests time out on larger tasks, increase timeout only after confirming the provider endpoint and key are correct. Long timeouts hide network and quota issues if used too early.
If model behavior feels inconsistent, check whether you are routing Opus, Sonnet, Haiku, and subagent calls to different models. Mixed routing can be useful, but it should be intentional.
If the agent starts making risky edits, narrow the task. Ask it to inspect first, explain the files it plans to touch, and then implement. Do not give a broad instruction such as "optimize the whole project" in a production repository.
8. Engineering Safety Rules
Use Claude Code as an accelerant, not as an unreviewed committer.
Keep secrets out of the repository. Keep API keys in local environment variables, shell profiles, settings files outside the repo, or secret managers. Never commit ~/.claude/settings.json into a project.
Give the agent small, reviewable tasks. The best early tasks are documentation updates, test fixes, localized refactors, and code explanation. The worst early tasks are broad rewrites, authentication changes, billing logic, database migrations, and security-sensitive edits.
Always review the diff before accepting changes. For production repositories, require the same checks you would require from a human teammate: type safety, tests, migration review, and security review.
When AI-generated code touches user data, admin permissions, payment, authentication, or publishing workflows, add a human approval gate. A coding agent can draft the change, but it should not be the final authority.
9. A Practical First Prompt
After setup, start with a prompt like this:
Read this repository and explain the architecture in five bullets. Then identify the safest small improvement you can make without changing runtime behavior. Do not edit files until you list the files you plan to touch.
This prompt forces the agent to inspect first, make a narrow proposal, and separate analysis from editing. Once you trust the route and output quality, you can move to real implementation tasks.
Conclusion
The useful pattern is not "replace Claude with a Chinese model" or "pretend all models behave the same." The useful pattern is to keep Claude Code's strong terminal workflow while making the model backend explicit.
DeepSeek is convenient for environment-variable based routing. Zhipu GLM is convenient for persistent Claude Code settings and coding-plan users. Both approaches can work, but both still require developer review, repository checks, and careful task boundaries.
For engineering teams, the deciding factor should be operational reliability: can the setup be reproduced, can model routing be inspected, can secrets stay out of git, and can every AI edit go through normal review before it reaches production?