A powerful CLI tool for switching between API provider settings for Claude Code. Manage multiple provider configurations (DeepSeek, GLM, MiniMax, Qwen) with global access, automatic backups, and validation.
- ✅ Global Tool: Install once, use from any directory
- 📋 List Profiles: View all available profiles with source indicators
- 🔍 Show Current: Display current active profile
- ✔️ Validation: Validate profiles before switching
- 💾 Automatic Backups: Automatic backup before switching
- 🔄 Restore Backups: Restore from previous backups
- 📊 Compare Profiles: Diff two profiles
- ✏️ Edit Profiles: Edit profiles with your default editor
- 📤 Import/Export: Import profiles from JSON files
- 🌍 Migration Tools: Migrate local profiles to global configuration
- 🔒 Secure: API tokens are masked in output
- 🎨 Beautiful Output: Rich formatting with colors and tables
- ⚙️ Global Configuration: Hierarchical profile discovery with environment variable support
macOS Only - This tool is currently developed, tested, and supported exclusively on macOS.
- ✅ Fully Supported: macOS (Monterey 12.0 and later)
- ❌ Not Supported: Windows, Linux, or other operating systems
- 🔄 Future Plans: Cross-platform support may be considered in future releases
The tool is designed to work with Claude Code, which is primarily available on macOS. All documentation and troubleshooting guidance assumes a macOS environment.
Before installing, ensure you have:
- macOS 12.0 (Monterey) or later
- Python 3.8+ installed (comes with macOS by default)
- uv package manager - install with:
# Using Homebrew (recommended) brew install uv # Or install directly curl -LsSf https://astral.sh/uv/install.sh | sh
- Terminal access with shell (zsh or bash)
Note: This tool is designed for macOS systems with Claude Code installed. Ensure you have Claude Code properly set up before using this switcher.
# Install globally as a tool (recommended)
uv tool install .
# Build and install from wheel
uv build
uv tool install dist/*.whlpip install cc-api-switcherAfter installation, initialize global configuration:
cas initIf you have existing profile files, migrate them to global configuration:
cas migrate --forcecc-api-switch to cas for convenience.
If you were using the previous cc-api-switch command:
- The new command is
cas(shorter and easier to type) - All functionality and arguments remain identical
- Update any scripts or automation to use
casinstead ofcc-api-switch - The old
cc-api-switchcommand is no longer available after updating
# Old command (no longer available)
cc-api-switch list
# New command (use this instead)
cas listcas listcas switch deepseek
cas switch glm
cas switch minimax
cas switch qwencas showcas validate deepseekcas backupcas restore --listcas restore settings.json.backup.20251103_143022cas diff deepseek glmcas import ~/Downloads/my-profile.json --name customcas edit deepseek# List profiles from a specific directory
cas list --dir ~/my-profiles
# Switch using profiles from a specific directory
cas switch deepseek --dir ~/my-profiles
# Import into a specific directory
cas import profile.json --name new --dir ~/my-profiles# Switch to a different settings file location
cas switch deepseek --target ~/.config/claude/settings.jsoncas switch deepseek --no-backupcas switch deepseek --verbosecas initcas profile-dir# Show all configuration
cas config show
# Get specific setting
cas config get default_profile_dir
# Set configuration value
cas config set auto_backup false# Preview migration (dry run)
cas migrate --dry-run
# Perform migration
cas migrate
# Migrate and clean up local files
cas migrate --cleanup# Override profile directory
export CC_API_SWITCHER_PROFILE_DIR="~/my-profiles"
cas list
# Use custom config directory
export XDG_CONFIG_HOME="~/.my-config"
cas initProfile files are JSON files containing your API provider settings. They should follow this structure:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
"ANTHROPIC_AUTH_TOKEN": "sk-your-token-here",
"API_TIMEOUT_MS": "600000",
"ANTHROPIC_MODEL": "deepseek-chat",
"ANTHROPIC_SMALL_FAST_MODEL": "deepseek-chat",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-chat",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-chat",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-chat"
},
"statusLine": {
"type": "command",
"command": "/Users/username/.claude/dracula-statusline.sh",
"padding": 0
},
"enabledPlugins": {
"uni-secretary-tools@hugolld-CC-plugins": true
},
"alwaysThinkingEnabled": false
}{
"env": {
"ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
"ANTHROPIC_AUTH_TOKEN": "sk-deepseek-example-placeholder",
"API_TIMEOUT_MS": "600000",
"ANTHROPIC_MODEL": "deepseek-chat"
}
}{
"env": {
"ANTHROPIC_BASE_URL": "https://open.bigmodel.cn/api/anthropic",
"ANTHROPIC_AUTH_TOKEN": "sk-glm-example-placeholder",
"API_TIMEOUT_MS": "3000000",
"ANTHROPIC_MODEL": "glm-4.6"
}
}{
"env": {
"ANTHROPIC_BASE_URL": "https://api.minimaxi.com/anthropic",
"ANTHROPIC_AUTH_TOKEN": "sk-minimax-example-placeholder",
"API_TIMEOUT_MS": "3000000",
"ANTHROPIC_MODEL": "MiniMax-M2"
}
}{
"env": {
"ANTHROPIC_BASE_URL": "https://dashscope.aliyuncs.com/api/v2/apps/claude-code-proxy",
"ANTHROPIC_AUTH_TOKEN": "sk-qwen-example-placeholder",
"API_TIMEOUT_MS": "3000000",
"ANTHROPIC_MODEL": "qwen-max"
}
}- DeepSeek: https://platform.deepseek.com/
- GLM: https://open.bigmodel.cn/
- MiniMax: https://api.minimaxi.com/
- Qwen: https://dashscope.aliyun.com/
- Kimi: https://platform.moonshot.cn/
cc-api-switcher/
├── pyproject.toml # Project configuration
├── README.md # This file
├── src/
│ └── settings_switcher/
│ ├── __init__.py # Package info
│ ├── cli.py # Command-line interface
│ ├── config.py # Profile models and validation
│ ├── core.py # Core switching logic
│ └── exceptions.py # Custom exceptions
├── tests/
│ ├── __init__.py
│ ├── test_config.py # Config tests
│ ├── test_core.py # Core tests
│ └── test_cli.py # CLI tests
# Clone and setup
git clone <repo>
cd cc-api-switcher
# Install dependencies
uv sync --dev
# Run tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=src
# Format code
uv run ruff format .
# Lint code
uv run ruff check .
# Type checking
uv run mypy srcTo add support for a new provider:
- Add a new profile file following the JSON structure above
- The provider will be automatically detected from the
ANTHROPIC_BASE_URL - Update the
providerproperty inSettingsProfileclass if needed
⚠️ API tokens are sensitive: Keep your profile files secure- 🔒 File permissions: The tool automatically sets settings file permissions to 0o600 (owner read/write only)
- 🔍 Token masking: API tokens are masked in all output (showing only first/last 4 characters)
- 💾 Backups: Automatic backups protect against configuration loss
- 🚫 Path traversal: Input paths are validated to prevent directory traversal attacks
zsh: command not found: casSolution:
- Ensure uv is installed:
brew install uv - Check installation:
uv tool list - Verify PATH includes uv's bin directory:
echo $PATH - Add uv bin to PATH if needed:
export PATH="$HOME/.cargo/bin:$PATH"
Error: Permission denied when accessing ~/.claude/settings.json
Solution:
- Check file permissions:
ls -la ~/.claude/settings.json - Fix permissions:
chmod 600 ~/.claude/settings.json - Ensure ownership:
chown $USER ~/.claude/settings.json
# For zsh (default on modern macOS)
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
# For bash
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profileError: Profile 'deepseek' not found
Solution: Use cas list to see available profiles, or use --dir to specify the profile directory.
Profile validation failed:
- Missing ANTHROPIC_BASE_URL in env
Solution: Ensure your profile JSON has all required fields: ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN in the env section.
Error: Failed to create backup
Solution: Check that you have write permissions to the backup directory (~/.config/cc-api-switcher/backups/).
- Default:
~/.claude/settings.jsonon macOS - Custom: Use
--targetflag for different locations - Verification: Check if Claude Code can read the settings file
If experiencing path-related issues:
- Use absolute paths:
cas switch deepseek --target ~/Documents/custom-settings.json - Check Home Directory:
echo $HOME - Verify Claude Code installation:
which claude
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
For issues, questions, or suggestions, please open an issue on GitHub.