glm-switch
v2.0.5
Published
CLI utility to switch between Claude API and GLM 4.6 models in Claude Code
Readme
GLM Switch Profile for claude-code
Public tool for Supermeo & Inwave DR Team
A CLI tool for managing multiple GLM API profiles in Claude Code/VS Code. Quickly switch between different GLM configurations without manual editing.
Features
- Multiple Profiles - Manage multiple profiles with different tokens and models
- Quick Switch - Switch between profiles with a single command
- Session-Local Start - Run GLM in only one terminal session without touching global settings
- Env Export - Print shell-specific exports for advanced workflows
- Bulk Update - Update config across all profiles at once
- Safe Operations - Automatic backup, JSON validation, and rollback on errors
- Cross-Platform - Support for Windows & macOS
- JSONC Support - Reads settings.json with comments
- Auto-Create - Automatically creates files if they don't exist
Installation
Method 1: Install from npm (Recommended)
npm install -g glm-switchMethod 2: Install from GitHub
# Clone repository
git clone https://github.com/supermeo-studio/glm-switch.git
cd glm-switch
# Setup
npm run setupThe npm run setup command will:
- Install dependencies
- Build TypeScript to JavaScript
- Create a global symlink via
npm link
Profile Concept
Each profile is a separate GLM API configuration containing:
| Config Key | Description |
|------------|-------------|
| ANTHROPIC_BASE_URL | API endpoint for GLM |
| ANTHROPIC_AUTH_TOKEN | Authentication token |
| ANTHROPIC_DEFAULT_HAIKU_MODEL | Haiku model (lightweight) |
| ANTHROPIC_DEFAULT_SONNET_MODEL | Sonnet model (balanced) |
| ANTHROPIC_DEFAULT_OPUS_MODEL | Opus model (powerful) |
Storage: Profiles are stored in ~/.claude/glm-switch/
Usage Guide
1. Create Your First Profile
# Create profile 0 with default values
glm-switch init 0Output:
✓ Profile 0 created
Config: {
"ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
"ANTHROPIC_AUTH_TOKEN": "",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5"
}
Don't forget to set your auth token:
glm-switch set 0 token <your-token>2. Set Token for Profile
# Set token for profile 0
glm-switch set 0 token your_token_here3. Apply Profile
# Apply default profile (0)
glm-switch on
# Apply specific profile
glm-switch on 1Important: After applying, restart Claude Code/VS Code for changes to take effect.
4. Start GLM for One Terminal Only (Recommended)
# Start a new child shell using profile 1 env
glm-switch start 1
# Exit child shell to return to your original terminal context
exitThis mode does not edit ~/.claude/settings.json, so other existing/new terminals keep their normal Claude setup.
5. Export Env to Current Shell (Advanced)
# macOS bash/zsh
eval "$(glm-switch env 1 --shell zsh)"
# fish
glm-switch env 1 --shell fish | source
# PowerShell
glm-switch env 1 --shell powershell | Invoke-ExpressionUse this when you explicitly want to inject profile env into the current shell process.
6. Create Additional Profiles
# Create profile 1
glm-switch init 1
# Set different token for profile 1
glm-switch set 1 token another_token_here
# Apply profile 1
glm-switch on 17. Bulk Update - Update All Profiles
# Update Sonnet model for all profiles
glm-switch setall sonnet glm-5
# Update Opus model for all profiles
glm-switch setall opus glm-5
# Update Haiku model for all profiles
glm-switch setall haiku glm-4.5-air
# Update API endpoint for all profiles
glm-switch setall ANTHROPIC_BASE_URL https://api.z.ai/api/anthropic8. List All Profiles
glm-switch listOutput:
Profiles:
[active] [default] 0
Base URL: https://api.z.ai/api/anthropic
Token: b8eb5131e...
Haiku: glm-4.5-air
Sonnet: glm-5
Opus: glm-5
1
Base URL: https://api.z.ai/api/anthropic
Token: (not set)
Haiku: glm-4.5-air
Sonnet: glm-5
Opus: glm-59. Check Current Status
glm-switch status10. Delete Profile
glm-switch delete 111. Disable GLM Mode (Restore Claude API)
glm-switch offAll Commands
| Command | Description | Example |
|---------|-------------|---------|
| init [id] | Create a new profile | glm-switch init 0 |
| set <id> <key> <value> | Set value for a specific profile | glm-switch set 0 token xxxx |
| setall <key> <value> | Set value for all profiles | glm-switch setall sonnet glm-5 |
| on [id] | Apply profile (default: 0) | glm-switch on 1 |
| start [id] | Start child shell with profile env only | glm-switch start 1 |
| env [id] --shell <shell> | Print shell export commands | glm-switch env 1 --shell zsh |
| off | Remove GLM config | glm-switch off |
| status | Show current status | glm-switch status |
| list | List all profiles | glm-switch list |
| delete <id> | Delete a profile | glm-switch delete 1 |
| --help | Show help | glm-switch --help |
| --version | Show version | glm-switch --version |
Valid Config Keys
When using set or setall commands, you can use full keys or shorthand aliases:
ANTHROPIC_BASE_URL
ANTHROPIC_AUTH_TOKEN
ANTHROPIC_DEFAULT_HAIKU_MODEL
ANTHROPIC_DEFAULT_SONNET_MODEL
ANTHROPIC_DEFAULT_OPUS_MODEL
token
haiku
sonnet
opusHow It Works
File Storage Structure
~/.claude/
├── settings.json # Claude Code settings
└── glm-switch/ # GLM Switch profiles directory
├── profile-0.json # Profile 0 config
├── profile-1.json # Profile 1 config
├── active-profile.json # Currently active profile
└── default-profile.json # Default profile (0)Profile File Format
{
"id": "0",
"config": {
"ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
"ANTHROPIC_AUTH_TOKEN": "your-token-here",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5"
},
"createdAt": "2025-01-14T10:00:00.000Z",
"updatedAt": "2025-01-14T10:00:00.000Z"
}Settings.json Modification
When running glm-switch on [id], the tool injects config from the profile into ~/.claude/settings.json:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
"ANTHROPIC_AUTH_TOKEN": "your-token-here",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5"
}
}Session-Local Mode (No Global Changes)
When running glm-switch start [id], the tool:
- Starts a new child shell at current
cwd - Injects profile env only into that child session
- Does not modify
~/.claude/settings.json - Leaves other terminals unaffected
Recommended Workflows
First-Time Setup
# 1. Create profile 0
glm-switch init 0
# 2. Set your token
glm-switch set 0 token your_token_here
# 3. Apply
glm-switch on
# 4. Restart Claude CodeAdd New Profile
# 1. Create new profile
glm-switch init 1
# 2. Set token
glm-switch set 1 token another_token
# 3. Apply when needed
glm-switch on 1Use GLM in One Terminal, Keep Others Default
# Start isolated GLM shell from current directory
glm-switch start 1
# Work with GLM in this shell only...
# Exit back to normal Claude environment
exitUpdate Models for All
glm-switch setall sonnet glm-5
glm-switch setall opus glm-5
glm-switch setall haiku glm-4.5-airSafety Features
- Automatic Backup - Creates
.backupfile before modifying - Atomic Writes - Uses temp files to prevent corruption
- JSON Validation - Validates structure before writing
- Rollback on Error - Restores from backup if modification fails
- Non-destructive - Preserves other settings
- Session isolation -
startmode does not change global settings - No hardcoded token default - Profile token defaults to empty
Troubleshooting
Command not found after installation
# Close and reopen terminal
# Or check npm bin path
npm bin -g
# Ensure npm bin is in your PATHChanges not taking effect
# 1. Check status
glm-switch status
# 2. Restart Claude Code/VS Code COMPLETELY
# 3. Check status againProfile does not exist
# List all profiles
glm-switch list
# Create profile if needed
glm-switch init 0Invalid config key
✗ Invalid config key: invalid_key
Valid keys: ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_DEFAULT_HAIKU_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_OPUS_MODELPermission errors
Windows: Run terminal as Administrator
macOS:
# Check permissions
ls -la ~/.claude/
# Fix permissions
chmod 644 ~/.claude/settings.jsonDevelopment
Clone & Setup
git clone https://github.com/supermeo-studio/glm-switch.git
cd glm-switch
npm run setupBuild
npm run buildWatch Mode
npm run devClean
npm run cleanUninstallation
Global npm package
npm uninstall -g glm-switchManual cleanup (optional)
# Remove profiles directory
rm -rf ~/.claude/glm-switchPlatform Support
| Platform | Status | Settings Location |
|----------|--------|-------------------|
| Windows 10/11 | ✅ Supported | C:\Users\{username}\.claude\settings.json |
| macOS | ✅ Supported | ~/.claude/settings.json |
| Linux | ⚠️ Untested | ~/.claude/settings.json |
Version History
v2.0.5 (Current)
- ✨ New command:
start [id]for session-local GLM shell (no global settings changes) - ✨ New command:
env [id] --shell <shell>for shell export output - 🔒 Security: removed hardcoded auth token default
- 🧩 Added shorthand config key aliases:
token,haiku,sonnet,opus
v2.0.0
- ✨ Multi-profile support
- ✨ New commands:
init,set,setall,list,delete - ✨ Profile storage in
~/.claude/glm-switch/ - ✨ Default profile concept
v1.1.0
- ✅ JSONC support (comments in settings.json)
- ✅ Auto-create settings.json
v1.0.0
- 🎉 Initial release
- ✅ Basic on/off switching
License
MIT © Supermeo & Inwave DR Team
Links
- npm: https://www.npmjs.com/package/glm-switch
- GitHub: https://github.com/supermeo-studio/glm-switch
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
