glm-switch
v2.1.0
Published
CLI utility to switch between Claude API and GLM 4.6 models in Claude Code
Downloads
324
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
- 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 b8eb5131e993419fa5f39181c7c6a1db.emTv6QgzVxbSo3a73. 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. 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 15. 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/anthropic6. 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-57. Check Current Status
glm-switch status8. Delete Profile
glm-switch delete 19. 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 |
| 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 |
Config Key Aliases
For easier editing, you can use short aliases instead of full config key names:
| Alias | Full Key Name |
|-------|---------------|
| token | ANTHROPIC_AUTH_TOKEN |
| haiku | ANTHROPIC_DEFAULT_HAIKU_MODEL |
| sonnet | ANTHROPIC_DEFAULT_SONNET_MODEL |
| opus | ANTHROPIC_DEFAULT_OPUS_MODEL |
| url | ANTHROPIC_BASE_URL |
Examples with Aliases
# Set token (short)
glm-switch set 0 token my-token-123
# Update models (short)
glm-switch set 0 sonnet glm-5
glm-switch set 0 opus glm-5
glm-switch set 0 haiku glm-4.5-air
# Bulk update (short)
glm-switch setall sonnet glm-5Valid Config Keys
When using set or setall commands, you can use either aliases (recommended) or full keys:
Aliases (Recommended)
token
haiku
sonnet
opus
urlFull Keys
ANTHROPIC_BASE_URL
ANTHROPIC_AUTH_TOKEN
ANTHROPIC_DEFAULT_HAIKU_MODEL
ANTHROPIC_DEFAULT_SONNET_MODEL
ANTHROPIC_DEFAULT_OPUS_MODELHow 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"
}
}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 1Update 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
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.1.0 (Current)
- ✨ Config key aliases (token, haiku, sonnet, opus, url)
- ✨ Easier profile editing with short commands
- 🔧 Single source of truth for config templates
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.
