@jigonr/claude-switch
v0.1.0
Published
Simple API provider switcher for Claude Code CLI
Maintainers
Readme
claude-switch
Simple API provider switcher for Claude Code CLI
A lightweight, secure CLI tool to seamlessly switch between different API providers for Claude Code: Claude Pro subscription, Anthropic API, and z.ai (GLM models).
Built for Claude Code CLI
Features
- 🔄 Simple Provider Switching - Switch between 3 providers with one command
- 🔒 Security First - Separate credential storage with proper permissions
- 📁 Project-Aware - Auto-detects project-specific configs
- ⚡ Fast - Built with Bun and TypeScript for optimal performance
- 🛡️ Type-Safe - Zod schema validation for all configurations
- 📦 Zero Config - Works out of the box with sensible defaults
Supported Providers
| Provider | Type | Description | |----------|------|-------------| | claude-pro-max | Subscription | Claude Pro via browser authentication | | anthropic | API | Official Anthropic API | | z.ai | API | z.ai API with GLM models |
Installation
# Using npm
npm install -g @jigonr/claude-switch
# Using bun
bun add -g @jigonr/claude-switch
# Using yarn
yarn global add @jigonr/claude-switchQuick Start
# Show current provider
claude-switch
# Switch to a provider
claude-switch claude-pro-max
claude-switch anthropic
claude-switch z.ai
# List all available providers
claude-switch list
# Show detailed status
claude-switch status
# Import from bash script configuration
claude-switch import-bashUsage
Basic Commands
Switch Provider
# Switch to Claude Pro subscription
claude-switch claude-pro-max
# Switch to Anthropic API
claude-switch anthropic
# Switch to z.ai (GLM models)
claude-switch z.aiList Providers
claude-switch listOutput:
Available Providers:
● claude-pro-max
Claude Pro subscription (browser-based)
Type: subscription
○ anthropic
Anthropic official API
Type: api
○ z.ai
z.ai API (GLM models)
Type: api
Current: claude-pro-maxShow Status
claude-switch statusOutput:
Current Provider:
claude-pro-max
Claude Pro subscription (browser-based)
Type: subscriptionAdvanced Usage
Project-Specific Configuration
Create a .claude-switch.json file in your project root:
{
"provider": "z.ai",
"inherits": "~/.claude/switch-config.json"
}claude-switch will automatically detect and use this configuration when run from within the project directory.
Import from Bash Script
If you're migrating from the bash version of claude-switch:
claude-switch import-bashThis will:
- Import your
~/.claude/glm-config.jsonsettings - Extract and securely store your z.ai API key
- Create the new configuration format
- Preserve your model preferences
Configuration
Global Configuration
Location: ~/.claude/switch-config.json
{
"version": "1.0",
"currentProvider": "claude-pro-max",
"providers": {
"claude-pro-max": {
"type": "subscription",
"description": "Claude Pro subscription (browser-based)",
"settings": {
"env": {
"API_TIMEOUT_MS": "3000000"
}
}
},
"anthropic": {
"type": "api",
"description": "Anthropic official API",
"settings": {
"env": {
"ANTHROPIC_API_KEY_FILE": "~/.claude/credentials/anthropic.key",
"API_TIMEOUT_MS": "3000000"
}
}
},
"z.ai": {
"type": "api",
"description": "z.ai API (GLM models)",
"settings": {
"env": {
"ANTHROPIC_API_KEY_FILE": "~/.claude/credentials/zai.key",
"API_TIMEOUT_MS": "3000000",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air"
}
}
}
}
}Credential Storage
API keys are stored separately from configuration:
~/.claude/credentials/
├── anthropic.key (chmod 600)
└── zai.key (chmod 600)Security Note: Never commit credential files to version control!
Security
API Key Storage
❌ BAD - Don't store API keys in config files:
{
"provider": "anthropic",
"apiKey": "sk-ant-..." // NEVER DO THIS
}✅ GOOD - Store keys in separate files:
# Create credentials directory
mkdir -p ~/.claude/credentials
# Store API key securely
echo "your-api-key-here" > ~/.claude/credentials/anthropic.key
chmod 600 ~/.claude/credentials/anthropic.keyFile Permissions
Ensure proper permissions on credential files:
chmod 600 ~/.claude/credentials/*.keyProject Configurations
Never commit project-specific configs with sensitive data:
# Add to .gitignore
echo ".claude-switch.json" >> .gitignoreDevelopment
Prerequisites
- Node.js ≥ 18.0.0
- Bun ≥ 1.0.0 (recommended) or npm
Setup
# Clone the repository
git clone https://github.com/jigonr/claude-switch.git
cd claude-switch
# Install dependencies
bun install
# Build
bun run build
# Run tests
bun run test
# Lint
bun run lint
# Type check
bun run typecheckProject Structure
claude-switch/
├── src/
│ ├── commands/ # CLI commands
│ │ ├── switch.ts # Provider switching logic
│ │ ├── list.ts # List providers
│ │ └── import.ts # Import from bash
│ ├── config/ # Configuration management
│ │ ├── schema.ts # Zod schemas
│ │ ├── manager.ts # Config I/O
│ │ └── detector.ts # Project config detection
│ ├── providers/ # Provider type definitions
│ ├── utils/ # Utilities (logger, errors)
│ └── index.ts # CLI entry point
├── tests/
│ ├── integration/ # Integration tests
│ └── unit/ # Unit tests
└── dist/ # Built outputRunning Tests
# Run all tests
bun run test
# Run with coverage
bun run test:coverage
# Watch mode
bun run test:watchTroubleshooting
Provider switch doesn't take effect
Make sure you're switching before launching Claude Code:
claude-switch anthropic
claude # Now launches with Anthropic APIAPI key not found
Verify your API key is stored correctly:
# Check file exists and has correct permissions
ls -la ~/.claude/credentials/
# Should show:
# -rw------- 1 user user ... anthropic.key
# -rw------- 1 user user ... zai.keyConfig validation errors
Reset to default configuration:
# Backup current config
mv ~/.claude/switch-config.json ~/.claude/switch-config.json.bak
# Let claude-switch create a new default
claude-switch listContributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
Development Workflow
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
bun run test) - Run linter (
bun run lint:fix) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT © J.I. Gonzalez-Rojas
Acknowledgments
- Built with Bun
- CLI framework: Commander.js
- Validation: Zod
- Linting: Biome
Roadmap
- [ ] Interactive TUI with Ink
- [ ] Shell completion (bash, zsh, fish)
- [ ] Validation command for credentials
- [ ] Doctor command for diagnostics
- [ ] Support for custom providers
- [ ] Configuration profiles management
Related Projects
- letta-switch - Comprehensive configuration manager for Letta CLI (agents + models + memory blocks)
Made with ❤️ for the Claude Code community
