A lightweight local proxy that lets you use Z.ai GLM models inside Claude Code as a selectable model option, alongside the regular Claude models.
Claude Code only talks to the Anthropic API. This proxy sits in between: regular requests pass through to Anthropic unchanged, while any request for a model containing glm gets rerouted to Z.ai.
Claude Code → localhost:8787 → api.anthropic.com (Claude models)
→ api.z.ai (GLM models)
The proxy auto-starts when Claude Code launches (via a SessionStart hook) and stays running in the background. No service registration, no platform-specific setup.
- Python 3.6+
- A Z.ai API key with GLM access
git clone https://github.com/eyehol3/claude-glm-proxy.git
cd claude-glm-proxy
./install.shThe script copies model_proxy.py to ~/.config/model-proxy/ and creates a config file for your API key. Then it prints the JSON to merge into ~/.claude/settings.json.
After running:
- Set your API key in
~/.config/model-proxy/model-proxy.env - Add the settings to
~/.claude/settings.json(the script prints them)
claude --model glm # start with GLMInside a session, use /model to switch between Claude and GLM.
model_proxy.py is a zero-dependency Python HTTP proxy. On each request it reads the model field from the JSON body and matches it against a routing table:
| Model contains | Backend | Path prefix |
|---|---|---|
glm |
api.z.ai |
/api/anthropic |
| (anything else) | api.anthropic.com |
(none) |
The proxy rewrites auth headers per-backend automatically. API keys are read from ~/.config/model-proxy/model-proxy.env.
Claude Code's SessionStart hook handles lifecycle: it checks localhost:8787/health, starts the proxy if needed, waits a second, then verifies it's actually up. If it fails to start you'll see an error in the Claude Code banner. No launchd/systemd/cron needed.
Logs: ~/.config/model-proxy/model-proxy.log
Extend MODEL_ROUTES in model_proxy.py:
MODEL_ROUTES = {
"glm": ("api.z.ai", "/api/anthropic"),
"mymodel": ("my-api.example.com", "/v1"),
}Add the corresponding API key env var in model_proxy.py and set it in model-proxy.env.
- Remove the
envkeys (ANTHROPIC_BASE_URL,ANTHROPIC_CUSTOM_MODEL_OPTION*) and theSessionStarthook from~/.claude/settings.json - Kill the proxy and delete the files:
pkill -f model_proxy.py
rm -rf ~/.config/model-proxyClaude Code will go back to talking directly to Anthropic's API.