GLM Integration for Claude Code
November 19, 2025 ยท View on GitHub
This guide explains how to set up and use GLM models with Claude Code.
Prerequisites
- Claude Code installed and working
- A GLM API key from Z.AI Console
Step-by-Step Setup
1. Get Your GLM API Key
- Visit Z.AI Console
- Sign up or log in to your account
- Navigate to API Keys section
- Create a new API key
- Copy your API key for the next steps
2. Create the GLM Wrapper Script
Run the following command to create the wrapper script:
cat >/opt/homebrew/bin/glm <<'EOF'
#!/bin/bash
ANTHROPIC_BASE_URL="https://api.z.ai/api/anthropic" ANTHROPIC_AUTH_TOKEN="YOUR-GLM-API-KEY" API_TIMEOUT_MS=600000 ANTHROPIC_MODEL=GLM-4.6 ANTHROPIC_SMALL_FAST_MODEL=GLM-4.5-Air CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 claude "$@"
EOF
chmod +x /opt/homebrew/bin/glm
3. Configure Your API Key
IMPORTANT: Replace YOUR-GLM-API-KEY with your actual GLM API key in the script.
Edit the script file:
nano /opt/homebrew/bin/glm
Find this line:
ANTHROPIC_AUTH_TOKEN="YOUR-GLM-API-KEY" \
Replace YOUR-GLM-API-KEY with your actual API key:
ANTHROPIC_AUTH_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
Usage
Basic Usage
glm
Troubleshooting
Command Not Found
If you get "command not found" after installation:
- Ensure
/opt/homebrew/bin/is in your PATH - Restart your terminal or run:
source ~/.zshrc(or~/.bashrc)
API Key Issues
- Verify your GLM API key is correct
- Check that your account has sufficient credits
- Ensure the API key is properly formatted
Connection Issues
- Check your internet connection
- Verify the GLM API endpoint is accessible
- Check if there are any service outages on Z.AI Status
Notes
- This wrapper uses Claude Code's infrastructure but routes requests to GLM's API
- All Claude Code features and commands work the same way
- Environment variables are set only for the execution process, not permanently