Claude Code - GLM Switcher ๐Ÿš€

February 21, 2026 ยท View on GitHub

Use Claude Code with GLM-5 or native Claude models - Switch instantly with dedicated commands!

License: MIT GLM-5 Claude Sonnet 4.5

๐ŸŽฏ What is this?

This tool lets you use Claude Code with:

  • Native Claude models (Opus 4.1, Sonnet 4.5) via Anthropic API
  • GLM models (GLM-5, GLM-4.5-Air) via Z.AI API - SAVE 85%!

Model Mapping

  • GLM-5 โ†’ replaces Claude Opus & Sonnet (main coding/model)
  • GLM-4.5-Air โ†’ replaces Claude Haiku (fast model)

The New Philosophy: One Command Per Model

claude         # Use Claude Sonnet 4.5 / Opus 4.1 (Anthropic)
claude-glm     # Use GLM-5 (Z.AI) - Opus/Sonnet replacement
claude-glm-air # Use GLM-4.5-Air (Z.AI) - Haiku replacement

No manual switching! Each command launches Claude Code with the right model automatically.

๐Ÿš€ Quick Install (2 minutes)

Prerequisites

  • Linux, macOS, or WSL2 on Windows
  • Claude Code installed (npm install -g @anthropic-ai/claude-code)

Automatic Setup

# Clone the repository
git clone https://github.com/Shor73/claude-code-glm-switcher.git
cd claude-code-glm-switcher

# Run the installer
./install.sh

The installer will:

  1. Copy scripts to ~/.claude/ directory
  2. Add aliases to your .bashrc
  3. Configure everything automatically

After Installation

# Reload your terminal
source ~/.bashrc

# Now you can use:
claude         # For Anthropic models
claude-glm     # For GLM-5 (Opus/Sonnet replacement)
claude-glm-air # For GLM-4.5-Air (Haiku replacement)

๐Ÿ“– How It Works

Simplified Architecture

Instead of modifying global environment variables, each command uses its own dedicated script:

claude-glm โ†’ launch-with-glm.sh โ†’ Sets GLM variables โ†’ Launches Claude Code
claude โ†’ No extra variables โ†’ Uses native Anthropic API

The Three Main Scripts

  1. launch-with-glm.sh

    • Sets: ANTHROPIC_DEFAULT_OPUS_MODEL="glm-5", ANTHROPIC_DEFAULT_SONNET_MODEL="glm-5", ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-4.5-air"
    • API: https://api.z.ai/api/anthropic
    • Best for: Complex coding, deep analysis
  2. launch-with-glm-air.sh

    • Sets: Same as above (GLM-5 for Opus/Sonnet, GLM-4.5-Air for Haiku)
    • API: https://api.z.ai/api/anthropic
    • Best for: Quick searches, file search, syntax checks
  3. Native Claude (no script needed)

    • Uses original Anthropic models
    • No extra configuration

๐Ÿ’ฐ Why Use GLM?

Cost Comparison

ServiceMonthly CostSavings
Claude Pro$20-
Claude Max$200-
GLM-5 via Z.AI$385-98%

GLM-5 Performance

  • Latest model from Zhipu AI (replaces GLM-4.7)
  • Context: 200K tokens (was 128K)
  • Max Output: 128K tokens
  • Ranking: Top-tier globally in benchmarks
  • Specialty: Excellent at coding, tool use, planning

โœจ GLM-5 New Features

FeatureDescription
Extended Context200K tokens for larger projects
Deep Thinkingthinking={ type: "enabled" } for complex reasoning
Streaming Tool Callstool_stream=true for real-time tool output
Superior Code PerformanceBetter at coding and advanced reasoning

๐Ÿ”ง Advanced Configuration (Optional)

Add to ~/.claude/settings.json for custom behavior:

{
  "temperature": 1.0,
  "top_p": 0.95
}

Note: Only tune temperature OR top_p, not both simultaneously.

GLM-4.5-Air Performance

  • Fast model optimized for quick tasks
  • Perfect for: File search, syntax checks, simple queries
  • Cost-effective: Ultra-low latency responses

๐Ÿ”ง Optional Menu (claude-switch)

If you prefer an interactive menu, you can still use:

claude-switch

This shows a menu to:

  • Switch between models
  • View current status
  • Manage configurations

BUT IT'S NOT NECESSARY! The new claude-glm and claude commands are more direct.

๐Ÿ› ๏ธ Manual Configuration

If you want to configure manually:

1. Copy the scripts

mkdir -p ~/.claude
cp launch-with-glm.sh ~/.claude/
cp launch-with-glm-air.sh ~/.claude/
chmod +x ~/.claude/launch-*.sh

2. Add aliases

echo 'alias claude-glm="~/.claude/launch-with-glm.sh"' >> ~/.bashrc
echo 'alias claude-glm-air="~/.claude/launch-with-glm-air.sh"' >> ~/.bashrc
source ~/.bashrc

3. Configure Z.AI API Key

Edit launch-with-glm.sh and insert your API key:

export ANTHROPIC_AUTH_TOKEN="your-api-key-here"

Get your key from: https://z.ai

๐Ÿ“Š Available Models

Via Anthropic (command claude)

  • Claude Opus 4.1 - Most powerful
  • Claude Sonnet 4.5 - Balanced, great for coding

Via Z.AI (commands claude-glm*)

  • GLM-5 - Main model (replaces GLM-4.7), excellent for everything
  • GLM-4.5-Air - Lightning fast, perfect for simple tasks

๐ŸŽฏ When to Use What

Use this commandWhen you want
claudeMaximum quality, cost is not a concern
claude-glmSave 85% while maintaining excellent quality
claude-glm-airInstant responses for simple tasks

๐Ÿ› Troubleshooting

"command not found"

source ~/.bashrc  # Reload your shell configuration

"Invalid API key"

Edit ~/.claude/launch-with-glm.sh and insert your Z.AI key

Want to change default GLM model

Modify ANTHROPIC_MODEL in ~/.claude/launch-with-glm.sh

๐Ÿค Contributing

PRs welcome! Especially for:

  • Support for other open models (Llama, Mistral)
  • GUI for configuration
  • VS Code integration

๐Ÿ“„ License

MIT - See LICENSE

๐Ÿ™ Acknowledgments

  • Zhipu AI for GLM-5 and GLM-4.5-Air
  • Anthropic for Claude Code
  • The open source community

โญ Support the Project

If this project saves you money, consider giving it a star โญ!


Save. Switch. Code.