Setting up z.ai GLM 4.7 with Claude Code

Tags:

Why?

I started looking at z.ai as an alternative, as I hit the Claude Code limits far too quickly and often. GLM 4.7 claims to be on par with Anthropic while only costing USD 36/year at the time I subscribed. They've now raised their prices to USD 84/year ( non-referral link ).

The Claude Code client currently is still better than the client provided by opencode. Soon, opencode will have a --yolo mode to auto-override all permission prompts. Maybe it will even support monochrome mode instead of its fruit salad UI, but I think that the allure of all those TUI tools to their creator is to create a colorful slot machine where people spend their tokens.

Installation

Installing the Claude Code client just follows the default installation. I simply reused my existing CC installation.

Config setup

The configuration is where instead of pointing to the Claude Code models, the client is pointed to the GLM models that have the same API.

  1. Get your API key from the z.ai API key page
  2. Add the following setting to your environment

    export ANTHROPIC_AUTH_TOKEN_HELPER='echo "your_zai_api_key"'
    
  3. Add the "env" block to your (z.ai) .claude.conf

    {
        "env": {
            "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
            "API_TIMEOUT_MS": "3000000"
        }
    }
    
  4. Launch Claude as usual

Containerfile creating a container for CC-with-GLM4.7

The Containerfile I used with Claude also works with z.ai , as long as you mount the appropriate config directory.