claude-code-model-switch 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -9,6 +9,7 @@ A CLI tool for switching between different AI models in Claude Code.
9
9
  - Automatic handling of model-related environment variables
10
10
  - Simple command-line interface
11
11
  - Secure configuration management - only modifies model-related settings
12
+ - Reset to official models with unset command
12
13
 
13
14
  ## 📦 Installation
14
15
 
@@ -32,6 +33,9 @@ ccms list
32
33
 
33
34
  # Show configuration file paths
34
35
  ccms config-path
36
+
37
+ # Remove all model-related configuration and use official models
38
+ ccms unset
35
39
  ```
36
40
 
37
41
  ### Model Configuration
@@ -88,6 +92,7 @@ Edit the configuration file `~/.claude-code-model-switch/settings.json`:
88
92
  - `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` defaults to `1`
89
93
  - Unset model fields automatically use the value of `ANTHROPIC_MODEL`
90
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`
91
96
 
92
97
  ## 📁 File Locations
93
98
 
package/README_CN.md CHANGED
@@ -9,6 +9,7 @@
9
9
  - 自动处理模型相关环境变量
10
10
  - 命令行界面,操作简单
11
11
  - 安全的配置管理,只修改模型相关设置
12
+ - 使用 unset 命令重置为官方模型
12
13
 
13
14
  ## 📦 安装
14
15
 
@@ -32,6 +33,9 @@ ccms list
32
33
 
33
34
  # 查看配置文件路径
34
35
  ccms config-path
36
+
37
+ # 清除所有模型相关配置,恢复使用官方模型
38
+ ccms unset
35
39
  ```
36
40
 
37
41
  ### 配置模型
@@ -88,6 +92,7 @@ ccms config-path
88
92
  - `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` 默认为 `1`
89
93
  - 未设置的模型字段会自动使用 `ANTHROPIC_MODEL` 的值
90
94
  3. **配置文件**:首次运行时会自动创建空的配置文件 `{"models": {}}`
95
+ 4. **Unset 命令**:`ccms unset` 命令只删除模型特定的变量,同时保留 `CLAUDE_CODE_MAX_OUTPUT_TOKENS` 和 `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`
91
96
 
92
97
  ## 📁 文件位置
93
98
 
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
 
@@ -96,6 +98,22 @@ function applyModelConfig(modelConfig) {
96
98
  settings.env = {};
97
99
  }
98
100
 
101
+ // First, set default values for unset model fields in the config itself
102
+ // If ANTHROPIC_MODEL is set but other model fields are not, use ANTHROPIC_MODEL value
103
+ if (modelConfig.ANTHROPIC_MODEL) {
104
+ const derivedModelFields = [
105
+ 'ANTHROPIC_SMALL_FAST_MODEL',
106
+ 'ANTHROPIC_DEFAULT_SONNET_MODEL',
107
+ 'ANTHROPIC_DEFAULT_OPUS_MODEL'
108
+ ];
109
+
110
+ for (const field of derivedModelFields) {
111
+ if (!modelConfig[field]) {
112
+ modelConfig[field] = modelConfig.ANTHROPIC_MODEL;
113
+ }
114
+ }
115
+ }
116
+
99
117
  // Only update model-related environment variables
100
118
  const modelEnvVars = [
101
119
  'ANTHROPIC_AUTH_TOKEN',
@@ -130,19 +148,7 @@ function applyModelConfig(modelConfig) {
130
148
  }
131
149
  }
132
150
 
133
- // If other model fields are not set, use ANTHROPIC_MODEL value
134
- const derivedModelFields = [
135
- 'ANTHROPIC_SMALL_FAST_MODEL',
136
- 'ANTHROPIC_DEFAULT_SONNET_MODEL',
137
- 'ANTHROPIC_DEFAULT_OPUS_MODEL'
138
- ];
139
-
140
- for (const field of derivedModelFields) {
141
- if (!settings.env[field]) {
142
- settings.env[field] = settings.env.ANTHROPIC_MODEL;
143
- }
144
- }
145
-
151
+
146
152
  // Handle special environment variable defaults
147
153
  if (!settings.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS) {
148
154
  settings.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS = DEFAULT_MAX_OUTPUT_TOKENS;
@@ -184,7 +190,7 @@ function isValidModel(modelName) {
184
190
  program
185
191
  .name('ccms')
186
192
  .description('Claude Code Model Switch - Switch Claude Code models')
187
- .version('1.0.0')
193
+ .version('1.0.3')
188
194
  .argument('[model]', 'Model name to switch to')
189
195
  .action((model) => {
190
196
  if (model) {
@@ -206,6 +212,7 @@ program
206
212
  config.models[name] && Object.keys(config.models[name]).length > 0
207
213
  );
208
214
  console.log('Available models:', validModels.join(', ') || 'None');
215
+ console.log('Run "ccms --help" to see available commands');
209
216
  process.exit(1);
210
217
  }
211
218
  } else {
@@ -229,12 +236,60 @@ program
229
236
  listModels();
230
237
  });
231
238
 
239
+ // Unset all model-related configuration
240
+ function unsetModelConfig() {
241
+ const settings = loadClaudeSettings();
242
+
243
+ // Ensure env object exists
244
+ if (!settings.env) {
245
+ settings.env = {};
246
+ }
247
+
248
+ // Model-related environment variables to remove (excluding some settings)
249
+ const modelEnvVars = [
250
+ 'ANTHROPIC_AUTH_TOKEN',
251
+ 'ANTHROPIC_BASE_URL',
252
+ 'ANTHROPIC_MODEL',
253
+ 'ANTHROPIC_SMALL_FAST_MODEL',
254
+ 'ANTHROPIC_DEFAULT_SONNET_MODEL',
255
+ 'ANTHROPIC_DEFAULT_OPUS_MODEL'
256
+ ];
257
+
258
+ let removedCount = 0;
259
+ const removedVars = [];
260
+
261
+ // Remove only existing model-related environment variables
262
+ for (const key of modelEnvVars) {
263
+ if (settings.env.hasOwnProperty(key)) {
264
+ delete settings.env[key];
265
+ removedCount++;
266
+ removedVars.push(key);
267
+ }
268
+ }
269
+
270
+ saveClaudeSettings(settings);
271
+
272
+ if (removedCount > 0) {
273
+ console.log(`Removed ${removedCount} model-related configurations: ${removedVars.join(', ')}`);
274
+ console.log('Restored to use claude official models');
275
+ } else {
276
+ console.log('No model-related configurations found to remove');
277
+ }
278
+ }
279
+
232
280
  program
233
281
  .command('config-path')
234
282
  .description('Display configuration file paths')
235
283
  .action(() => {
236
284
  console.log('Model configuration file path:', MODEL_CONFIG_PATH);
237
- console.log('Claude settings file path:', CLAUDE_SETTINGS_PATH);
285
+ console.log('Claude Code settings file path:', CLAUDE_SETTINGS_PATH);
286
+ });
287
+
288
+ program
289
+ .command('unset')
290
+ .description('Remove all model-related configuration and use official models')
291
+ .action(() => {
292
+ unsetModelConfig();
238
293
  });
239
294
 
240
295
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-model-switch",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A CLI tool to switch Claude Code models",
5
5
  "main": "index.js",
6
6
  "bin": {
package/prompt.md DELETED
@@ -1,45 +0,0 @@
1
- 我需要实现一个claude code的模型切换器,这个切换器用node.js实现,可以通过npm安装.
2
-
3
- 实现逻辑非常简单.读取`~/.claude/settings.json`,切换里面和模型有关的环境变量。除了这些env,禁止修改配置文件的任何其他字段。
4
-
5
- ```json
6
- {
7
- "env": {
8
- "ANTHROPIC_AUTH_TOKEN": "sk-caf695360e7f4b018bb1b308cbf992eb",
9
- "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
10
- "ANTHROPIC_MODEL": "deepseek-chat",
11
- "ANTHROPIC_SMALL_FAST_MODEL": "deepseek-chat",
12
- "ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-chat",
13
- "ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-chat",
14
- "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "8192",
15
- "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
16
- }
17
- }
18
- ```
19
-
20
- 这个工具本身通过~/.claude-code-models.json配置多个模型,格式为
21
-
22
- ```json
23
- {
24
- "models":{
25
- "模型名称":{
26
- "ANTHROPIC_AUTH_TOKEN": "sk-caf695360e7f4b018bb1b308cbf992eb",
27
- "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
28
- "ANTHROPIC_MODEL": "deepseek-chat",
29
- "ANTHROPIC_SMALL_FAST_MODEL": "deepseek-chat",
30
- "ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-chat",
31
- "ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-chat",
32
- "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "8192",
33
- "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
34
- }
35
- }
36
- }
37
- ```
38
-
39
- 当用户执行`ccms 模型`命令时,读取`~/.claude-code-model-swich/settings.json`文件,检查是否有这个模型名称,没有报错,有就进行`~/.claude/settings.json`替换
40
-
41
- 重点:
42
- 1. `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`是一个特殊的环境变量,当用户没有设置这个环境变量时,**默认为1**,当用户设置为0时,表示允许非必要的流量,对应修改成0
43
- 2. `CLAUDE_CODE_MAX_OUTPUT_TOKENS`用户没有设置的时候,默认为8192
44
- 3. ANTHROPIC_SMALL_FAST_MODEL、ANTHROPIC_DEFAULT_SONNET_MODEL、ANTHROPIC_DEFAULT_OPUS_MODEL都可以不设置,只有ANTHROPIC_MODEL是必填的,其余三个环境变量在没有设置的时候,沿用ANTHROPIC_MODEL的值。
45
- 4. `~/.claude-code-model-swich/settings.json`文件不存在的时候,创建一个空的默认配置文件`{"models": {}}`,并按照模型不存在的错误提示用户(认为加载了这个空配置文件)