Skip to content

Instantly share code, notes, and snippets.

@widnyana
Created April 22, 2026 04:34
Show Gist options
  • Select an option

  • Save widnyana/b8adb45c33787baa1a8ab58b04651597 to your computer and use it in GitHub Desktop.

Select an option

Save widnyana/b8adb45c33787baa1a8ab58b04651597 to your computer and use it in GitHub Desktop.
Claude Code model switcher
#!/usr/bin/env bash
set -euo pipefail
BASE_DIR="$HOME/.claude"
TARGET="${BASE_DIR}/settings.json"
GLM_SRC="${BASE_DIR}/settings.glm.json"
CLAUDE_SRC="${BASE_DIR}/settings.claude.json"
MODE="${1:-claude}"
case "$MODE" in
glm)
SRC="$GLM_SRC"
;;
claude)
SRC="$CLAUDE_SRC"
;;
*)
echo "Usage: cc-switch-model [glm|claude]"
exit 1
;;
esac
if [[ ! -f "$SRC" ]]; then
echo "Error: source file not found: $SRC"
exit 1
fi
ln -sfn "$SRC" "$TARGET"
echo "Switched settings.json -> $(basename "$SRC")"

How it works

  1. Expects two config files to exist:
  • ~/.claude/settings.glm.json — your GLM model settings
  • ~/.claude/settings.claude.json — your Claude model settings
  1. Takes one argument: glm or claude (defaults to claude)
  2. Symlinks ~/.claude/settings.json → whichever source you picked

Setup

  1. Create the two source config files with whatever settings differ per model:
# Example: copy your current settings as a starting point
cp ~/.claude/settings.json ~/.claude/settings.claude.json
cp ~/.claude/settings.json ~/.claude/settings.glm.json
# Then edit each one for its model

~/.claude/settings.glm.json must contains Z.ai required configs, see example below

{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "<YOUR Z.AI TOKEN GOES HERE>",
    "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5.1",
    "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "10240"
  },
  ...
}
  1. Save the script somewhere on your $PATH and make it executable:
mkdir -p ~/.local/bin  # or wherever you keep personal scripts
# save the script as ~/.local/bin/cc-switch-model
chmod +x ~/.local/bin/cc-switch-model
  1. Make sure ~/.local/bin is in your PATH (add to ~/.zshrc if not):
export PATH="$HOME/.local/bin:$PATH"

Usage

cc-switch-model glm      # switch to GLM settings
cc-switch-model claude   # switch to Claude settings (default)

Note: Claude Code needs to be restarted after switching for the new settings to take effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment