# Using z.ai with Claude Code ## Why z.ai provides GLM models as a drop-in replacement for Anthropic's API in Claude Code. Much cheaper: $6-60/month vs $100-200/month for Claude Max. ## Setup ### 1. Get API Key - Go to https://z.ai/model-api - Register/login - Create API key at https://z.ai/manage-apikey/apikey-list ### 2. Configure Claude Code Edit `~/.claude/settings.json`: ```json { "env": { "ANTHROPIC_AUTH_TOKEN": "your_zai_api_key_here", "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic", "API_TIMEOUT_MS": "3000000" } } ``` ### 3. Open new terminal, run `claude` That's it. ## Switching Back to Anthropic Remove or comment out the env block in `~/.claude/settings.json`: ```json { } ``` Or just delete the three env vars. Open new terminal. ## Optional: Model Mapping To control which GLM model is used for each tier, add to the env block: ```json { "env": { "ANTHROPIC_AUTH_TOKEN": "your_zai_api_key_here", "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic", "API_TIMEOUT_MS": "3000000", "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7", "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air" } } ``` ## Notes - GLM-4.7 is the current best model on z.ai - glm-4.5-air is lighter/faster for haiku tasks - MCP tools, skills, and all Claude Code features work normally - If something breaks, just revert settings.json and restart