A CLI tool to switch between AI providers and models for Claude Code by outputting shell commands that can be executed to set environment variables.
RouterSwitch allows you to easily switch between different AI providers (like DeepSeek, GLM, MiniMax) and their models by outputting shell export commands. Version 3.0 returns to the shell command output approach for better shell integration while providing an optional wrapper function for easier usage.
- ๐ Shell Command Output: Outputs shell commands for environment variable setting
- ๐ Optional Shell Wrapper: Generate wrapper function for easier usage
- ๐ Provider Switching: Seamlessly switch between AI providers
- ๐ Configuration File: JSON-based provider configuration
- โ Validation: Validates providers and models before setting
- ๐ก๏ธ Error Handling: Comprehensive error checking and reporting
- ๐ Clean Switching: Automatically unsets old provider variables
- Go to the Releases page
- Download the appropriate binary for your platform:
- Linux x86-64:
router-switch-v*-linux-x86_64 - Linux ARM64:
router-switch-v*-linux-arm64 - macOS x86-64 (Intel):
router-switch-v*-darwin-x86_64 - macOS ARM64 (Apple Silicon):
router-switch-v*-darwin-arm64
- Linux x86-64:
- Verify the download with the provided checksum
- Make it executable and install:
# Example for Linux x86-64
chmod +x router-switch-v*-linux-x86_64
sudo mv router-switch-v*-linux-x86_64 /usr/local/bin/router-switchgit clone https://github.com/aokihu/claude-code-env-switcher.git
cd RouterSwitch
# Build release version (recommended)
make release
# Or build both debug and release versions
make build-all
# Install release version system-wide (optional)
sudo make install-release# Switch to provider with eval
eval $(router-switch --provider deepseek --model deepseek-chat)
# Use short flags
eval $(router-switch -p glm)
# Use custom configuration file
eval $(router-switch --config /path/to/custom-config.json --provider deepseek)# Switch using source (safer for special characters)
source <(router-switch --provider deepseek --model deepseek-chat)
# Or with process substitution
source <(router-switch -p glm)# Generate and install shell wrapper
router-switch --install >> ~/.zshrc && source ~/.zshrc
# For bash
router-switch --install >> ~/.bashrc && source ~/.bashrc
# Now you can use simple syntax:
router-switch deepseek
router-switch deepseek deepseek-chat
router-switch -v glmCommand Output:
$ router-switch --provider deepseek --model deepseek-chat
export ANTHROPIC_BASE_URL='https://api.deepseek.com/anthropic'
export ANTHROPIC_AUTH_TOKEN='sk-your-api-key'
export ANTHROPIC_MODEL='deepseek-chat'
export ANTHROPIC_DEFAULT_SONNET_MODEL='deepseek-chat'
export ANTHROPIC_DEFAULT_OPUS_MODEL='deepseek-reasoner'
export ANTHROPIC_DEFAULT_HAIKU_MODEL='deepseek-chat'
export ROUTERSWITCH_CURRENT_PROVIDER='deepseek'With Shell Wrapper Installed:
$ router-switch deepseek
# No output, but environment variables are set in current shell
$ router-switch -v deepseek deepseek-chat
# Verbose output to stderrThe shell wrapper provides the easiest usage experience. Here's how to install it:
-
Generate the wrapper function:
router-switch --install > ~/.router-switch-wrapper.sh
-
Add to your shell configuration:
# For zsh cat ~/.router-switch-wrapper.sh >> ~/.zshrc # For bash cat ~/.router-switch-wrapper.sh >> ~/.bashrc
-
Reload your shell:
# For zsh source ~/.zshrc # For bash source ~/.bashrc
-
Verify installation:
$ router-switch Usage: router-switch <provider> [model] [options] provider: AI provider name (e.g., deepseek, glm, minimax) model: Optional model name options: Additional options passed to router-switch Examples: router-switch deepseek router-switch deepseek deepseek-chat router-switch -v glm
- Simplified syntax:
router-switch deepseekinstead ofeval $(router-switch -p deepseek) - Tab completion: Auto-completion for provider names
- Cross-shell: Works with both bash and zsh
- Argument flexibility: Supports both simple and flag-based syntax
- Pass-through: All original flags still work
Create a config.json file in the same directory as the binary:
{
"providers": {
"deepseek": {
"description": "Deepseek V3.2",
"base_url": "https://api.deepseek.com/anthropic",
"api_key": "your-deepseek-api-key",
"models": ["deepseek-chat", "deepseek-reasoner"],
"env": {
"ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-chat",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-reasoner",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-chat"
}
},
"glm": {
"description": "BigModel GLM 4.6",
"base_url": "https://open.bigmodel.cn/api/anthropic",
"api_key": "your-glm-api-key",
"models": [],
"env": {
"API_TIMEOUT_MS": "3000000",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
}
}
}
}providers: Object containing all available providers[provider-name]: Key used with-pflagdescription: Human-readable descriptionbase_url: API endpoint URLapi_key: Authentication key (โ ๏ธ Keep secure!)models: Array of available models (empty = use Claude Code defaults)env: Additional environment variables to set
- Never commit real API keys to version control
- Use environment variables or secure configuration management
- Replace
"your-api-key"with your actual keys in the config file - The example shows obscured keys for demonstration purposes only
Usage: router-switch [options]
Options:
-p, --provider <provider> Specify AI provider from config.json
-m, --model <model> Specify AI model for the provider
-c, --config <path> Specify custom configuration file path
-v, --verbose Show detailed output to stderr
-i, --install Generate shell wrapper function for easy usage
-V, --version Display version information
-h, --help Display this help message
RouterSwitch automatically sets these environment variables:
ANTHROPIC_BASE_URL: API endpoint URLANTHROPIC_AUTH_TOKEN: API authentication tokenANTHROPIC_MODEL: Selected model (if models are configured)ROUTERSWITCH_CURRENT_PROVIDER: Current provider tracking- Custom environment variables from provider configuration
# Quick switching with eval
eval $(router-switch --provider deepseek)
echo $ANTHROPIC_BASE_URL
# Using source (safer)
source <(router-switch --provider glm --model gpt-4)
echo $ANTHROPIC_BASE_URL
# With installed wrapper
router-switch deepseek deepseek-chat
echo $ANTHROPIC_BASE_URL
# In scripts
#!/bin/bash
eval $(router-switch -p deepseek)
./my-ai-app.py # App inherits the environment
# For CI/CD pipelines
source <(router-switch --provider deepseek --model deepseek-chat)
make testVersion 3.0 changes back to shell command output approach. The migration is straightforward:
If you were using v2.x:
# Old (v2.x)
router-switch --provider deepseek
# New (v3.x) - need to eval the output
eval $(router-switch --provider deepseek)Or install the shell wrapper for the same experience:
# One-time setup
router-switch --install >> ~/.zshrc && source ~/.zshrc
# Now use same syntax as v2.x
router-switch --provider deepseek- GCC compiler (or Clang on macOS)
- Make
- Standard C library
# Build release version (optimized)
make release
# Build debug version (with symbols)
make debug
# Build both versions
make build-all
# Development workflow (clean, debug, test)
make dev
# Production workflow (clean, release, test)
make prod
# Install release version system-wide
sudo make install-release
# Run tests
make test
# Clean all build artifacts
make clean- Release: Optimized binary with full compiler optimizations (
-O3,-flto,-march=native) - Debug: Development build with debug symbols and no optimization
- Debug version:
bin/debug/router-switch - Release version:
bin/release/router-switch
- Check that the provider name matches exactly in
config.json - Verify the configuration file is valid JSON
- Use
--configflag if your config file is elsewhere
- Try using
source <(command)instead - Check for special characters in API keys or values
- Ensure the command output doesn't contain extra text
- The tool automatically escapes special characters
- If you encounter issues, use
source <(router-switch ...)instead ofeval
- Ensure GCC is installed:
gcc --version - Check that all required source files are present
- Try
make clean && make all
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions:
- Check this README
- Review the help text:
router-switch --help - Open an issue on the project repository