Using GLM 5.2 as a Cost-Effective Claude Code Engine

Nate Herk | AI Automationgo watch the original →

By routing Claude Code through the Z.ai API, you can replace Anthropic models with GLM 5.2 to achieve similar performance on most knowledge work at approximately one-fifth the cost.

Model Routing and Configuration

Claude Code acts as a harness for AI models, allowing developers to swap the underlying engine by modifying the .claude/settings.local.json file. By setting the ANTHROPIC_BASE_URL to the Z.ai API endpoint and updating the model defaults to glm-5.2, users can leverage the 756 billion parameter open-source model within the Claude Code interface. This configuration allows for project-specific model selection, where directories lacking a local settings file default to standard Anthropic models, while those with the custom config route requests through GLM 5.2.

Performance and Cost Analysis

GLM 5.2 offers a significant cost advantage over Claude 3.5 Opus. The input cost for GLM 5.2 is $1.40 per million tokens compared to $5.00 for Opus, and the output cost is $4.40 versus $25.00. While Opus remains superior for complex reasoning tasks, GLM 5.2 is highly capable for front-end design, research gathering, and general knowledge work. In testing, GLM 5.2 completed design tasks in approximately 4 minutes compared to 15 minutes for Opus, though it occasionally struggles with edge-case precision, such as handling duplicate records with mixed data types (e.g., true vs 1).

Implementation Strategy

To integrate GLM 5.2, users should add the following environment variables to their local configuration:

"env": {
  "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
  "ANTHROPIC_AUTH_TOKEN": "your-z-ai-api-key-here",
  "ANTHROPIC_API_KEY": "",
  "API_TIMEOUT_MS": "3000000",
  "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5.2",
  "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5.2",
  "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-5.2",
  "ANTHROPIC_SMALL_FAST_MODEL": "glm-5.2",
  "CLAUDE_CODE_SUBAGENT_MODEL": "glm-5.2"
}

Users can manage usage via Z.ai's subscription plans or pay-per-token billing. This approach provides a viable alternative for developers looking to reduce reliance on closed-source model providers while maintaining high-quality output for the majority of daily coding tasks.

  • #tutorial
  • #ai
  • #dev-tooling

summary by google/gemini-3.1-flash-lite. probably wrong about something. check the source.