A powerful Claude Code model switching tool with support for multiple AI service providers and intelligent fallback mechanisms
- 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
- π€ 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
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 | β 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 |
# 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
./ccm.sh
First run will automatically create configuration file ~/.ccm_config
. Please edit this file to add your API keys.
π Priority: Environment Variables > Configuration File
CCM follows a smart configuration hierarchy:
- Environment variables (highest priority) -
export DEEPSEEK_API_KEY=your-key
- 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
# 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
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.
ccm ds # Short for deepseek
ccm s # Short for claude sonnet
ccm o # Short for opus
ccm st # Short for status
# 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
CCM supports safe one-step installation without modifying your shell configuration files.
# 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.sh
CCM uses a smart hierarchical configuration system:
-
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
- Set in your shell session:
-
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
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
- Status output masks secrets (shows only first/last 4 chars)
- ccm sets only
ANTHROPIC_AUTH_TOKEN
(notANTHROPIC_API_KEY
), plus base URL and model variables - Configuration file precedence: Environment Variables > ~/.ccm_config
- Recommended file permission:
chmod 600 ~/.ccm_config
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)
~/.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
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
# 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
Issues and Pull Requests are welcome!
git clone https://github.com/yourusername/claude-code-switch.git
cd claude-code-switch
- Use clear commit messages
- Add appropriate tests
- Update documentation
This project is licensed under the MIT License.
- Claude - AI Assistant
- Deepseek - Efficient reasoning model
- KIMI - Long text processing
- Zhipu AI - GLM large model
- Qwen - Alibaba Tongyi Qianwen
β If this project helps you, please give it a Star!
π§ Questions or suggestions? Feel free to submit an Issue