Skip to main content

GLM CLI with Claude Code

bex glm starts a real Claude Code session against Z.ai's Anthropic-compatible endpoint — the pairing GLM's own docs describe. Bring your Z.ai coding-plan key: one hidden paste on first launch, verified live, and GLM's settings and history stay isolated from every other provider.

bex glm

Quickstart

# Claude Code is the runtime — install it once
npm install -g @anthropic-ai/claude-code
# first launch opens the provider console and captures your key once
bex glm
# everything after the provider name goes straight to claude
bex glm --continue
# rotate or replace the stored key any time
bex code keys set glm

How bex glm works

Documented seams, nothing forked

bex glm starts your installed Claude Code with ANTHROPIC_BASE_URL pointed at https://api.z.ai/api/anthropic and your key in ANTHROPIC_AUTH_TOKEN — only Claude Code's documented environment variables, injected at exec time.

An isolated config dir

CLAUDE_CONFIG_DIR is set to ~/.bex/code/claude-glm (base overridable with BEX_CODE_HOME): settings, history and permissions never collide with another provider, your personal ~/.claude is neither read nor modified, and inherited ANTHROPIC_* values are stripped so nothing leaks in.

One hidden paste, verified live

The first bex glm opens the provider's API-key console, takes one hidden paste, and verifies the key live against the provider's Messages endpoint — only an explicit 401/403 fails. The key is stored owner-only in ~/.bex/code/keys.toml and injected at launch, never written into a config file.

The environment always wins

A key already set in ZAI_API_KEY / GLM_API_KEY overrides the stored one — the first set variable wins — so CI jobs and one-off shells can bring their own key without touching keys.toml.

Everything else goes to claude

Arguments after the provider name pass through to claude unchanged: bex glm --continue resumes your last session, bex glm -p "one prompt" runs a single prompt, and Claude Code's own --help works as-is.

Manual env vars vs bex glm

By hand: five exports, every shell

export ANTHROPIC_BASE_URL="https://api.z.ai/api/anthropic"
export ANTHROPIC_AUTH_TOKEN="<api-key>"
export ANTHROPIC_MODEL="glm-5.2"
export ANTHROPIC_SMALL_FAST_MODEL="glm-5-turbo"
export CLAUDE_CONFIG_DIR="$HOME/.claude-glm"
claude

Claude Code's provider seams are environment variables, so a manual setup exports the endpoint, the key, both model slots and a config dir — in every new shell, for every provider, with nothing checking that the key actually works.

With bex: one command

bex glm

bex glm injects the same variables at exec time, keeps ~/.bex/code/claude-glm isolated so histories and settings never collide, and verifies your key before Claude Code starts.

GLM (Z.ai coding plan) defaults

Default modelglm-5.2
Small/fast modelglm-5-turbo
Base URLhttps://api.z.ai/api/anthropic
API-key consolehttps://z.ai/manage-apikey/apikey-list
Key environment variablesZAI_API_KEYGLM_API_KEY

The default model fills ANTHROPIC_MODEL and the opus/sonnet slots; the small/fast model fills ANTHROPIC_SMALL_FAST_MODEL and the haiku slot. Key environment variables are probed in order — the first set value wins, and the environment always beats the stored key.

What's specific to GLM (Z.ai coding plan)

Most GLM questions turn out to be Z.ai coding-plan questions: whether the plan's key works here, which of the two GLM models each model slot gets, and where bex glm reads the key from.

Can I use my Z.ai coding plan with Claude Code?

That is what bex glm is for. Z.ai publishes an Anthropic-compatible endpoint at https://api.z.ai/api/anthropic, and the launcher points Claude Code at it with your coding-plan key as the bearer token. The key comes from your own Z.ai console (https://z.ai/manage-apikey/apikey-list) and travels from your machine to Z.ai — bex brokers nothing and adds no plan of its own.

Which GLM model does each model slot get?

Two different ones. glm-5.2 fills ANTHROPIC_MODEL and the opus and sonnet slots; glm-5-turbo fills ANTHROPIC_SMALL_FAST_MODEL and the haiku slot, so Claude Code's lightweight calls stay on the faster model. Both are exported at exec time, never written into a settings file.

Which environment variable holds the GLM key?

ZAI_API_KEY / GLM_API_KEY, probed in that order: the first one set wins, and either beats the key stored in ~/.bex/code/keys.toml. A CI job or a one-off shell that already exports a Z.ai key therefore needs no bex configuration at all.

The other launchers

All Claude Code launchers