New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

glm-switch

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glm-switch

CLI utility to switch between Claude API and GLM 4.6 models in Claude Code

latest
npmnpm
Version
2.0.5
Version published
Maintainers
1
Created
Source

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.

npm version License: MIT

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

npm install -g glm-switch

Method 2: Install from GitHub

# Clone repository
git clone https://github.com/supermeo-studio/glm-switch.git
cd glm-switch

# Setup
npm run setup

The 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 KeyDescription
ANTHROPIC_BASE_URLAPI endpoint for GLM
ANTHROPIC_AUTH_TOKENAuthentication token
ANTHROPIC_DEFAULT_HAIKU_MODELHaiku model (lightweight)
ANTHROPIC_DEFAULT_SONNET_MODELSonnet model (balanced)
ANTHROPIC_DEFAULT_OPUS_MODELOpus 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 0

Output:

✓ 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_here

3. Apply Profile

# Apply default profile (0)
glm-switch on

# Apply specific profile
glm-switch on 1

Important: After applying, restart Claude Code/VS Code for changes to take effect.

# Start a new child shell using profile 1 env
glm-switch start 1

# Exit child shell to return to your original terminal context
exit

This 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-Expression

Use 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 1

7. 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/anthropic

8. List All Profiles

glm-switch list

Output:

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-5

9. Check Current Status

glm-switch status

10. Delete Profile

glm-switch delete 1

11. Disable GLM Mode (Restore Claude API)

glm-switch off

All Commands

CommandDescriptionExample
init [id]Create a new profileglm-switch init 0
set <id> <key> <value>Set value for a specific profileglm-switch set 0 token xxxx
setall <key> <value>Set value for all profilesglm-switch setall sonnet glm-5
on [id]Apply profile (default: 0)glm-switch on 1
start [id]Start child shell with profile env onlyglm-switch start 1
env [id] --shell <shell>Print shell export commandsglm-switch env 1 --shell zsh
offRemove GLM configglm-switch off
statusShow current statusglm-switch status
listList all profilesglm-switch list
delete <id>Delete a profileglm-switch delete 1
--helpShow helpglm-switch --help
--versionShow versionglm-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
opus

How 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

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 Code

Add 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 1

Use 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
exit

Update Models for All

glm-switch setall sonnet glm-5
glm-switch setall opus glm-5
glm-switch setall haiku glm-4.5-air

Safety Features

  • Automatic Backup - Creates .backup file 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 - start mode 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 PATH

Changes not taking effect

# 1. Check status
glm-switch status

# 2. Restart Claude Code/VS Code COMPLETELY
# 3. Check status again

Profile does not exist

# List all profiles
glm-switch list

# Create profile if needed
glm-switch init 0

Invalid 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_MODEL

Permission errors

Windows: Run terminal as Administrator

macOS:

# Check permissions
ls -la ~/.claude/

# Fix permissions
chmod 644 ~/.claude/settings.json

Development

Clone & Setup

git clone https://github.com/supermeo-studio/glm-switch.git
cd glm-switch
npm run setup

Build

npm run build

Watch Mode

npm run dev

Clean

npm run clean

Uninstallation

Global npm package

npm uninstall -g glm-switch

Manual cleanup (optional)

# Remove profiles directory
rm -rf ~/.claude/glm-switch

Platform Support

PlatformStatusSettings Location
Windows 10/11✅ SupportedC:\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

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Keywords

claude

FAQs

Package last updated on 30 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts