claude-code-env
v1.0.0
Published
CLI tool to switch AI providers for Claude Code
Downloads
5
Maintainers
Readme
Claude Code Environment Manager (ccenv)
A command-line tool to easily switch between different AI providers for Claude Code by managing the ~/.claude/settings.json configuration.
Features
- Switch between multiple AI providers with a single command
- Support for both direct provider APIs and PPINFRA proxy
- Automatic environment variable management
- Secure token handling with masked output
- Easy configuration through JSON file
Installation
Local Development
# Clone the repository
git clone <your-repo-url>
cd claude-code-env
# Install dependencies
npm install
# Build the project
npm run build
# Link globally to use 'ccenv' command
npm linkGlobal Installation (After Publishing)
npm install -g claude-code-envConfiguration
The tool supports two ways to configure API tokens (in priority order):
1. Environment Variables (Recommended)
Set environment variables before running the command:
# Export variables in your shell
export DEEPSEEK_AUTH_TOKEN="your_actual_deepseek_api_token"
export KIMI_AUTH_TOKEN="your_actual_kimi_api_token"
export GLM_AUTH_TOKEN="your_actual_glm_api_token"
# Then run ccenv
ccenv deepseekOr set them inline:
DEEPSEEK_AUTH_TOKEN="your_token" ccenv deepseek2. Configuration File (Fallback)
If environment variables are not set, the tool falls back to src/base.json:
{
"DEEPSEEK": {
"DEEPSEEK_AUTH_TOKEN": "your_actual_deepseek_api_token",
...
},
"KIMI": {
"KIMI_AUTH_TOKEN": "your_actual_kimi_api_token",
...
},
...
}After updating the tokens in base.json, rebuild the project:
npm run buildPriority: Environment variables take precedence over base.json values.
Usage
Basic Commands
# Show help
ccenv help
# Switch to a provider
ccenv deepseek # Switch to DeepSeek
ccenv glm # Switch to GLM-4.6
ccenv kimi # Switch to Kimi
ccenv qwen # Switch to Alibaba Qwen
ccenv minimax # Switch to MiniMax
ccenv longcat # Switch to LongCat
# Use PPINFRA proxy
ccenv pp kimi # Switch to PPINFRA Kimi
ccenv pp deepseek # Switch to PPINFRA DeepSeek
ccenv pp glm # Switch to PPINFRA GLM
ccenv pp qwen # Switch to PPINFRA Qwen
ccenv pp minimax # Switch to PPINFRA MiniMax
# Clear configuration
ccenv clear # Clear all environment variables
# Dynamic providers (any provider not in base.json)
ZAI_AUTH_TOKEN="your_token" ZAI_BASE_URL="https://api.z.ai/api/anthropic" ccenv zaiDynamic Provider Support
You can use any provider not defined in base.json by setting environment variables:
# Minimum required variables
PROVIDER_AUTH_TOKEN="your_token" \
PROVIDER_BASE_URL="https://api.provider.com/anthropic" \
ccenv provider
# With optional model configuration
PROVIDER_AUTH_TOKEN="your_token" \
PROVIDER_BASE_URL="https://api.provider.com/anthropic" \
PROVIDER_MODEL="model-name" \
PROVIDER_SMALL_FAST_MODEL="fast-model" \
ccenv providerExample with ZAI:
ZAI_AUTH_TOKEN="your_zai_token" \
ZAI_BASE_URL="https://api.z.ai/api/anthropic" \
ZAI_MODEL="claude-sonnet-4-5" \
ccenv zaiThis allows you to use any Anthropic-compatible API provider without modifying the code.
Workflow Example
# Switch to DeepSeek provider
ccenv deepseek
# Launch Claude Code
# Claude Code will now use DeepSeek API
# Switch to PPINFRA Kimi
ccenv pp kimi
# Relaunch Claude Code
# Claude Code will now use PPINFRA with Kimi model
# Clear configuration when done
ccenv clearSupported Providers
Direct Provider APIs
| Provider | Command | Base URL | Default Model |
|----------|---------|----------|---------------|
| DeepSeek | ccenv deepseek | https://api.deepseek.com/anthropic | deepseek-chat |
| Kimi | ccenv kimi | https://api.moonshot.cn/anthropic | kimi-k2-turbo-preview |
| GLM | ccenv glm | https://open.bigmodel.cn/api/anthropic | glm-4.6 |
| Qwen | ccenv qwen | https://dashscope.aliyuncs.com/compatible-mode/anthropic | qwen3-max |
| MiniMax | ccenv minimax | https://api.minimax.io/anthropic | MiniMax-M2 |
| LongCat | ccenv longcat | https://api.longcat.chat/anthropic | LongCat-Flash-Thinking |
PPINFRA Providers
All PPINFRA providers use https://api.ppinfra.com/anthropic as the base URL.
| Command | Model |
|---------|-------|
| ccenv pp deepseek | deepseek/deepseek-v3.2-exp |
| ccenv pp kimi | kimi-k2-turbo-preview |
| ccenv pp glm | zai-org/glm-4.6 |
| ccenv pp qwen | qwen3-next-80b-a3b-thinking |
| ccenv pp minimax | minimax/minimax-m2 |
How It Works
- The tool reads provider configurations from
src/base.json - When you run a command (e.g.,
ccenv deepseek), it:- Reads the current
~/.claude/settings.json - Converts provider-specific environment variables to Anthropic format:
DEEPSEEK_AUTH_TOKEN→ANTHROPIC_AUTH_TOKENDEEPSEEK_BASE_URL→ANTHROPIC_BASE_URLDEEPSEEK_MODEL→ANTHROPIC_MODELDEEPSEEK_SMALL_FAST_MODEL→ANTHROPIC_SMALL_FAST_MODEL
- Adds
API_TIMEOUT_MSset to 3000000 (3000 seconds) - Writes the updated configuration back to
~/.claude/settings.json
- Reads the current
- When you launch Claude Code, it reads these environment variables and uses the configured provider
Environment Variables Set
Each provider configuration sets the following environment variables in ~/.claude/settings.json:
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "your_api_key",
"ANTHROPIC_BASE_URL": "https://api.provider.com/anthropic",
"ANTHROPIC_MODEL": "model-name",
"ANTHROPIC_SMALL_FAST_MODEL": "fast-model-name",
"API_TIMEOUT_MS": "3000000"
}
}Development
# Run in development mode
npm run dev help
# Build the project
npm run build
# Run built version
npm start help
# Test the built CLI
node dist/index.js helpProject Structure
claude-code-env/
├── src/
│ ├── index.ts # Main CLI implementation
│ └── base.json # Provider configurations
├── dist/ # Compiled JavaScript (generated)
├── docs/
│ ├── docs.md # Implementation guide
│ └── sample.sh.txt # Reference configuration
├── package.json
├── tsconfig.json
└── README.mdEnvironment Variables Reference
The tool reads the following environment variables (provider-specific):
Regular Providers
DEEPSEEK_AUTH_TOKEN,DEEPSEEK_BASE_URL,DEEPSEEK_MODEL,DEEPSEEK_SMALL_FAST_MODELKIMI_AUTH_TOKEN,KIMI_BASE_URL,KIMI_MODEL,KIMI_SMALL_FAST_MODELGLM_AUTH_TOKEN,GLM_BASE_URL,GLM_MODEL,GLM_SMALL_FAST_MODELQWEN_AUTH_TOKEN,QWEN_BASE_URL,QWEN_MODEL,QWEN_SMALL_FAST_MODELMINIMAX_AUTH_TOKEN,MINIMAX_BASE_URL,MINIMAX_MODEL,MINIMAX_SMALL_FAST_MODELLONGCAT_AUTH_TOKEN,LONGCAT_BASE_URL,LONGCAT_MODEL,LONGCAT_SMALL_FAST_MODEL
PPINFRA Providers
PPINFRA_AUTH_TOKEN,PPINFRA_BASE_URLPPINFRA_DEEPSEEK_MODEL,PPINFRA_DEEPSEEK_SMALL_FAST_MODELPPINFRA_KIMI_MODEL,PPINFRA_KIMI_SMALL_FAST_MODELPPINFRA_GLM_MODEL,PPINFRA_GLM_SMALL_FAST_MODELPPINFRA_QWEN_MODEL,PPINFRA_QWEN_SMALL_FAST_MODELPPINFRA_MINIMAX_MODEL,PPINFRA_MINIMAX_SMALL_FAST_MODEL
Security
- API tokens can be stored in environment variables (recommended) or
src/base.json - Environment variables take priority over base.json for better security
- Token values are masked in console output (shows first 10 characters only)
- Configuration is stored locally in
~/.claude/settings.json - Add
src/base.jsonto.gitignoreto avoid committing secrets
Troubleshooting
Command not found: ccenv
Run npm link again in the project directory.
Settings not updating
- Check if
~/.claudedirectory exists - Verify you have write permissions to
~/.claude/settings.json - Try running with
sudoif on Linux/Mac
Provider not working
- Verify your API token is correctly set in
src/base.json - Rebuild the project:
npm run build - Check the base URL is correct for your provider
- Ensure Claude Code is restarted after switching providers
License
ISC
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
