# Cheat Sheet — The env Block for GLM Routing in Claude Code

File: `.claude/settings.local.json` (project-scoped, ignored by Git) or `~/.claude/settings.json` (machine-wide).

```json
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "DEIN_ZAI_API_KEY",
    "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.7",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5.2[1m]",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5.2[1m]",
    "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1000000",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
    "API_TIMEOUT_MS": "3000000"
  }
}
```

## What the Fields Mean

| Field | Function |
|---|---|
| `ANTHROPIC_AUTH_TOKEN` | Bearer token for the gateway. With Z.ai it must go here, not in `ANTHROPIC_API_KEY`. |
| `ANTHROPIC_BASE_URL` | Redirects all traffic to the third-party endpoint. |
| `ANTHROPIC_DEFAULT_HAIKU_MODEL` | Tier *haiku* → the low-cost `glm-4.7`. |
| `ANTHROPIC_DEFAULT_SONNET_MODEL` | Tier *sonnet* → `glm-5.2[1m]` (1M context). |
| `ANTHROPIC_DEFAULT_OPUS_MODEL` | Tier *opus* → `glm-5.2[1m]`. |
| `API_TIMEOUT_MS` | Raised because GLM responds more slowly and agent loops would otherwise time out. |

## Verifying

1. `echo $ANTHROPIC_BASE_URL` → must print `https://api.z.ai/api/anthropic`
2. `/model` → should show GLM-5.2, with no Claude fallback
3. Identity probe: "What model are you?" → if it says "Claude", the routing is wrong

## Common Mistakes

- Wrong key variable (`ANTHROPIC_API_KEY` instead of `AUTH_TOKEN`)
- Wrong URL path (not the generic OpenAI path)
- Process not fully restarted
- A competing Claude login takes precedence → check with `/status`
- Key in Git: keep `settings.local.json` in `.gitignore`

Source: official Z.ai documentation on Claude Code integration.
