cc-switch
快速切换 Claude Code API 提供商的 TUI 工具
当 token 额度用尽时,可以快速切换到另一个提供商/token。
功能特性
- 🔄 快速切换 - 1-2 秒内完成提供商切换
- 🎨 交互式选择 - 支持模糊搜索的友好界面
- 🔒 自动备份 - 每次切换前自动备份配置
- 📦 可扩展 - 预留 MCP、技能、插件切换接口
- 🌍 多提供商 - 支持任意兼容 Anthropic API 的提供商
安装
全局安装
npm install -g @supertiny99/cc-switch
本地开发
git clone <repo-url>
cd cc-switch
npm install
npm link
快速开始
1. 查看当前配置
cc-switch current
输出:
Current Configuration:
Provider: zhipu
Base URL: https://open.bigmodel.cn/api/anthropic
Haiku Model: GLM-4.5-Air
Sonnet Model: GLM-4.7
Opus Model: GLM-4.7
2. 列出所有提供商
cc-switch list
3. 交互式切换
cc-switch
输入 zh 即可快速定位到 "Zhipu AI",按 Enter 确认。
4. 直接切换
cc-switch use anthropic
配置文件
提供商配置文件位于 ~/.claude/profiles/:
~/.claude/
├── settings.json # Claude Code 当前配置
├── profiles/ # 提供商配置目录
│ ├── zhipu.json # 智谱 AI (GLM)
│ ├── anthropic.json # Anthropic 官方
│ └── custom.json # 自定义提供商
└── cc-switch-backups/ # 自动备份目录
创建自定义提供商
在 ~/.claude/profiles/ 创建 JSON 文件:
{
"id": "my-provider",
"name": "我的提供商",
"description": "自定义 API 提供商",
"icon": "🚀",
"config": {
"env": {
"ANTHROPIC_AUTH_TOKEN": "your_token_here",
"ANTHROPIC_BASE_URL": "https://your-api-endpoint.com",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "model-name",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "model-name",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "model-name"
}
}
}
命令参考
cc-switch | 交互式选择提供商 |
cc-switch use <id> | 直接切换到指定提供商 |
cc-switch list | 列出所有可用提供商 |
cc-switch current | 显示当前配置 |
cc-switch history | 查看备份历史 |
cc-switch restore <file> | 从备份恢复 |
开发
项目结构
cc-switch/
├── src/
│ ├── index.ts # CLI 入口
│ ├── lib/
│ │ └── config/
│ │ ├── schema.ts # 类型定义
│ │ ├── loader.ts # 配置读取
│ │ └── writer.ts # 配置写入(含备份)
│ └── ui/
│ └── quick-select.ts # 交互式选择
├── package.json
├── tsconfig.json
└── README.md
开发命令
npm install
npm run dev list
npm run build
npm link
cc-switch list
npm test
添加新功能
- 新增 CLI 命令 - 在
src/index.ts 添加:
program
.command('my-command')
.description('我的命令')
.action(async () => {
});
测试
手动测试清单
cc-switch list
cc-switch current
cc-switch use anthropic
cc-switch current
cc-switch history
cc-switch restore settings-2025-01-29T14-30-22-123Z.json
cc-switch
单元测试(待实现)
npm test
发布到 npm
1. 准备发布
npm run build
cat package.json
2. npm 账号设置
npm login
npm token create
npm logout
npm login --registry=https://registry.npmjs.org --auth-only
3. 检查包名是否可用
npm search @supertiny99/cc-switch
4. 发布流程
npm version patch
npm version minor
npm version major
npm publish
npm view @supertiny99/cc-switch
5. 发布选项
npm publish
npm publish --access public
npm publish --dry-run
npm publish --tag beta
6. 发布后验证
npm install -g @supertiny99/cc-switch
npx @supertiny99/cc-switch list
发布检查清单
故障排除
命令未找到
npm link
which cc-switch
配置文件错误
cc-switch history
cc-switch restore <backup-file>
权限问题
sudo npm link
兼容性
- Node.js >= 16.0.0
- macOS, Linux, Windows
许可证
MIT
贡献
欢迎提交 Issue 和 Pull Request!
路线图
相关链接