claude-code-model-switch 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Claude Code Model Switch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # Claude Code Model Switch (CCMS)
2
+
3
+ A CLI tool for switching between different AI models in Claude Code.
4
+
5
+ ## 🚀 Features
6
+
7
+ - Quickly switch AI models used by Claude Code
8
+ - Support for multiple pre-configured model environments
9
+ - Automatic handling of model-related environment variables
10
+ - Simple command-line interface
11
+ - Secure configuration management - only modifies model-related settings
12
+ - Reset to official models with unset command
13
+
14
+ ## 📦 Installation
15
+
16
+ ```bash
17
+ npm install -g claude-code-model-switch
18
+ ```
19
+
20
+ ## 🛠️ Usage
21
+
22
+ ### Basic Commands
23
+
24
+ ```bash
25
+ # Switch to specified model
26
+ ccms deepseek-chat
27
+
28
+ # Or use switch subcommand
29
+ ccms switch deepseek-chat
30
+
31
+ # List all available models
32
+ ccms list
33
+
34
+ # Show configuration file paths
35
+ ccms config-path
36
+
37
+ # Remove all model-related configuration and use official models
38
+ ccms unset
39
+ ```
40
+
41
+ ### Model Configuration
42
+
43
+ Edit the configuration file `~/.claude-code-model-switch/settings.json`:
44
+
45
+ ```json
46
+ {
47
+ "models": {
48
+ "deepseek-chat": {
49
+ "ANTHROPIC_AUTH_TOKEN": "sk-your-token-here",
50
+ "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
51
+ "ANTHROPIC_MODEL": "deepseek-chat",
52
+ "ANTHROPIC_SMALL_FAST_MODEL": "deepseek-chat",
53
+ "ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-chat",
54
+ "ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-chat",
55
+ "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "8192",
56
+ "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
57
+ },
58
+ "claude-3-5-sonnet": {
59
+ "ANTHROPIC_AUTH_TOKEN": "your-anthropic-token-here",
60
+ "ANTHROPIC_BASE_URL": "https://api.anthropic.com",
61
+ "ANTHROPIC_MODEL": "claude-3-5-sonnet-20241022",
62
+ "ANTHROPIC_SMALL_FAST_MODEL": "claude-3-haiku-20240307",
63
+ "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-3-5-sonnet-20241022",
64
+ "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-3-opus-20240229",
65
+ "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "8192",
66
+ "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "0"
67
+ }
68
+ }
69
+ }
70
+ ```
71
+
72
+ ## ⚙️ Configuration
73
+
74
+ ### Environment Variables
75
+
76
+ | Variable | Required | Default | Description |
77
+ |----------|----------|---------|-------------|
78
+ | `ANTHROPIC_AUTH_TOKEN` | ✅ | - | API authentication token |
79
+ | `ANTHROPIC_BASE_URL` | ✅ | - | API base URL |
80
+ | `ANTHROPIC_MODEL` | ✅ | - | Main model name |
81
+ | `ANTHROPIC_SMALL_FAST_MODEL` | ❌ | Same as `ANTHROPIC_MODEL` | Small fast model |
82
+ | `ANTHROPIC_DEFAULT_SONNET_MODEL` | ❌ | Same as `ANTHROPIC_MODEL` | Default Sonnet model |
83
+ | `ANTHROPIC_DEFAULT_OPUS_MODEL` | ❌ | Same as `ANTHROPIC_MODEL` | Default Opus model |
84
+ | `CLAUDE_CODE_MAX_OUTPUT_TOKENS` | ❌ | `8192` | Maximum output tokens |
85
+ | `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` | ❌ | `1` | Disable non-essential traffic |
86
+
87
+ ### Special Rules
88
+
89
+ 1. **Secure Configuration**: The tool only modifies model-related environment variables and won't touch other fields in the configuration file
90
+ 2. **Default Values**:
91
+ - `CLAUDE_CODE_MAX_OUTPUT_TOKENS` defaults to `8192`
92
+ - `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` defaults to `1`
93
+ - Unset model fields automatically use the value of `ANTHROPIC_MODEL`
94
+ 3. **Configuration File**: Empty configuration file `{"models": {}}` is automatically created on first run
95
+ 4. **Unset Command**: The `ccms unset` command removes only model-specific variables while preserving `CLAUDE_CODE_MAX_OUTPUT_TOKENS` and `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`
96
+
97
+ ## 📁 File Locations
98
+
99
+ - Claude settings file: `~/.claude/settings.json`
100
+ - Model configuration file: `~/.claude-code-model-switch/settings.json`
101
+
102
+ ## 🔧 Development
103
+
104
+ ```bash
105
+ # Clone repository
106
+ git clone https://github.com/musnows/claude-code-model-switch.git
107
+ cd claude-code-model-switch
108
+
109
+ # Install dependencies
110
+ npm install
111
+
112
+ # Global link (for development)
113
+ npm link
114
+ ```
115
+
116
+ ## 📄 License
117
+
118
+ MIT License
119
+
120
+ ## 🤝 Contributing
121
+
122
+ Issues and Pull Requests are welcome!
123
+
124
+ ## 🔗 Repository
125
+
126
+ https://github.com/musnows/claude-code-model-switch
package/README_CN.md ADDED
@@ -0,0 +1,126 @@
1
+ # Claude Code Model Switch (CCMS)
2
+
3
+ 一个用于 Claude Code 的模型切换器,可以轻松在不同 AI 模型之间切换。
4
+
5
+ ## 🚀 功能特性
6
+
7
+ - 快速切换 Claude Code 使用的 AI 模型
8
+ - 支持多个预配置模型环境
9
+ - 自动处理模型相关环境变量
10
+ - 命令行界面,操作简单
11
+ - 安全的配置管理,只修改模型相关设置
12
+ - 使用 unset 命令重置为官方模型
13
+
14
+ ## 📦 安装
15
+
16
+ ```bash
17
+ npm install -g claude-code-model-switch
18
+ ```
19
+
20
+ ## 🛠️ 使用方法
21
+
22
+ ### 基本命令
23
+
24
+ ```bash
25
+ # 切换到指定模型
26
+ ccms deepseek-chat
27
+
28
+ # 或者使用 switch 子命令
29
+ ccms switch deepseek-chat
30
+
31
+ # 列出所有可用模型
32
+ ccms list
33
+
34
+ # 查看配置文件路径
35
+ ccms config-path
36
+
37
+ # 清除所有模型相关配置,恢复使用官方模型
38
+ ccms unset
39
+ ```
40
+
41
+ ### 配置模型
42
+
43
+ 编辑配置文件 `~/.claude-code-model-switch/settings.json`:
44
+
45
+ ```json
46
+ {
47
+ "models": {
48
+ "deepseek-chat": {
49
+ "ANTHROPIC_AUTH_TOKEN": "sk-your-token-here",
50
+ "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
51
+ "ANTHROPIC_MODEL": "deepseek-chat",
52
+ "ANTHROPIC_SMALL_FAST_MODEL": "deepseek-chat",
53
+ "ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-chat",
54
+ "ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-chat",
55
+ "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "8192",
56
+ "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
57
+ },
58
+ "claude-3-5-sonnet": {
59
+ "ANTHROPIC_AUTH_TOKEN": "your-anthropic-token-here",
60
+ "ANTHROPIC_BASE_URL": "https://api.anthropic.com",
61
+ "ANTHROPIC_MODEL": "claude-3-5-sonnet-20241022",
62
+ "ANTHROPIC_SMALL_FAST_MODEL": "claude-3-haiku-20240307",
63
+ "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-3-5-sonnet-20241022",
64
+ "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-3-opus-20240229",
65
+ "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "8192",
66
+ "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "0"
67
+ }
68
+ }
69
+ }
70
+ ```
71
+
72
+ ## ⚙️ 配置说明
73
+
74
+ ### 环境变量说明
75
+
76
+ | 变量名 | 必填 | 默认值 | 说明 |
77
+ |--------|------|--------|------|
78
+ | `ANTHROPIC_AUTH_TOKEN` | ✅ | - | API 认证令牌 |
79
+ | `ANTHROPIC_BASE_URL` | ✅ | - | API 基础 URL |
80
+ | `ANTHROPIC_MODEL` | ✅ | - | 主模型名称 |
81
+ | `ANTHROPIC_SMALL_FAST_MODEL` | ❌ | 同 `ANTHROPIC_MODEL` | 小型快速模型 |
82
+ | `ANTHROPIC_DEFAULT_SONNET_MODEL` | ❌ | 同 `ANTHROPIC_MODEL` | 默认 Sonnet 模型 |
83
+ | `ANTHROPIC_DEFAULT_OPUS_MODEL` | ❌ | 同 `ANTHROPIC_MODEL` | 默认 Opus 模型 |
84
+ | `CLAUDE_CODE_MAX_OUTPUT_TOKENS` | ❌ | `8192` | 最大输出令牌数 |
85
+ | `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` | ❌ | `1` | 禁用非必要流量 |
86
+
87
+ ### 特殊规则
88
+
89
+ 1. **安全配置**:工具只会修改与模型相关的环境变量,不会触及配置文件中的其他字段
90
+ 2. **默认值处理**:
91
+ - `CLAUDE_CODE_MAX_OUTPUT_TOKENS` 默认为 `8192`
92
+ - `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` 默认为 `1`
93
+ - 未设置的模型字段会自动使用 `ANTHROPIC_MODEL` 的值
94
+ 3. **配置文件**:首次运行时会自动创建空的配置文件 `{"models": {}}`
95
+ 4. **Unset 命令**:`ccms unset` 命令只删除模型特定的变量,同时保留 `CLAUDE_CODE_MAX_OUTPUT_TOKENS` 和 `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`
96
+
97
+ ## 📁 文件位置
98
+
99
+ - Claude 设置文件:`~/.claude/settings.json`
100
+ - 模型配置文件:`~/.claude-code-model-switch/settings.json`
101
+
102
+ ## 🔧 开发
103
+
104
+ ```bash
105
+ # 克隆仓库
106
+ git clone https://github.com/musnows/claude-code-model-switch.git
107
+ cd claude-code-model-switch
108
+
109
+ # 安装依赖
110
+ npm install
111
+
112
+ # 全局链接(开发用)
113
+ npm link
114
+ ```
115
+
116
+ ## 📄 许可证
117
+
118
+ MIT License
119
+
120
+ ## 🤝 贡献
121
+
122
+ 欢迎提交 Issue 和 Pull Request!
123
+
124
+ ## 🔗 开源地址
125
+
126
+ https://github.com/musnows/claude-code-model-switch
package/index.js CHANGED
@@ -73,6 +73,7 @@ function getModelConfig(modelName) {
73
73
  if (!config.models || !config.models[modelName]) {
74
74
  console.error(`Error: Model "${modelName}" not found`);
75
75
  console.log('Available models:', Object.keys(config.models || {}).join(', ') || 'None');
76
+ console.log('Run "ccms --help" to see available commands');
76
77
  process.exit(1);
77
78
  }
78
79
 
@@ -81,6 +82,7 @@ function getModelConfig(modelName) {
81
82
  // Check if model configuration is empty
82
83
  if (Object.keys(modelConfig).length === 0) {
83
84
  console.error(`Error: Model "${modelName}" configuration is empty`);
85
+ console.log('Run "ccms --help" to see available commands');
84
86
  process.exit(1);
85
87
  }
86
88
 
@@ -184,7 +186,7 @@ function isValidModel(modelName) {
184
186
  program
185
187
  .name('ccms')
186
188
  .description('Claude Code Model Switch - Switch Claude Code models')
187
- .version('1.0.0')
189
+ .version('1.0.2')
188
190
  .argument('[model]', 'Model name to switch to')
189
191
  .action((model) => {
190
192
  if (model) {
@@ -206,6 +208,7 @@ program
206
208
  config.models[name] && Object.keys(config.models[name]).length > 0
207
209
  );
208
210
  console.log('Available models:', validModels.join(', ') || 'None');
211
+ console.log('Run "ccms --help" to see available commands');
209
212
  process.exit(1);
210
213
  }
211
214
  } else {
@@ -229,12 +232,60 @@ program
229
232
  listModels();
230
233
  });
231
234
 
235
+ // Unset all model-related configuration
236
+ function unsetModelConfig() {
237
+ const settings = loadClaudeSettings();
238
+
239
+ // Ensure env object exists
240
+ if (!settings.env) {
241
+ settings.env = {};
242
+ }
243
+
244
+ // Model-related environment variables to remove (excluding some settings)
245
+ const modelEnvVars = [
246
+ 'ANTHROPIC_AUTH_TOKEN',
247
+ 'ANTHROPIC_BASE_URL',
248
+ 'ANTHROPIC_MODEL',
249
+ 'ANTHROPIC_SMALL_FAST_MODEL',
250
+ 'ANTHROPIC_DEFAULT_SONNET_MODEL',
251
+ 'ANTHROPIC_DEFAULT_OPUS_MODEL'
252
+ ];
253
+
254
+ let removedCount = 0;
255
+ const removedVars = [];
256
+
257
+ // Remove only existing model-related environment variables
258
+ for (const key of modelEnvVars) {
259
+ if (settings.env.hasOwnProperty(key)) {
260
+ delete settings.env[key];
261
+ removedCount++;
262
+ removedVars.push(key);
263
+ }
264
+ }
265
+
266
+ saveClaudeSettings(settings);
267
+
268
+ if (removedCount > 0) {
269
+ console.log(`Removed ${removedCount} model-related configurations: ${removedVars.join(', ')}`);
270
+ console.log('Restored to use claude official models');
271
+ } else {
272
+ console.log('No model-related configurations found to remove');
273
+ }
274
+ }
275
+
232
276
  program
233
277
  .command('config-path')
234
278
  .description('Display configuration file paths')
235
279
  .action(() => {
236
280
  console.log('Model configuration file path:', MODEL_CONFIG_PATH);
237
- console.log('Claude settings file path:', CLAUDE_SETTINGS_PATH);
281
+ console.log('Claude Code settings file path:', CLAUDE_SETTINGS_PATH);
282
+ });
283
+
284
+ program
285
+ .command('unset')
286
+ .description('Remove all model-related configuration and use official models')
287
+ .action(() => {
288
+ unsetModelConfig();
238
289
  });
239
290
 
240
291
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-model-switch",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A CLI tool to switch Claude Code models",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -9,10 +9,15 @@
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1"
11
11
  },
12
- "keywords": ["claude", "code", "model", "switch"],
12
+ "keywords": [
13
+ "claude",
14
+ "code",
15
+ "model",
16
+ "switch"
17
+ ],
13
18
  "author": "",
14
19
  "license": "MIT",
15
20
  "dependencies": {
16
21
  "commander": "^11.1.0"
17
22
  }
18
- }
23
+ }