Skip to content

Instantly share code, notes, and snippets.

@xpepper
Created January 13, 2026 20:12
Show Gist options
  • Select an option

  • Save xpepper/996c16292d06b9bd2c06a8378d04dbce to your computer and use it in GitHub Desktop.

Select an option

Save xpepper/996c16292d06b9bd2c06a8378d04dbce to your computer and use it in GitHub Desktop.
A Claude Code switcher between Anthropic coding subscriptions and Z.ai coding plan :D
#!/bin/bash
set -e
usage() {
echo "Usage:"
echo " switch-claude [-y] {pro|zai}"
echo " switch-claude status"
}
AUTO_YES=false
while getopts "y" opt; do
case "$opt" in
y) AUTO_YES=true ;;
*) usage; exit 1 ;;
esac
done
shift $((OPTIND - 1))
CMD="${1:-}"
# ---- status command ---------------------------------------------------------
if [ "$CMD" = "status" ]; then
SETTINGS_LINK="$HOME/.claude/settings.json"
if [ ! -e "$SETTINGS_LINK" ]; then
echo "unknown (no ~/.claude/settings.json found)"
exit 0
fi
# Try to resolve symlink target (works on macOS)
TARGET_PATH="$(readlink "$SETTINGS_LINK" 2>/dev/null || true)"
# If it's not a symlink, readlink returns empty
if [ -n "$TARGET_PATH" ]; then
case "$TARGET_PATH" in
*settings.zai.json) echo "zai"; exit 0 ;;
*settings.pro.json) echo "pro"; exit 0 ;;
esac
fi
# Fallback: infer from file content (no jq needed)
# If ANTHROPIC_BASE_URL is present and has a non-empty string value -> zai
if grep -Eq '"ANTHROPIC_BASE_URL"[[:space:]]*:[[:space:]]*"[^"]+"' "$SETTINGS_LINK"; then
echo "zai"
else
echo "pro"
fi
exit 0
fi
# ---- switch command ---------------------------------------------------------
TARGET="$CMD"
case "$TARGET" in
pro)
TARGET_FILE="$HOME/.claude/settings.pro.json"
LABEL="Claude Pro"
;;
zai)
TARGET_FILE="$HOME/.claude/settings.zai.json"
LABEL="Z.ai"
;;
*)
usage
exit 1
;;
esac
if [ ! -f "$TARGET_FILE" ]; then
echo "Error: $TARGET_FILE does not exist"
exit 1
fi
if [ "$AUTO_YES" = false ]; then
echo "You are about to switch Claude Code to: $LABEL"
echo "This will update ~/.claude/settings.json"
printf "Continue? [y/N] "
read -r ANSWER
case "$ANSWER" in
y|Y|yes|YES) ;;
*)
echo "Aborted"
exit 0
;;
esac
fi
ln -sf "$TARGET_FILE" "$HOME/.claude/settings.json"
echo "Switched to $LABEL settings"
# Reminder if Claude Code appears to be running (restart required)
if pgrep -f '(^|/)(claude|Claude Code)( |$)' >/dev/null 2>&1; then
echo "Note: Claude Code appears to be running. Restart required for changes to take effect."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment