ccconfig 1.2.0 → 1.4.0

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) 2025 Daniel
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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # Claude Code Configuration Manager
2
2
 
3
+ [English](README.md) | [中文](README_zh.md)
4
+
3
5
  Quickly switch between different claude-code providers
4
6
 
5
7
 
@@ -35,7 +37,8 @@ ccconfig add
35
37
  # - ANTHROPIC_BASE_URL
36
38
  # - ANTHROPIC_AUTH_TOKEN
37
39
  # - ANTHROPIC_API_KEY
38
- # - Description
40
+ # - ANTHROPIC_MODEL (optional)
41
+ # - ANTHROPIC_SMALL_FAST_MODEL (optional)
39
42
 
40
43
  # 3. Switch configuration
41
44
  ccconfig use work
@@ -72,7 +75,8 @@ ccconfig add
72
75
  # - ANTHROPIC_BASE_URL
73
76
  # - ANTHROPIC_AUTH_TOKEN
74
77
  # - ANTHROPIC_API_KEY
75
- # - Description
78
+ # - ANTHROPIC_MODEL (optional)
79
+ # - ANTHROPIC_SMALL_FAST_MODEL (optional)
76
80
 
77
81
  # 3. Switch configuration
78
82
  ccconfig use work
@@ -179,6 +183,91 @@ if (Test-Path $cconfigEnv) {
179
183
 
180
184
  ## Advanced Usage
181
185
 
186
+ ### Update Existing Configuration
187
+
188
+ If you need to modify an existing configuration, use the `update` command:
189
+
190
+ ```bash
191
+ # Update a configuration interactively
192
+ ccconfig update work
193
+
194
+ # The tool will:
195
+ # 1. Show current values as defaults
196
+ # 2. Prompt for each field
197
+ # 3. Press Enter to keep current value, or type new value to update
198
+ ```
199
+
200
+ **Example:**
201
+ ```bash
202
+ $ ccconfig update work
203
+ Updating configuration 'work'
204
+ Press Enter to keep the current value, or enter a new value to update
205
+
206
+ ANTHROPIC_BASE_URL [https://api.company.com]: https://new-api.company.com
207
+ ANTHROPIC_AUTH_TOKEN [sk-ant-api...]: <press Enter to keep>
208
+ ANTHROPIC_API_KEY []: sk-new-key-123
209
+ ANTHROPIC_MODEL [claude-sonnet-4-5-20250929]: <press Enter to keep>
210
+ Do you want to set ANTHROPIC_SMALL_FAST_MODEL? (y/N) [n]:
211
+
212
+ ✓ Configuration 'work' updated
213
+ ```
214
+
215
+ **Note:** After updating a configuration, remember to activate it with `ccconfig use work` if you want the changes to take effect immediately.
216
+
217
+ ### Shell Completion
218
+
219
+ ccconfig supports shell completion for commands, profile names, and options. This makes it easier to discover and use commands.
220
+
221
+ **Features:**
222
+ - ✅ Command completion (list, add, update, use, remove, etc.)
223
+ - ✅ Profile name completion (dynamically reads from your configurations)
224
+ - ✅ Option completion (--permanent, --show-secret, etc.)
225
+ - ✅ Mode completion (settings, env)
226
+ - ✅ Format completion (bash, zsh, fish, etc.)
227
+
228
+ **Installation:**
229
+
230
+ ```bash
231
+ # Bash
232
+ ccconfig completion bash >> ~/.bashrc
233
+ source ~/.bashrc
234
+
235
+ # Zsh
236
+ ccconfig completion zsh >> ~/.zshrc
237
+ source ~/.zshrc
238
+
239
+ # Fish
240
+ ccconfig completion fish > ~/.config/fish/completions/ccconfig.fish
241
+ # Fish will automatically load it on next startup
242
+
243
+ # PowerShell
244
+ ccconfig completion pwsh >> $PROFILE
245
+ # Reload profile: . $PROFILE
246
+ ```
247
+
248
+ **Note for PowerShell:** If you get an error about `$PROFILE` not existing, create it first:
249
+ ```powershell
250
+ New-Item -Path $PROFILE -ItemType File -Force
251
+ ccconfig completion pwsh >> $PROFILE
252
+ . $PROFILE
253
+ ```
254
+
255
+ **Usage examples after installing completion:**
256
+
257
+ ```bash
258
+ # Type 'ccconfig' and press TAB to see all commands
259
+ ccconfig <TAB>
260
+ # Shows: list, add, update, use, remove, current, mode, env, edit, completion
261
+
262
+ # Type 'ccconfig use' and press TAB to see all profiles
263
+ ccconfig use <TAB>
264
+ # Shows: work, personal, project1, etc.
265
+
266
+ # Type 'ccconfig mode' and press TAB
267
+ ccconfig mode <TAB>
268
+ # Shows: settings, env
269
+ ```
270
+
182
271
  ### Quick Aliases
183
272
 
184
273
  ```bash
package/README_zh.md ADDED
@@ -0,0 +1,406 @@
1
+ # Claude Code 配置管理器
2
+
3
+ [English](README.md) | [中文](README_zh.md)
4
+
5
+ 快速切换不同的 claude-code 提供商配置
6
+
7
+ ```bash
8
+ # 工作时间切换到公司配置
9
+ ccconfig use company
10
+
11
+ # 下班后切换回个人配置
12
+ ccconfig use personal
13
+
14
+ # 永久写入 shell 配置文件(无需每次 eval 或 source)
15
+ ccconfig use personal --permanent # 或使用 -p 简写
16
+ ```
17
+
18
+ ## 快速开始
19
+
20
+ ### 安装
21
+
22
+ ```bash
23
+ # 从 npm 安装(推荐)
24
+ npm install -g ccconfig
25
+ ```
26
+
27
+ ### ENV 模式(推荐,默认)
28
+
29
+ ```bash
30
+ # 1. 配置 Shell 自动加载(见下文)
31
+
32
+ # 2. 添加配置(交互模式)
33
+ ccconfig add
34
+ # 按提示输入:
35
+ # - 名称
36
+ # - ANTHROPIC_BASE_URL
37
+ # - ANTHROPIC_AUTH_TOKEN
38
+ # - ANTHROPIC_API_KEY
39
+ # - ANTHROPIC_MODEL(可选)
40
+ # - ANTHROPIC_SMALL_FAST_MODEL(可选)
41
+
42
+ # 3. 切换配置
43
+ ccconfig use work
44
+
45
+ # 4. 立即生效(选择一种方法):
46
+ # 方法 A: 临时生效(仅当前 shell)
47
+ eval $(ccconfig env bash) # 或使用输出中检测到的命令
48
+
49
+ # 方法 B: 永久生效(写入 shell 配置文件)
50
+ ccconfig use work --permanent # 或使用 -p 简写
51
+ # 自动检测并修改 ~/.bashrc、~/.zshrc 或 config.fish
52
+ ```
53
+
54
+ ### Settings 模式
55
+
56
+ Settings 模式直接修改 `~/.claude/settings.json` 文件,这是 Claude Code 的原生配置文件。此模式适合不想配置 shell 脚本的情况。
57
+
58
+ **工作原理:**
59
+ - 直接将环境变量写入 `~/.claude/settings.json` 的 `env` 字段
60
+ - Claude Code 启动时读取这些设置
61
+ - 无需 shell 配置
62
+ - 每次切换后需要重启 Claude Code
63
+
64
+ **设置步骤:**
65
+
66
+ ```bash
67
+ # 1. 切换到 settings 模式
68
+ ccconfig mode settings
69
+
70
+ # 2. 添加配置(交互模式)
71
+ ccconfig add
72
+ # 按提示输入:
73
+ # - 名称
74
+ # - ANTHROPIC_BASE_URL
75
+ # - ANTHROPIC_AUTH_TOKEN
76
+ # - ANTHROPIC_API_KEY
77
+ # - ANTHROPIC_MODEL(可选)
78
+ # - ANTHROPIC_SMALL_FAST_MODEL(可选)
79
+
80
+ # 3. 切换配置
81
+ ccconfig use work
82
+
83
+ # 4. 重启 Claude Code
84
+ # 配置现已生效!
85
+ ```
86
+
87
+ **验证:**
88
+ ```bash
89
+ # 查看当前配置
90
+ ccconfig current
91
+
92
+ # 直接查看 settings 文件
93
+ cat ~/.claude/settings.json
94
+ ```
95
+
96
+ #### ENV 模式 Shell 配置
97
+
98
+ 您有两种方式配置 shell 环境:
99
+
100
+ **方式 1: 自动配置(推荐)**
101
+
102
+ 使用 `-p/--permanent` 标志自动写入您的 shell 配置:
103
+
104
+ ```bash
105
+ # 自动检测您的 shell 并写入相应的配置文件
106
+ ccconfig use <profile> --permanent
107
+
108
+ # 您将看到:
109
+ # - 修改 shell 配置的警告
110
+ # - 目标文件路径
111
+ # - 内容预览
112
+ # - 确认提示(yes/no)
113
+
114
+ # 这将修改:
115
+ # - Fish: ~/.config/fish/config.fish
116
+ # - Bash: ~/.bashrc
117
+ # - Zsh: ~/.zshrc
118
+ # - PowerShell: ~/.config/powershell/profile.ps1
119
+ ```
120
+
121
+ 工具会在 `# >>> ccconfig >>>` 和 `# <<< ccconfig <<<` 标记之间添加一个标记块,便于后续识别和更新。
122
+
123
+ **安全特性:**
124
+ - **需要用户确认**: 修改文件前会提示确认
125
+ - **内容预览**: 显示将要写入的确切内容
126
+ - **清晰说明**: 解释将要进行的更改
127
+ - **非破坏性**: 保留现有内容,仅更新 ccconfig 块
128
+ - **仅交互模式**: 需要交互式终端以防止意外修改
129
+
130
+ **方式 2: 手动配置**
131
+
132
+ 如果您喜欢手动配置,请将以下内容添加到您的 shell 启动文件:
133
+
134
+ **Fish** (`~/.config/fish/config.fish`):
135
+ ```fish
136
+ # 加载 Claude Code 环境变量
137
+ set -l ccconfig_env ~/.config/ccconfig/current.env
138
+ if test -f $ccconfig_env
139
+ for line in (cat $ccconfig_env)
140
+ set -l parts (string split -m1 '=' $line)
141
+ if test (count $parts) -eq 2
142
+ set -gx $parts[1] $parts[2]
143
+ end
144
+ end
145
+ end
146
+ ```
147
+
148
+ **Bash** (`~/.bashrc`):
149
+ ```bash
150
+ # 加载 Claude Code 环境变量
151
+ if [ -f ~/.config/ccconfig/current.env ]; then
152
+ set -a
153
+ . ~/.config/ccconfig/current.env
154
+ set +a
155
+ fi
156
+ ```
157
+
158
+ **Zsh** (`~/.zshrc`):
159
+ ```zsh
160
+ # 加载 Claude Code 环境变量
161
+ if [ -f ~/.config/ccconfig/current.env ]; then
162
+ set -a
163
+ . ~/.config/ccconfig/current.env
164
+ set +a
165
+ fi
166
+ ```
167
+
168
+ **PowerShell** (`$PROFILE`):
169
+ ```powershell
170
+ # 加载 Claude Code 环境变量
171
+ $cconfigEnv = "$env:USERPROFILE\.config\ccconfig\current.env"
172
+ if (Test-Path $cconfigEnv) {
173
+ Get-Content $cconfigEnv | ForEach-Object {
174
+ if ($_ -match '^([^=]+)=(.*)$') {
175
+ [Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process')
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+ **注意**: 手动配置允许您通过更改 `current.env` 动态切换配置文件,而 `-p/--permanent` 直接将值写入 shell 配置文件。
182
+
183
+ ## 高级用法
184
+
185
+ ### 更新现有配置
186
+
187
+ 如果您需要修改已有配置,使用 `update` 命令:
188
+
189
+ ```bash
190
+ # 交互式更新配置
191
+ ccconfig update work
192
+
193
+ # 工具会:
194
+ # 1. 显示当前值作为默认值
195
+ # 2. 提示输入每个字段
196
+ # 3. 按 Enter 保持当前值,或输入新值来更新
197
+ ```
198
+
199
+ **示例:**
200
+ ```bash
201
+ $ ccconfig update work
202
+ Updating configuration 'work'
203
+ Press Enter to keep the current value, or enter a new value to update
204
+
205
+ ANTHROPIC_BASE_URL [https://api.company.com]: https://new-api.company.com
206
+ ANTHROPIC_AUTH_TOKEN [sk-ant-api...]: <按 Enter 保持不变>
207
+ ANTHROPIC_API_KEY []: sk-new-key-123
208
+ ANTHROPIC_MODEL [claude-sonnet-4-5-20250929]: <按 Enter 保持不变>
209
+ Do you want to set ANTHROPIC_SMALL_FAST_MODEL? (y/N) [n]:
210
+
211
+ ✓ Configuration 'work' updated
212
+ ```
213
+
214
+ **注意:** 更新配置后,如果要立即生效,记得使用 `ccconfig use work` 激活配置。
215
+
216
+ ### Shell 自动补全
217
+
218
+ ccconfig 支持命令、配置名称和选项的 shell 自动补全,让您更容易发现和使用命令。
219
+
220
+ **功能:**
221
+ - ✅ 命令补全 (list, add, update, use, remove 等)
222
+ - ✅ 配置名称补全(动态读取您的配置)
223
+ - ✅ 选项补全 (--permanent, --show-secret 等)
224
+ - ✅ 模式补全 (settings, env)
225
+ - ✅ 格式补全 (bash, zsh, fish 等)
226
+
227
+ **安装:**
228
+
229
+ ```bash
230
+ # Bash
231
+ ccconfig completion bash >> ~/.bashrc
232
+ source ~/.bashrc
233
+
234
+ # Zsh
235
+ ccconfig completion zsh >> ~/.zshrc
236
+ source ~/.zshrc
237
+
238
+ # Fish
239
+ ccconfig completion fish > ~/.config/fish/completions/ccconfig.fish
240
+ # Fish 会在下次启动时自动加载
241
+
242
+ # PowerShell
243
+ ccconfig completion pwsh >> $PROFILE
244
+ # 重新加载配置: . $PROFILE
245
+ ```
246
+
247
+ **PowerShell 注意事项:** 如果遇到 `$PROFILE` 不存在的错误,请先创建它:
248
+ ```powershell
249
+ New-Item -Path $PROFILE -ItemType File -Force
250
+ ccconfig completion pwsh >> $PROFILE
251
+ . $PROFILE
252
+ ```
253
+
254
+ **安装补全后的使用示例:**
255
+
256
+ ```bash
257
+ # 输入 'ccconfig' 然后按 TAB 查看所有命令
258
+ ccconfig <TAB>
259
+ # 显示: list, add, update, use, remove, current, mode, env, edit, completion
260
+
261
+ # 输入 'ccconfig use' 然后按 TAB 查看所有配置
262
+ ccconfig use <TAB>
263
+ # 显示: work, personal, project1 等
264
+
265
+ # 输入 'ccconfig mode' 然后按 TAB
266
+ ccconfig mode <TAB>
267
+ # 显示: settings, env
268
+ ```
269
+
270
+ ### 快捷别名
271
+
272
+ ```bash
273
+ # 添加到 ~/.bashrc 或 ~/.zshrc
274
+ alias ccs='ccconfig'
275
+ alias ccs-use='ccconfig use'
276
+ alias ccs-list='ccconfig list'
277
+ alias ccs-current='ccconfig current'
278
+
279
+ # Fish (~/.config/fish/config.fish)
280
+ abbr ccs 'ccconfig'
281
+ abbr ccs-use 'ccconfig use'
282
+ abbr ccs-list 'ccconfig list'
283
+ ```
284
+
285
+ ### 项目级配置
286
+
287
+ 对于特定项目,您可以导出 .env 文件:
288
+
289
+ ```bash
290
+ # 导出到项目目录
291
+ cd my-project
292
+ ccconfig use project-config
293
+ ccconfig env dotenv > .env
294
+
295
+ # 使用项目配置
296
+ source .env
297
+ ```
298
+
299
+ ### 备份和同步
300
+
301
+ ```bash
302
+ # 备份配置
303
+ cp ~/.config/ccconfig/profiles.json ~/backup/ccconfig-profiles.json
304
+
305
+ # 同步到新机器
306
+ scp ~/backup/ccconfig-profiles.json new-machine:~/.config/ccconfig/
307
+
308
+ # 或使用版本控制(注意安全!)
309
+ cd ~/.config/ccconfig
310
+ git init
311
+ echo "*.env" >> .gitignore
312
+ git add profiles.json
313
+ git commit -m "ccconfig profiles"
314
+ ```
315
+
316
+ ## 故障排除
317
+
318
+ ### 配置未生效
319
+
320
+ **Settings 模式**:
321
+ 1. **检查配置是否正确写入**:
322
+ ```bash
323
+ ccconfig current
324
+ # 查看【1】~/.claude/settings.json 部分
325
+ ```
326
+ 2. **直接验证 settings.json**:
327
+ ```bash
328
+ cat ~/.claude/settings.json | grep -A 5 '"env"'
329
+ ```
330
+ 3. **确认已重启 Claude Code**:
331
+ - 完全退出 Claude Code(不只是关闭窗口)
332
+ - 重新启动应用程序
333
+ 4. **检查 `~/.claude/settings.json` 中的 `env` 字段**:
334
+ ```json
335
+ {
336
+ "env": {
337
+ "ANTHROPIC_BASE_URL": "https://api.anthropic.com",
338
+ "ANTHROPIC_AUTH_TOKEN": "sk-...",
339
+ "ANTHROPIC_API_KEY": "sk-..."
340
+ }
341
+ }
342
+ ```
343
+
344
+ **ENV 模式**:
345
+ 1. **检查环境变量文件**:
346
+ ```bash
347
+ cat ~/.config/ccconfig/current.env
348
+ ```
349
+ 2. **如果使用 --permanent 标志**:
350
+ - 工具会显示警告并在修改文件前要求确认
351
+ - 检查您的 shell 配置文件是否有 ccconfig 块:
352
+ ```bash
353
+ # For bash/zsh
354
+ cat ~/.bashrc | grep -A 5 "ccconfig"
355
+ # For fish
356
+ cat ~/.config/fish/config.fish | grep -A 5 "ccconfig"
357
+ ```
358
+ - 重启 shell 或运行: `source ~/.bashrc`(或您的 shell 对应的命令)
359
+ - 注意: 您也可以使用 `-p` 作为 `--permanent` 的简写
360
+ - 要取消操作,在提示时输入 "no"
361
+
362
+ 3. **如果使用手动配置或 eval 命令**:
363
+ - 确认 Shell 配置正确: `cat ~/.bashrc | grep ccconfig`
364
+ - 重启 Shell 或使用 `eval $(ccconfig env bash)`
365
+
366
+ 4. **检查进程环境变量**:
367
+ ```bash
368
+ ccconfig current
369
+ # 查看【3】当前进程环境变量部分
370
+ ```
371
+
372
+ ### 切换模式后配置丢失
373
+
374
+ 切换模式不会影响已保存的配置,只会改变配置的应用方式。切换后,您需要再次 `use`:
375
+
376
+ ```bash
377
+ ccconfig mode env # 切换到 env 模式
378
+ ccconfig use work # 重新应用配置
379
+ ```
380
+
381
+ ### 文件权限问题
382
+
383
+ ```bash
384
+ # 修复配置文件权限
385
+ chmod 600 ~/.config/ccconfig/profiles.json
386
+ chmod 600 ~/.claude/settings.json
387
+ chmod 600 ~/.config/ccconfig/current.env
388
+ ```
389
+
390
+ ## 安全考虑
391
+
392
+ 1. **文件权限**: 工具会自动将配置文件设置为 600 权限(仅所有者可读写)
393
+
394
+ 2. **敏感信息**:
395
+ - API 密钥默认隐藏,使用 `--show-secret` 查看完整值
396
+ - 不要将配置文件提交到公共仓库
397
+ - 使用 `.gitignore` 排除敏感文件
398
+
399
+ 3. **环境变量**: ENV 模式的环境变量会被子进程继承,请注意安全
400
+
401
+ 4. **版本控制**: 如果对配置进行版本控制,请使用加密或私有仓库
402
+
403
+ ## 许可证
404
+
405
+ MIT
406
+