Skip to content

One-command model switcher for Claude Code (Deepseek/KIMI/GLM/Qwen). Env-first config, masked status, PPINFRA fallback. No zshrc changes, one-step install/uninstall.

License

Notifications You must be signed in to change notification settings

jackie991/claude-code-switch

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Claude Code Model Switcher (CCM) πŸ”§

A powerful Claude Code model switching tool with support for multiple AI service providers and intelligent fallback mechanisms

License: MIT Bash Platform

δΈ­ζ–‡ζ–‡ζ‘£ | English

πŸš€ Quick Start (60 seconds)

  • Install (adds ccm function to your shell rc)
chmod +x install.sh ccm.sh && ./install.sh
source ~/.zshrc  # reload current shell
  • Configure (env > config)
# Option A: create/edit config file
ccm            # first run creates ~/.ccm_config
ccm config     # open it in your editor

# Option B: set environment variables (highest priority)
export DEEPSEEK_API_KEY=sk-...
  • Use (after install)
ccm deepseek   # or: ccm ds / ccm kimi / ccm qwen / ccm glm / ccm claude / ccm opus
ccm status
  • Uninstall
./uninstall.sh

Notes: installer adds a ccm() function into your ~/.zshrc (or ~/.bashrc). Secrets are masked in status. Recommend chmod 600 ~/.ccm_config

🌟 Features

  • πŸ€– Multi-model Support: Claude, Deepseek, KIMI, GLM, Qwen and other mainstream AI models
  • πŸ”„ Smart Fallback Mechanism: Official API priority with automatic fallback to PPINFRA backup service
  • ⚑ Quick Switching: One-click switching between different AI models to boost productivity
  • 🎨 Colorful Interface: Intuitive command-line interface with clear switching status display
  • πŸ›‘οΈ Secure Configuration: Independent configuration file for API key management, multi-editor support
  • πŸ“Š Status Monitoring: Real-time display of current model configuration and key status

πŸ“¦ Supported Models

Model Official Support Fallback Support(PPINFRA) Features
πŸŒ™ KIMI2 βœ… moonshot-v1-128k βœ… moonshotai/kimi-k2-0905 Long text processing
πŸ€– Deepseek βœ… deepseek-chat βœ… deepseek/deepseek-v3.1 Cost-effective reasoning
🐱 LongCat βœ… LongCat-Flash-Chat ❌ Official only High-speed chat
πŸͺ Qwen ⚠️ Requires endpoint config βœ… qwen3-next-80b-a3b-thinking Thinking model
πŸ‡¨πŸ‡³ GLM4.5 βœ… glm-4-plus ❌ Official only Zhipu AI
🧠 Claude Sonnet 4 βœ… claude-sonnet-4-20250514 ❌ Official only Balanced performance
πŸš€ Claude Opus 4.1 βœ… claude-opus-4-1-20250805 ❌ Official only Strongest reasoning

πŸš€ Quick Start

1. Download Script

# Clone the project
git clone https://github.com/yourusername/claude-code-switch.git
cd claude-code-switch

# Or download script directly
wget https://raw.githubusercontent.com/yourusername/claude-code-switch/main/ccm.sh
chmod +x ccm.sh

2. First Run

./ccm.sh

First run will automatically create configuration file ~/.ccm_config. Please edit this file to add your API keys.

3. Configure API Keys

πŸ”‘ Priority: Environment Variables > Configuration File

CCM follows a smart configuration hierarchy:

  1. Environment variables (highest priority) - export DEEPSEEK_API_KEY=your-key
  2. Configuration file ~/.ccm_config (fallback when env vars not set)
# Option 1: Set environment variables (recommended for security)
export DEEPSEEK_API_KEY=sk-your-deepseek-api-key
export KIMI_API_KEY=your-kimi-api-key
export LONGCAT_API_KEY=your-longcat-api-key
export PPINFRA_API_KEY=your-ppinfra-api-key

# Option 2: Edit configuration file
./ccm.sh config
# Or manually: vim ~/.ccm_config

Configuration file example:

# CCM Configuration File
# Note: Environment variables take priority over this file

# Official API keys
DEEPSEEK_API_KEY=sk-your-deepseek-api-key
KIMI_API_KEY=your-kimi-api-key
LONGCAT_API_KEY=your-longcat-api-key
GLM_API_KEY=your-glm-api-key
QWEN_API_KEY=your-qwen-api-key
QWEN_ANTHROPIC_BASE_URL=https://your-qwen-anthropic-gateway

# Optional: override model IDs (if omitted, defaults are used)
DEEPSEEK_MODEL=deepseek-chat
DEEPSEEK_SMALL_FAST_MODEL=deepseek-chat
KIMI_MODEL=kimi-k2-0905-preview
KIMI_SMALL_FAST_MODEL=kimi-k2-0905-preview
LONGCAT_MODEL=LongCat-Flash-Thinking
LONGCAT_SMALL_FAST_MODEL=LongCat-Flash-Chat
QWEN_MODEL=qwen3-next-80b-a3b-thinking
QWEN_SMALL_FAST_MODEL=qwen3-next-80b-a3b-thinking
GLM_MODEL=glm-4.5
GLM_SMALL_FAST_MODEL=glm-4.5-air
CLAUDE_MODEL=claude-sonnet-4-20250514
CLAUDE_SMALL_FAST_MODEL=claude-sonnet-4-20250514
OPUS_MODEL=claude-opus-4-1-20250805
OPUS_SMALL_FAST_MODEL=claude-sonnet-4-20250514

# Fallback service (only enabled when official keys are missing)
PPINFRA_API_KEY=your-ppinfra-api-key

πŸ“– Usage

Basic Commands

# Switch to different models
ccm kimi          # Switch to KIMI2
ccm deepseek      # Switch to Deepseek  
ccm qwen          # Switch to Qwen
ccm glm           # Switch to GLM4.5
ccm longcat       # Switch to LongCat
ccm claude        # Switch to Claude Sonnet 4
ccm opus          # Switch to Claude Opus 4.1

# View current status (masked)
ccm status

# Edit configuration
ccm config

# Show help
ccm help

Official keys are required (and model IDs are configurable)

To use a given model, you must provide an official API key either:

  • as an environment variable in your shell session; or
  • in ~/.ccm_config (the installer created it on first run)

You may also override the default model IDs in ~/.ccm_config using per-provider variables (e.g., DEEPSEEK_MODEL, KIMI_MODEL, LONGCAT_MODEL, etc.). If omitted, sensible defaults are used. Placeholders like your-xxx-api-key or empty values are treated as not configured.

Command Shortcuts

ccm ds           # Short for deepseek
ccm s            # Short for claude sonnet  
ccm o            # Short for opus
ccm st           # Short for status

Usage Examples

# Switch to KIMI for long text processing
ccm kimi
ccm status
πŸ“Š Current model configuration:
   BASE_URL: https://api.moonshot.cn/v1/anthropic
   AUTH_TOKEN: [Set]
   MODEL: kimi-k2-0905-preview
   SMALL_MODEL: kimi-k2-0905-preview

# Switch to Deepseek for code generation
ccm ds
ccm status
πŸ“Š Current model configuration:
   BASE_URL: https://api.deepseek.com/anthropic   # or PPINFRA fallback if official key is missing
   AUTH_TOKEN: [Set]
   MODEL: deepseek-chat
   SMALL_MODEL: deepseek-chat

πŸ› οΈ Install (adds ccm function to rc)

CCM supports safe one-step installation without modifying your shell configuration files.

One-step install

# From the project directory
chmod +x install.sh ccm.sh
./install.sh
  • Writes a ccm() function block into your rc (zsh preferred, bash fallback)
  • Does NOT copy binaries or modify PATH
  • Idempotent: re-running install replaces the previous block

Uninstall

./uninstall.sh

πŸ”§ Advanced Configuration

πŸ”‘ Configuration Priority System

CCM uses a smart hierarchical configuration system:

  1. Environment Variables (Highest Priority)

    • Set in your shell session: export DEEPSEEK_API_KEY=your-key
    • Recommended for temporary testing or CI/CD environments
    • Always takes precedence over configuration files
  2. Configuration File ~/.ccm_config (Fallback)

    • Persistent storage for API keys
    • Only used when corresponding environment variable is not set
    • Ideal for daily development use

Example scenario:

# Environment variable exists
export DEEPSEEK_API_KEY=env-key-123

# Config file contains
echo "DEEPSEEK_API_KEY=config-key-456" >> ~/.ccm_config

# CCM will use: env-key-123 (environment variable wins)
./ccm.sh status  # Shows DEEPSEEK_API_KEY: env-key-123

Smart Fallback Mechanism

CCM implements intelligent fallback mechanism:

  • Official API Priority: Uses official service if official keys are configured
  • Auto Fallback: Automatically switches to PPINFRA backup service when official keys are not configured
  • Transparent Switching: Seamless to users, commands remain consistent

Security and Privacy

  • Status output masks secrets (shows only first/last 4 chars)
  • ccm sets only ANTHROPIC_AUTH_TOKEN (not ANTHROPIC_API_KEY), plus base URL and model variables
  • Configuration file precedence: Environment Variables > ~/.ccm_config
  • Recommended file permission: chmod 600 ~/.ccm_config

PPINFRA Fallback Service

PPINFRA is a third-party AI model aggregation service providing:

  • Base URL: https://api.ppinfra.com/openai/v1/anthropic
  • Supported models:
    • moonshotai/kimi-k2-0905 (KIMI fallback)
    • deepseek/deepseek-v3.1 (Deepseek fallback)
    • qwen3-next-80b-a3b-thinking (Qwen fallback)

Configuration File Details

~/.ccm_config file contains all API key configurations:

# Required: Official keys from various providers (at least one)
DEEPSEEK_API_KEY=sk-your-deepseek-key
KIMI_API_KEY=your-kimi-key  
GLM_API_KEY=your-glm-key
QWEN_API_KEY=your-qwen-key

# Optional: Qwen official Anthropic-compatible endpoint
QWEN_ANTHROPIC_BASE_URL=https://your-qwen-gateway

# Optional but recommended: Fallback service key
PPINFRA_API_KEY=your-ppinfra-key

# Claude (if using API instead of Pro subscription)
CLAUDE_API_KEY=your-claude-key

πŸ› Troubleshooting

Common Issues

Q: Getting "XXX_API_KEY not detected" error

A: Check if the corresponding API key is correctly configured in ~/.ccm_config
   ./ccm.sh config  # Open config file to check

Q: Claude Code doesn't work after switching

A: Confirm environment variables are set correctly:
   ccm status  # Check current configuration status
   echo $ANTHROPIC_BASE_URL  # Check environment variable

Q: Want to force using official service instead of fallback

A: Configure the corresponding official API key, script will automatically prioritize official service

Debug Mode

# Show detailed status information
ccm status

# Check configuration file
cat ~/.ccm_config

# Verify environment variables
env | grep ANTHROPIC

# If you see an auth conflict about API_KEY vs AUTH_TOKEN
unset ANTHROPIC_API_KEY   # ccm only sets ANTHROPIC_AUTH_TOKEN

🀝 Contributing

Issues and Pull Requests are welcome!

Development Setup

git clone https://github.com/yourusername/claude-code-switch.git
cd claude-code-switch

Commit Guidelines

  • Use clear commit messages
  • Add appropriate tests
  • Update documentation

πŸ“„ License

This project is licensed under the MIT License.

πŸ™ Acknowledgments


⭐ If this project helps you, please give it a Star!

πŸ“§ Questions or suggestions? Feel free to submit an Issue

About

One-command model switcher for Claude Code (Deepseek/KIMI/GLM/Qwen). Env-first config, masked status, PPINFRA fallback. No zshrc changes, one-step install/uninstall.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%