中文 (Chinese) | English
Environment Configuration Switcher for Anthropic-Compatible AI Providers
Features • Installation • Quick Start • Commands • Configuration • Troubleshooting
Problem: Manually updating Claude model configurations in your shell environment is tedious and error-prone.
- Switching between different AI providers (Kimi, GLM, Minimax, etc.) requires editing multiple environment files
- Configuration changes don't take effect until you restart your shell
- Easy to forget which provider is currently configured
Solution: freecc enables one-command model switching directly in your shell.
# Before: Edit files, restart shell, check configs...
# After: Just type this!
freecc switch kimi🎯 Easy Provider Switching - Switch between AI providers (Kimi, GLM, Minimax, etc.) with a single command
🚀 Zero Setup - Automatic hook installation on npm install
🐚 Cross-Shell Support - Works with Bash, Zsh, Fish, PowerShell, and 5+ other shells
🔄 Idempotent - Safe to run multiple times, won't create duplicates
📦 Lightweight - Minimal dependencies, ~50KB total
✅ Anthropic Compatible - Supports any Anthropic API-compatible provider
# Install globally
npm install -g @free-air/claude-code
# Initialize configuration file with examples
free init
# View available providers
free list
# Switch to a provider
free switch kimi
# See what's currently active
free currentnpm install -g @free-air/claude-codeThe command free will be available in your shell. Hook installation is automatic.
npm install --save-dev @free-air/claude-code
npx free --helpIf automatic installation doesn't work:
free hookThen open a new terminal or run:
source ~/.bashrc # or ~/.zshrc, ~/.config/fish/config.fish, etc.List all available provider configurations.
$ free list
Available configurations:
• kimi
• glm
• minimaxShow the currently active provider configuration.
$ free current
Current config: kimiSwitch to a provider and Load its environment variables.
$ free switch glm
export ANTHROPIC_BASE_URL="https://api.z.ai/api/anthropic"
export ANTHROPIC_AUTH_TOKEN="your_zai_api_key"
export ANTHROPIC_DEFAULT_SONNET_MODEL="glm-4.6"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-4.5-air"
export FREE_CURRENT_CONFIG="glm"
[OK] Switched to config: glmCreate a template configuration file with example providers.
$ free init
[OK] Created example config file: /home/user/.free.json
Edit this file to add your own configurations and API keys.Manually install the hook function to your shell configuration.
$ free hook
[OK] Installed to /home/user/.bashrc
[OK] Installed to /home/user/.config/fish/config.fishRemove all hooks from shell configuration files.
$ free remove
[OK] Removed from bash: /home/user/.bashrc
[OK] Removed from zsh: /home/user/.zshrcConfiguration is stored in ~/.free.json (JSON format).
- Linux/macOS:
~/.free.json - Windows:
C:\Users\<YourUsername>\.free.json
{
"kimi": {
"ANTHROPIC_BASE_URL": "https://api.moonshot.ai/anthropic",
"ANTHROPIC_AUTH_TOKEN": "your_moonshot_api_key",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "kimi-k2.5",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "kimi-k2.5",
"ENABLE_TOOL_SEARCH": "false"
},
"glm": {
"ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
"ANTHROPIC_AUTH_TOKEN": "your_zai_api_key",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.6",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air"
},
"minimax": {
"ANTHROPIC_BASE_URL": "https://api.minimax.chat/anthropic",
"ANTHROPIC_AUTH_TOKEN": "your_minimax_api_key",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "MiniMax-M1",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "MiniMax-Text-01"
}
}Edit ~/.free.json and add a new entry:
{
"my-provider": {
"ANTHROPIC_BASE_URL": "https://your-api-endpoint.com/anthropic",
"ANTHROPIC_AUTH_TOKEN": "your_api_key",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "model-name",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "model-name"
}
}Then:
free switch my-providerThe tool automatically detects and supports:
| Shell | Config File | Status |
|---|---|---|
| Bash | ~/.bashrc, ~/.bash_profile |
✅ Supported |
| Zsh | ~/.zshrc |
✅ Supported |
| Fish | ~/.config/fish/config.fish |
✅ Supported |
| PowerShell | Multiple locations | ✅ Supported |
| Ksh | ~/.kshrc |
✅ Supported |
| Tcsh | ~/.tcshrc |
✅ Supported |
| Csh | ~/.cshrc |
✅ Supported |
| Dash | ~/.dashrc |
✅ Supported |
| Sh | ~/.profile |
✅ Supported |
-
Hook Installation: On npm install, the tool automatically adds a function to your shell config file.
-
Environment Variable Loading: When you run
free switch <name>, it outputs shell commands that set the environment variables. -
Shell Wrapper: The hook function intercepts
free switchand evaluates the output, making variables available in your current session. -
Idempotent: The installation uses marker blocks to prevent duplicate entries.
# For Kimi project
free switch kimi
# For GLM project
free switch glm
# Back to default
free switch minimaxcurrent_provider=$(echo $FREE_CURRENT_CONFIG)
echo "Using provider: $current_provider"# Switch provider
free switch kimi
# Run Claude commands (will use kimi's API endpoint)
claude chat "hello world"free switch my-local-provider
# Tools configured to use ANTHROPIC_BASE_URL will now use your local providerProblem: free: command not found
Solution:
- Verify npm installation:
npm list -g @free-air/claude-code - Ensure npm bin directory is in PATH:
echo $PATH - Reinstall:
npm install -g @free-air/claude-code - Manually install hook:
free hook
Problem: Hook isn't available after opening a new terminal
Solution:
- Run
free hookto reinstall - Open a new terminal window
- For PowerShell: May require execution policy change
Problem: Failed to parse ~/.free.json
Solution:
- Create and initialize:
free init - Verify JSON is valid:
cat ~/.free.json - Use a JSON validator to check syntax
Problem: After free switch, variables aren't available
Solution:
- Verify you're using the wrapper:
type free(bash/zsh) orGet-Command free(PowerShell) - Make sure hook was installed:
grep -n "free-env manager" ~/.bashrc - Verify config exists:
cat ~/.free.json - Reinstall hook:
free hook
Problem: Hook installed in wrong location
Solution: The tool checks multiple standard locations. You can manually add to additional profiles if needed:
# For bash
source ~/.bashrc
# For zsh
source ~/.zshrc
# For fish
source ~/.config/fish/config.fishWhen you run free switch kimi, the tool sets:
FREE_CURRENT_CONFIG- The active provider name- All environment variables from the configuration
echo $FREE_CURRENT_CONFIG# Remove globally
npm uninstall -g @free-air/claude-code
# Clean up shell config
free removeThis tool works with any provider that is compatible with the Anthropic API specification, including:
- Moonshot AI (Kimi)
- Zhipu AI (GLM)
- Minimax
- Claude (Anthropic)
- Custom local providers
git clone https://github.com/wusfe/switch-claude-model.git
cd switch-claude-model
npm install
npm run build
npm linkfree hook
free list
free switch kimi
free current
free removeMIT License - feel free to use in your projects!
wusfe - GitHub
Issues and pull requests are welcome on GitHub.
- Initial release
- Support for 9 shell types (Bash, Zsh, Fish, PowerShell, Ksh, Tcsh, Csh, Dash, Sh)
- Automatic hook installation via npm postinstall
- Manual hook installation via
free hookcommand - Multi-file configuration support
- Idempotent block insertion/removal freecc switch freecc --help
Alias:
- `kim` -> `kimi`
## Examples
```bash
freecc list
freecc switch kim
freecc --help