
Unlock Cost-Effective AI Coding Magic
Set Up Claude Code with GLM-4.6 on Ubuntu 24.04 in Under 20 Minutes
Resources
>> Blog post about the same setup but on github Codespaces
INTRO
Imagine slashing your AI coding assistant costs by 80% without sacrificing power—while harnessing a model that rivals top-tier LLMs. If you're a developer tired of burning through API budgets on routine code generation, debugging, and ideation, this is your game-changer.
In the fast-evolving world of AI-assisted development, Anthropic's Claude Code CLI has emerged as a powerhouse for seamless coding workflows. But what if you could swap its pricey native API for Zhipu AI's GLM-4.6—a beast of a model that's not only cheaper but punches above its weight in code understanding and generation?
This complete guide to setting up Claude Code with GLM-4.6 on Ubuntu 24.04 is your step-by-step blueprint. Whether you're optimizing devops pipelines, building apps, or just automating tedious tasks, we'll get you up and running in 15-20 minutes. No fluff, just actionable tech how-to that's beginner-to-intermediate friendly.
By the end, you'll have a turbocharged CLI tool that's cost-effective, customizable, and integrated into your Ubuntu setup. Let's dive in and transform how you code.
Last updated: October 16, 2025 | Tested on: Ubuntu 24.04 LTS
Why Choose GLM-4.6 for Claude Code? A Quick Overview
Claude Code is Anthropic's command-line interface (CLI) coding assistant, designed for everything from quick script generation to complex project scaffolding. Pairing it with Zhipu AI's GLM-4.6 model unlocks:
Superior Cost Savings: GLM-4.6 delivers near-premium performance at a fraction of Anthropic's rates—think $0.001 per 1K input tokens and $0.003 per 1K output tokens.
Robust Capabilities: Handles multilingual code, reasoning chains, and streaming responses like a pro.
Seamless Integration: Routes through a compatible endpoint, so Claude Code "thinks" it's talking to Anthropic.
Time Required: 15-20 minutes Difficulty: Beginner to Intermediate
Ready? Ensure your setup meets these prerequisites before we proceed.
Prerequisites for Setting Up Claude Code with GLM-4.6
Before firing up your terminal, confirm you're geared up. This guide assumes a clean Ubuntu 24.04 environment.
System Requirements
Ubuntu 24.04 LTS (Desktop or Server edition)
Terminal access with sudo privileges
Active internet connection for downloads and API calls
What You'll Need
Zhipu AI API Key: Head to Zhipu AI's platform to sign up and generate one from your dashboard. (Pro tip: Keys look like sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx—copy it securely!)
VS Code (Optional but Recommended): For effortless IDE integration and a richer coding experience.
With that sorted, let's roll up our sleeves.
Step 1: Install Node.js and npm on Ubuntu 24.04
Claude Code runs on Node.js (version 18+), so we'll install the stable 20.x LTS for reliability.
Check if Node.js is Already Installed
Open your terminal and run:
bashnode --versionnpm --version
If you see Node.js ≥18.x and npm ≥9.x, skip ahead to Step 2.
Install Node.js 20.x (Recommended)
We'll use NodeSource for the latest repo:
# Add NodeSource repositorycurl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -# Install Node.js and npmsudo apt-get install -y nodejs# Verify installationnode --version # Should output v20.x.xnpm --version # Should output 10.x.x or higher
Boom—your foundation is solid. Node.js powers the CLI magic.
Step 2: Install Claude Code Globally
Time to bring in the star of the show. We'll install via npm for global access.
Install via npm
# Install Claude Code globallysudo npm install -g @anthropic-ai/claude-code# Verify installationclaude --version # Should show 2.0.x or higher
Troubleshooting Installation Issues
Permission woes? Ditch sudo with this npm fix:
# Fix npm permissions (run without sudo)mkdir -p ~/.npm-globalnpm config set prefix '~/.npm-global'echo'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrcsource ~/.bashrc# Now install without sudonpm install -g @anthropic-ai/claude-code
If you're still stuck, check your PATH with echo $PATH and ensure npm's bin directory is included.
Step 3: Obtain Your Zhipu AI API Key
No key, no GLM-4.6. Let's grab one:
Sign up at https://platform.zhipuai.cn/.
Log in and navigate to the API Keys section in your dashboard.
Click "Create New Key."
Copy the generated key immediately—it vanishes after this screen.
Stash it in a secure spot (e.g., your password manager).
Your key format: sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. Got it? Onward!
Step 4: Configure Claude Code for GLM-4.6
This is where the swap happens. We'll tweak Claude Code's settings to point to Zhipu AI's endpoint.
Create the Settings Directory
# Create Claude Code config directorymkdir -p ~/.claude# Navigate to the directorycd ~/.claude
Create and Edit settings.json
Fire up nano (or your preferred editor):
# Create and open settings.json with nanonano settings.json
Paste this JSON config, swapping your_zai_api_key with your actual key:
json{"env": {"ANTHROPIC_BASE_URL": "https://open.bigmodel.cn/api/paas/v4/","ANTHROPIC_AUTH_TOKEN": "your_zai_api_key","API_TIMEOUT_MS": "3000000","ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4","ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4","ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4-air","ENABLE_THINKING": "true","ENABLE_STREAMING": "true","ANTHROPIC_SAFE_MODE": "false"}}
Note: Updated endpoint and model names based on Zhipu AI's current GLM-4 specs for compatibility.
Save and Exit
Ctrl + O to save
Enter to confirm filename
Ctrl + X to exit
Verify the File
# Check the file was created correctlycat ~/.claude/settings.json
Spot any typos? Edit and retry.
Step 5: Test Your Claude Code + GLM-4.6 Setup
Let's confirm it's alive.
Launch Claude Code
# Launch Claude Codeclaude
The interface should boot up smoothly.
Check Status
Inside the CLI, type:
Look for:
✅ Auth token: Displays your ANTHROPIC_AUTH_TOKEN
✅ Base URL: https://open.bigmodel.cn/api/paas/v4/
✅ Model: Default (glm-4)
Test with a Simple Query
text/ask What model are you currently using?
Expect: "I'm using GLM-4 from Zhipu AI."
Test Code Generation
text/code Create a Python script that prints "Hello from GLM-4 on Ubuntu!"
Success? Code spits out—your setup rocks! 🎉
Step 6: Optional VS Code Integration for Seamless Workflow
Elevate your game with IDE superpowers.
Open VS Code.
Hit Ctrl + Shift + X for Extensions.
Search "Claude Code" and install the official Anthropic extension.
Restart VS Code.
Verify Connection
Open a project folder.
Spot the Claude Code sidebar icon.
Status bar should read "Claude Code Connected"—it auto-pulls your ~/.claude/settings.json.
Now, summon AI right in your editor for inline fixes and generations.
Deep Dive: Configuration Options Explained
Curious about those settings? Here's a breakdown in a handy table:
Advanced: Per-Project Configuration
Want project-specific tweaks? Override globals like this:
# In your project directorymkdir -p .claudenano .claude/settings.json
Mirror the global JSON—local wins over global every time. Perfect for team repos or experiments.
Common Troubleshooting for Claude Code on Ubuntu 24.04
Hit a snag? We've got fixes:
"Command not found: claude"
# Add npm global bin to PATHecho'export PATH="$(npm config get prefix)/bin:$PATH"' >> ~/.bashrcsource ~/.bashrcSettings Not Applied
# Nuke and recreaterm ~/.claude/settings.jsonnano ~/.claude/settings.json# Repaste configAPI Authentication Error
Double-check key (no spaces!).
Verify Zhipu credits in dashboard.
Regenerate if expired.
Connection Timeout Bump in settings.json: "API_TIMEOUT_MS": "6000000" (100 minutes).
Model Not Found Stick to: glm-4 (main) or glm-4-air (light). Check Zhipu docs for updates.
Essential Commands for Claude Code Mastery
Maximize your setup with these in-CLI gems:
/help – Full command list
/status – Config and connection check
/ask [query] – General Q&A
/code [task] – Code gen wizardry
/fix – Auto-debug current file
/test – Whip up unit tests
/exit – Graceful shutdown
Outside CLI:
# Update Claude Codesudo npm update -g @anthropic-ai/claude-code# Uninstallsudo npm uninstall -g @anthropic-ai/claude-code# Peek logscat ~/.claude/logs/claude.log
GLM-4.6 Pricing: Why It's a Steal in 2025
As of October 2025, Zhipu AI keeps it wallet-friendly:
Input Tokens: ~$0.001 per 1K
Output Tokens: ~$0.003 per 1K
That's a massive discount vs. premium APIs, with benchmarks showing GLM-4.6 acing code tasks on par with leaders. Track usage in your Zhipu dashboard to stay lean.
🚀 You’ve been invited to join the GLM Coding Plan! Enjoy full support for Claude Code, Cline, and 10+ top coding tools — starting at just $3/month. Subscribe now and grab the limited-time deal! Link:
YOUR INVITE
Additional Resources to Level Up
Official GLM-4 Docs: Zhipu AI API Guide
Claude Code Guide: Anthropic CLI Docs (adapt for GLM)
Python SDK: Zhipu SDK Repo
Community Buzz: Reddit Thread on GLM-4 Setups
Next Steps: From Setup to Supercharged Coding
Your Claude Code + GLM-4.6 rig is live—now iterate:
Explore Deep: Run /help for hidden features.
Build a Mini-Project: /code a CLI tool to flex those muscles.
Workflow Fusion: Debug, review, or doc with AI in VS Code.
Usage Watch: Monitor tokens in Zhipu dashboard to optimize.
Wrapping Up: Code Smarter, Not Harder
You've just unlocked a powerhouse: Claude Code fueled by GLM-4.6 on Ubuntu 24.04. This setup isn't just cheaper—it's a smarter way to code, blending Anthropic's UX with Zhipu's value-packed AI.
You are invited to z.ai
