How to Use GLM-4.6 with Claude Code CLI for Coding (2026 Step-by-Step Guide)
I was staring at my Anthropic billing statement. $20/month for Claude Code Plus. Not terrible, but it adds up. A Reddit thread caught my eye—someone tested 5 Chinese LLMs for coding and found GLM-4.6 from Z.AI cost only $6/month while handling Sonnet-level tasks. I decided to give it a try.
The challenge: Claude Code CLI doesn’t natively support switching API providers. It’s built to talk to Anthropic’s servers only. But here’s the thing—Z.AI offers an Anthropic-compatible API endpoint. If I could redirect Claude Code’s API calls to Z.AI instead, I could use GLM-4.6 without changing my workflow.
First I installed Claude Code CLI globally:
npm install -g @anthropic-ai/claude-codeNext I needed a Z.AI API key. I went to https://z.ai, created an account, and generated a new key in the API Keys section. It started with sk- just like Anthropic’s format.
Now for the actual configuration. Claude Code reads settings from ~/.claude/settings.json. I opened that file and added:
{ "env": { "ANTHROPIC_AUTH_TOKEN": "sk-your-zai-api-key", "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic", "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.6", "ANTHROPIC_MODEL": "glm-4.6" }}Here’s what each setting does:
ANTHROPIC_AUTH_TOKENpoints to my Z.AI key instead of Anthropic’sANTHROPIC_BASE_URLredirects all API calls to Z.AI’s Anthropic-compatible endpointANTHROPIC_DEFAULT_SONNET_MODELtells Claude Code to use GLM-4.6 when it would normally request SonnetANTHROPIC_MODELsets GLM-4.6 as the default model
I saved the file, opened a new terminal session (important—environment variables don’t reload in existing sessions), and ran:
claudeThe startup message showed “API Usage Billing” instead of “Plus Plan.” That was my signal it worked.
Claude Code v1.x.xModel: GLM-4.6API Usage Billing: ActiveI tried a simple task: “Write a TypeScript function that validates email addresses using regex.” The response came back quickly. The code was clean, included JSDoc comments, and used proper type annotations. It felt indistinguishable from Sonnet’s output.
Then I tested something more complex: “Refactor this React component to use custom hooks for state management.” GLM-4.6 analyzed the component, extracted the state logic into a reusable hook, and updated the component accordingly. The reasoning was sound, and the code followed React best practices.
After a week of daily use, here’s what I noticed:
Performance:
- Code generation: On par with Sonnet 3.5 for standard tasks
- Bug fixing: Good for common issues, sometimes misses edge cases
- Refactoring: Solid for straightforward transformations
- Documentation: Clear and comprehensive
Limitations:
- Complex architectural decisions occasionally miss nuances
- Creative code solutions feel more conventional than Sonnet’s sometimes
- Very edge-case debugging can require extra prompting
Cost: My actual usage came out to about $6/month—a 70% reduction from Claude Plus.
You can also configure all three model tiers. Here’s the complete configuration I’m using now:
{ "env": { "ANTHROPIC_AUTH_TOKEN": "sk-your-zai-api-key", "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air", "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.6", "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7", "ANTHROPIC_MODEL": "glm-4.6" }}The model mapping works like this:
Claude Code Request GLM Model Used------------------- ----------------claude-3-5-haiku → glm-4.5-airclaude-3-5-sonnet → glm-4.6claude-3-5-opus → glm-4.7If you’re in China, use BigModel’s direct API instead:
{ "env": { "ANTHROPIC_AUTH_TOKEN": "sk-your-bigmodel-api-key", "ANTHROPIC_BASE_URL": "https://open.bigmodel.cn/api/anthropic", "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.6", "ANTHROPIC_MODEL": "glm-4.6" }}For cross-platform setups without a settings file, you can use environment variables directly:
Linux/macOS:
export ANTHROPIC_AUTH_TOKEN="sk-your-zai-api-key"export ANTHROPIC_BASE_URL="https://api.z.ai/api/anthropic"export ANTHROPIC_MODEL="glm-4.6"Windows PowerShell:
[Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "sk-your-zai-api-key", "User")[Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://api.z.ai/api/anthropic", "User")[Environment]::SetEnvironmentVariable("ANTHROPIC_MODEL", "glm-4.6", "User")Here’s what the data flow looks like with this setup:
┌─────────────┐│ Claude Code │ Standard Anthropic API calls│ CLI │──────────────────┐└─────────────┘ │ ▼ ┌─────────────────┐ │ ~/.claude/ │ Redirects via │ settings.json │──────────┐ └─────────────────┘ │ ▼ ┌──────────────────┐ │ Z.AI Endpoint │ Serves GLM-4.6 │ (Anthropic- │──────────┐ │ compatible) │ │ └──────────────────┘ │ ▼ ┌──────────┐ │ GLM-4.6 │ │ Response │ └──────────┘I hit a few snags along the way. Once, the “Plus Plan” message still showed even after configuration. Turned out I didn’t restart my terminal—existing sessions don’t reload environment variables. Another time I got authentication errors because I copied my Z.AI key with a trailing space. API keys are case-sensitive and whitespace-sensitive.
If you see “Model not found” errors, double-check your model names. Z.AI currently supports glm-4.5-air, glm-4.6, and glm-4.7. Typos here won’t work.
For security best practices: never commit API keys to version control, rotate keys periodically through the Z.AI dashboard, and monitor usage for anomalies. Consider using a .env file locally with proper .gitignore entries if you prefer that approach.
So is GLM-4.6 worth it? For daily coding tasks—writing functions, debugging common issues, generating boilerplate, writing tests—it absolutely delivers comparable results to Sonnet at 30% of the cost. For complex architectural work or creative solutions that need deep reasoning, I sometimes fall back to the real Sonnet. But for the majority of my coding workflow, GLM-4.6 through Claude Code CLI handles everything I throw at it.
The setup took about five minutes. No code changes required, just configuration. Same Claude Code workflow I was used to. The only difference is what shows up on my bill at the end of the month.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
- 👨💻 Z.AI Claude Code Tool Documentation
- 👨💻 Z.AI BigModel Documentation
- 👨💻 Claude Code Official Documentation
- 👨💻 2026年国内使用Claude Code 完整指南
- 👨💻 Claude Code + GLM-4.6 配置避坑指南
- 👨💻 Claude Code & 智谱GLM-4.6 环境配置指南
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments