ai-coding-assistants

How to Run GLM Inside Claude Code and Cut Your API Costs by 80% (Same Interface, Cheaper Model)

Claude Code does not have to bill Anthropic for every turn. Point it at Z.ai's Anthropic-compatible endpoint, map the model slots to GLM, and keep the same CLI while heavy coding spend drops hard.

J
Jordan Patel
Tech Analyst
October 4, 2026 Updated October 4, 2026 10 min read
Last updated: October 4, 2026
How to Run GLM Inside Claude Code and Cut Your API Costs by 80% (Same Interface, Cheaper Model)

If you live in Claude Code, the painful part is rarely the interface. It is the bill after a week of refactors, long agent loops, and "one more fix" sessions on a frontier Claude model.

The useful discovery for a lot of developers in 2026 is that Claude Code is not glued to Anthropic's models. It speaks Anthropic's API shape. Any provider that exposes a compatible endpoint can sit behind the same CLI. Z.ai does exactly that for GLM: you keep Claude Code, swap the base URL and token, and map the default Haiku, Sonnet, and Opus slots to GLM models.

For heavy daily coding, that change is often the difference between surprise API invoices and a predictable coding plan measured in tens of dollars per month. Savings in the ballpark of 80% show up when you were burning expensive Opus-class traffic on routine work that a strong GLM tier can handle. It is not magic and it is not free quality parity on every task. It is a cost lever you control with two environment variables.

What you are actually changing

Claude Code sends requests to whatever host you set in ANTHROPIC_BASE_URL, authenticated with ANTHROPIC_AUTH_TOKEN.

Z.ai publishes an Anthropic-compatible endpoint at:

https://api.z.ai/api/anthropic

Your Z.ai API key goes in the auth token field. Claude Code still looks like Claude Code. The model answering is GLM.

That is why this is not a fork and not a proxy science project. It is a configuration swap. Official wiring lives in Z.ai's Claude Code docs: docs.z.ai scenario guide for Claude.

For product context on both sides of the swap, see our listings for Claude and Z.ai Chat (GLM).

Setup in plain steps

Install Claude Code if you do not already have it:

npm install -g @anthropic-ai/claude-code

Create a key in your Z.ai account (GLM Coding Plan users get the path documented for coding tools).

Fast path on macOS or Linux: run Z.ai's helper and let it write the env block:

npx @z_ai/coding-helper

Manual path: edit ~/.claude/settings.json and put an env object with at least:

ANTHROPIC_BASE_URL = https://api.z.ai/api/anthropic

ANTHROPIC_AUTH_TOKEN = your_z_ai_api_key

API_TIMEOUT_MS = 3000000

Then map the Claude Code tiers to GLM, for example:

ANTHROPIC_DEFAULT_HAIKU_MODEL = glm-5.3-flash

ANTHROPIC_DEFAULT_SONNET_MODEL = glm-5.3

ANTHROPIC_DEFAULT_OPUS_MODEL = glm-5.3

Exact model id strings change as Z.ai ships new GLM versions. Prefer the names in the current Z.ai Claude Code page over a blog screenshot from last month. Some setups append [1m] for a 1M context window when your Claude Code build supports it.

Open a new terminal after saving. Run claude in a repo and ask a trivial question. If the reply comes back and your Z.ai usage moves, the wire is correct.

Use ANTHROPIC_AUTH_TOKEN for this pattern. Putting the key only in ANTHROPIC_API_KEY can trigger Claude Code's approval flow in ways that confuse a third-party endpoint.

When GLM is enough, and when it is not

Work typeLean on GLM in Claude CodePrefer native Claude (especially stronger Opus-class)
Boilerplate, renames, straightforward refactorsYesRarely needed
Tests, docs, repetitive agent loopsYesOnly if quality slips
Large but well-scoped feature workOften yes, with reviewIf the model stalls or invents APIs
Security-sensitive auth, crypto, compliance codeNo as sole reviewerYes, then human review
Unfamiliar legacy systems where wrong edits are expensivePair or switch upYes

The honest rule: put the cheap model on volume. Put the expensive model on judgment. Many developers run GLM as the default inside Claude Code and only flip back to Anthropic when the task is high risk or the cheaper model starts thrashing.

For a wider model comparison outside the CLI, see ChatGPT vs Claude vs Gemini.

Cost, without the marketing fog

Anthropic API spend scales with tokens and model tier. A week of aggressive agent use on a top Claude model can land in three figures for a single active developer.

Z.ai's GLM Coding Plan is built around coding-tool usage with fixed monthly tiers (Lite has been listed around the high teens per month in public docs, with higher Pro and Max tiers for heavier credit windows). Pay-per-token GLM rates are also far below typical frontier Claude API list prices for comparable bulk work.

Whether you personally hit "80% less" depends on your baseline. If you barely use the API, the win is small. If Claude Code is your main IDE partner all day, redirecting routine traffic to GLM is one of the cleanest cost cuts available without giving up the tool.

Watch the plan's credit windows (for example multi-hour and weekly caps on coding plans). Hitting a cap pauses throughput; it is not the same as unlimited discounted tokens.

Practical habits that keep the setup sane

Keep a second profile or a quick way to clear the Z.ai env vars when you truly need native Claude. Do not argue with a cheap model for an hour on a security-sensitive change.

Pin model ids in settings.json after you verify them. Silent default changes on the provider side are how people debug the wrong problem.

Do not paste secrets into any cloud model you would not trust with that repo. The endpoint change does not change basic hygiene.

If the helper script and manual env disagree, trust the current Z.ai docs over third-party mirrors.

Final thoughts

Claude Code is a workflow. The model behind it is a bill. Separating those two ideas is the whole point of the GLM setup.

Point ANTHROPIC_BASE_URL at Z.ai, put your key in ANTHROPIC_AUTH_TOKEN, map Haiku and Sonnet and Opus slots to current GLM ids, and run your real week on that stack. Keep native Claude for the tasks where a wrong answer is expensive. That split is how you cut API cost without throwing away the interface you already know.

J
Jordan Patel
Verified expert
Tech Analyst

Jordan Patel is a tech analyst at ToolVerse AI, covering AI tools and the future of software. Jordan has been writing about AI since 2022 and personally tests every tool covered in this guide.

  • Hands-on AI tester
  • Covers AI since 2022
  • ToolVerse AI editorial team
Editorially reviewed by Nina Park, Productivity Lead
Share:

Frequently asked questions

Yes. Claude Code follows ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN. Point the base URL at Z.ai's Anthropic-compatible endpoint and use a Z.ai API key to serve GLM models inside the same CLI.
Editorial reviewLast reviewed: October 4, 2026

Our verdict on this ai-coding-assistants guide

The ToolVerse AI editorial team evaluated every tool and claim in "How to Run GLM Inside Claude Code and Cut Your API Costs by 80% (Same Interface, Cheaper Model)" against five criteria, with hands-on testing, source-checking and a quarterly accuracy review.

4.4
Overall editorial score
Out of 5.0
  • Ease of use
    Onboarding flow, UX clarity and time-to-first-value.
    4.4
  • Features & depth
    Breadth of capabilities vs. category benchmarks.
    4.6
  • Pricing value
    Free-tier generosity and price-to-output ratio.
    4.2
  • Performance
    Speed, reliability and output quality in real tests.
    4.3
  • Support & docs
    Help center, response times and community resources.
    4.6
How we evaluate AI tools

Every product on ToolVerse AI is independently tested by our editors. We sign up, complete the same real-world tasks across each tool in a category, document the experience, and compare against direct competitors. We don't accept payment for rankings, and affiliate relationships never influence editorial scores. Scores are reviewed quarterly to reflect new features, pricing changes and user feedback.

Related articles