npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

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.

npm version License: MIT


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

  1. Install dependencies
  2. Build TypeScript to JavaScript
  3. 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 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 b8eb5131e993419fa5f39181c7c6a1db.emTv6QgzVxbSo3a7

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.

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 1

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

6. 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

7. Check Current Status

glm-switch status

8. Delete Profile

glm-switch delete 1

9. Disable GLM Mode (Restore Claude API)

glm-switch off

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

Valid Config Keys

When using set or setall commands, you can use either aliases (recommended) or full keys:

Aliases (Recommended)

token
haiku
sonnet
opus
url

Full Keys

ANTHROPIC_BASE_URL
ANTHROPIC_AUTH_TOKEN
ANTHROPIC_DEFAULT_HAIKU_MODEL
ANTHROPIC_DEFAULT_SONNET_MODEL
ANTHROPIC_DEFAULT_OPUS_MODEL

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"
  }
}

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

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

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

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