ccconfig 1.1.0 → 1.3.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/README.md +198 -160
- package/README_zh.md +406 -0
- package/ccconfig.js +767 -59
- package/package.json +1 -1
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
|
|
|
@@ -9,6 +11,9 @@ ccconfig use company
|
|
|
9
11
|
|
|
10
12
|
# Switch back to personal configuration after work
|
|
11
13
|
ccconfig use personal
|
|
14
|
+
|
|
15
|
+
# Permanently write to shell config (no need to eval or source each time)
|
|
16
|
+
ccconfig use personal --permanent # or use -p for short
|
|
12
17
|
```
|
|
13
18
|
|
|
14
19
|
## Quick Start
|
|
@@ -32,24 +37,46 @@ ccconfig add
|
|
|
32
37
|
# - ANTHROPIC_BASE_URL
|
|
33
38
|
# - ANTHROPIC_AUTH_TOKEN
|
|
34
39
|
# - ANTHROPIC_API_KEY
|
|
35
|
-
# -
|
|
40
|
+
# - ANTHROPIC_MODEL (optional)
|
|
41
|
+
# - ANTHROPIC_SMALL_FAST_MODEL (optional)
|
|
36
42
|
|
|
37
43
|
# 3. Switch configuration
|
|
38
44
|
ccconfig use work
|
|
39
45
|
|
|
40
|
-
# 4.
|
|
46
|
+
# 4. Apply immediately (choose one method):
|
|
47
|
+
# Method A: Temporary (only in current shell)
|
|
41
48
|
eval $(ccconfig env bash) # or use the detected command from output
|
|
49
|
+
|
|
50
|
+
# Method B: Permanent (write to shell config file)
|
|
51
|
+
ccconfig use work --permanent # or -p for short
|
|
52
|
+
# Automatically detects and modifies ~/.bashrc, ~/.zshrc, or config.fish
|
|
42
53
|
```
|
|
43
54
|
|
|
44
55
|
### Settings Mode
|
|
45
56
|
|
|
57
|
+
Settings Mode directly modifies `~/.claude/settings.json` file, which is Claude Code's native configuration file. This mode is suitable when you don't want to configure shell scripts.
|
|
58
|
+
|
|
59
|
+
**How it works:**
|
|
60
|
+
- Writes environment variables directly into `~/.claude/settings.json` under the `env` field
|
|
61
|
+
- Claude Code reads these settings on startup
|
|
62
|
+
- No shell configuration required
|
|
63
|
+
- Requires Claude Code restart after each switch
|
|
64
|
+
|
|
65
|
+
**Setup:**
|
|
66
|
+
|
|
46
67
|
```bash
|
|
47
68
|
# 1. Switch to settings mode
|
|
48
69
|
ccconfig mode settings
|
|
49
70
|
|
|
50
71
|
# 2. Add configuration (interactive mode)
|
|
51
72
|
ccconfig add
|
|
52
|
-
# Follow the prompts to
|
|
73
|
+
# Follow the prompts to enter:
|
|
74
|
+
# - Name
|
|
75
|
+
# - ANTHROPIC_BASE_URL
|
|
76
|
+
# - ANTHROPIC_AUTH_TOKEN
|
|
77
|
+
# - ANTHROPIC_API_KEY
|
|
78
|
+
# - ANTHROPIC_MODEL (optional)
|
|
79
|
+
# - ANTHROPIC_SMALL_FAST_MODEL (optional)
|
|
53
80
|
|
|
54
81
|
# 3. Switch configuration
|
|
55
82
|
ccconfig use work
|
|
@@ -58,9 +85,52 @@ ccconfig use work
|
|
|
58
85
|
# Configuration is now active!
|
|
59
86
|
```
|
|
60
87
|
|
|
88
|
+
**Verification:**
|
|
89
|
+
```bash
|
|
90
|
+
# Check current configuration
|
|
91
|
+
ccconfig current
|
|
92
|
+
|
|
93
|
+
# View the settings file directly
|
|
94
|
+
cat ~/.claude/settings.json
|
|
95
|
+
```
|
|
96
|
+
|
|
61
97
|
#### ENV Mode Shell Configuration
|
|
62
98
|
|
|
63
|
-
|
|
99
|
+
You have two options to configure shell environment:
|
|
100
|
+
|
|
101
|
+
**Option 1: Automatic (Recommended)**
|
|
102
|
+
|
|
103
|
+
Use the `-p/--permanent` flag to automatically write to your shell config:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Automatically detects your shell and writes to the appropriate config file
|
|
107
|
+
ccconfig use <profile> --permanent
|
|
108
|
+
|
|
109
|
+
# You will be prompted with:
|
|
110
|
+
# - Warning about modifying shell config
|
|
111
|
+
# - Target file path
|
|
112
|
+
# - Content preview
|
|
113
|
+
# - Confirmation prompt (yes/no)
|
|
114
|
+
|
|
115
|
+
# This will modify:
|
|
116
|
+
# - Fish: ~/.config/fish/config.fish
|
|
117
|
+
# - Bash: ~/.bashrc
|
|
118
|
+
# - Zsh: ~/.zshrc
|
|
119
|
+
# - PowerShell: ~/.config/powershell/profile.ps1
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The tool will add a marked block between `# >>> ccconfig >>>` and `# <<< ccconfig <<<` markers, making it easy to identify and update later.
|
|
123
|
+
|
|
124
|
+
**Safety Features:**
|
|
125
|
+
- **User confirmation required**: You will be prompted before any file is modified
|
|
126
|
+
- **Content preview**: Shows exactly what will be written
|
|
127
|
+
- **Clear explanation**: Explains what changes will be made
|
|
128
|
+
- **Non-destructive**: Existing content is preserved, only the ccconfig block is updated
|
|
129
|
+
- **Interactive only**: Requires interactive terminal to prevent accidental modifications
|
|
130
|
+
|
|
131
|
+
**Option 2: Manual Configuration**
|
|
132
|
+
|
|
133
|
+
If you prefer to manually configure, add the following to your shell startup files:
|
|
64
134
|
|
|
65
135
|
**Fish** (`~/.config/fish/config.fish`):
|
|
66
136
|
```fish
|
|
@@ -68,8 +138,10 @@ Configure once by adding to your Shell startup files:
|
|
|
68
138
|
set -l ccconfig_env ~/.config/ccconfig/current.env
|
|
69
139
|
if test -f $ccconfig_env
|
|
70
140
|
for line in (cat $ccconfig_env)
|
|
71
|
-
set -l parts (string split '=' $line)
|
|
72
|
-
|
|
141
|
+
set -l parts (string split -m1 '=' $line)
|
|
142
|
+
if test (count $parts) -eq 2
|
|
143
|
+
set -gx $parts[1] $parts[2]
|
|
144
|
+
end
|
|
73
145
|
end
|
|
74
146
|
end
|
|
75
147
|
```
|
|
@@ -78,7 +150,9 @@ end
|
|
|
78
150
|
```bash
|
|
79
151
|
# Load Claude Code environment variables
|
|
80
152
|
if [ -f ~/.config/ccconfig/current.env ]; then
|
|
81
|
-
|
|
153
|
+
set -a
|
|
154
|
+
. ~/.config/ccconfig/current.env
|
|
155
|
+
set +a
|
|
82
156
|
fi
|
|
83
157
|
```
|
|
84
158
|
|
|
@@ -86,7 +160,9 @@ fi
|
|
|
86
160
|
```zsh
|
|
87
161
|
# Load Claude Code environment variables
|
|
88
162
|
if [ -f ~/.config/ccconfig/current.env ]; then
|
|
89
|
-
|
|
163
|
+
set -a
|
|
164
|
+
. ~/.config/ccconfig/current.env
|
|
165
|
+
set +a
|
|
90
166
|
fi
|
|
91
167
|
```
|
|
92
168
|
|
|
@@ -103,98 +179,95 @@ if (Test-Path $cconfigEnv) {
|
|
|
103
179
|
}
|
|
104
180
|
```
|
|
105
181
|
|
|
106
|
-
|
|
182
|
+
**Note**: Manual configuration allows you to switch profiles dynamically by changing `current.env`, while `-p/--permanent` writes the values directly into the shell config.
|
|
183
|
+
|
|
184
|
+
## Advanced Usage
|
|
107
185
|
|
|
108
|
-
###
|
|
186
|
+
### Update Existing Configuration
|
|
187
|
+
|
|
188
|
+
If you need to modify an existing configuration, use the `update` command:
|
|
109
189
|
|
|
110
190
|
```bash
|
|
111
|
-
#
|
|
112
|
-
ccconfig
|
|
191
|
+
# Update a configuration interactively
|
|
192
|
+
ccconfig update work
|
|
113
193
|
|
|
114
|
-
#
|
|
115
|
-
|
|
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
|
+
```
|
|
116
199
|
|
|
117
|
-
|
|
118
|
-
|
|
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
|
|
119
205
|
|
|
120
|
-
|
|
121
|
-
|
|
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]:
|
|
122
211
|
|
|
123
|
-
|
|
124
|
-
|
|
212
|
+
✓ Configuration 'work' updated
|
|
213
|
+
```
|
|
125
214
|
|
|
126
|
-
|
|
127
|
-
ccconfig current
|
|
128
|
-
ccconfig current --show-secret # Show full token
|
|
215
|
+
**Note:** After updating a configuration, remember to activate it with `ccconfig use work` if you want the changes to take effect immediately.
|
|
129
216
|
|
|
130
|
-
|
|
131
|
-
ccconfig edit
|
|
217
|
+
### Shell Completion
|
|
132
218
|
|
|
133
|
-
|
|
134
|
-
ccconfig --version # or -V
|
|
135
|
-
```
|
|
219
|
+
ccconfig supports shell completion for commands, profile names, and options. This makes it easier to discover and use commands.
|
|
136
220
|
|
|
137
|
-
|
|
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:**
|
|
138
229
|
|
|
139
230
|
```bash
|
|
140
|
-
#
|
|
141
|
-
ccconfig
|
|
231
|
+
# Bash
|
|
232
|
+
ccconfig completion bash >> ~/.bashrc
|
|
233
|
+
source ~/.bashrc
|
|
142
234
|
|
|
143
|
-
#
|
|
144
|
-
ccconfig
|
|
235
|
+
# Zsh
|
|
236
|
+
ccconfig completion zsh >> ~/.zshrc
|
|
237
|
+
source ~/.zshrc
|
|
145
238
|
|
|
146
|
-
#
|
|
147
|
-
ccconfig
|
|
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
|
|
148
246
|
```
|
|
149
247
|
|
|
150
|
-
|
|
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:**
|
|
151
256
|
|
|
152
257
|
```bash
|
|
153
|
-
#
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
ccconfig env pwsh | iex # PowerShell
|
|
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
|
|
157
261
|
|
|
158
|
-
#
|
|
159
|
-
ccconfig
|
|
160
|
-
|
|
262
|
+
# Type 'ccconfig use' and press TAB to see all profiles
|
|
263
|
+
ccconfig use <TAB>
|
|
264
|
+
# Shows: work, personal, project1, etc.
|
|
161
265
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
- **Claude Settings**: `~/.claude/settings.json`
|
|
166
|
-
- **Environment Variables File**: `~/.config/ccconfig/current.env`
|
|
167
|
-
- **Mode Settings**: `~/.config/ccconfig/mode`
|
|
168
|
-
|
|
169
|
-
## Configuration Example
|
|
170
|
-
|
|
171
|
-
`~/.config/ccconfig/profiles.json`:
|
|
172
|
-
|
|
173
|
-
```json
|
|
174
|
-
{
|
|
175
|
-
"profiles": {
|
|
176
|
-
"work": {
|
|
177
|
-
"env": {
|
|
178
|
-
"ANTHROPIC_BASE_URL": "https://api-proxy.company.com",
|
|
179
|
-
"ANTHROPIC_AUTH_TOKEN": "sk-auth-work-xxxxx",
|
|
180
|
-
"ANTHROPIC_API_KEY": "sk-key-work-xxxxx"
|
|
181
|
-
},
|
|
182
|
-
"description": "Work account"
|
|
183
|
-
},
|
|
184
|
-
"personal": {
|
|
185
|
-
"env": {
|
|
186
|
-
"ANTHROPIC_BASE_URL": "https://api.anthropic.com",
|
|
187
|
-
"ANTHROPIC_AUTH_TOKEN": "sk-ant-personal-xxxxx",
|
|
188
|
-
"ANTHROPIC_API_KEY": "sk-ant-personal-xxxxx"
|
|
189
|
-
},
|
|
190
|
-
"description": "Personal account"
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
266
|
+
# Type 'ccconfig mode' and press TAB
|
|
267
|
+
ccconfig mode <TAB>
|
|
268
|
+
# Shows: settings, env
|
|
194
269
|
```
|
|
195
270
|
|
|
196
|
-
## Advanced Usage
|
|
197
|
-
|
|
198
271
|
### Quick Aliases
|
|
199
272
|
|
|
200
273
|
```bash
|
|
@@ -246,15 +319,56 @@ git commit -m "ccconfig profiles"
|
|
|
246
319
|
### Configuration Not Taking Effect
|
|
247
320
|
|
|
248
321
|
**Settings Mode**:
|
|
249
|
-
1. Check
|
|
250
|
-
|
|
251
|
-
|
|
322
|
+
1. **Check configuration is written correctly**:
|
|
323
|
+
```bash
|
|
324
|
+
ccconfig current
|
|
325
|
+
# Look at section 【1】~/.claude/settings.json
|
|
326
|
+
```
|
|
327
|
+
2. **Verify settings.json directly**:
|
|
328
|
+
```bash
|
|
329
|
+
cat ~/.claude/settings.json | grep -A 5 '"env"'
|
|
330
|
+
```
|
|
331
|
+
3. **Confirm Claude Code has been restarted**:
|
|
332
|
+
- Completely quit Claude Code (not just close window)
|
|
333
|
+
- Restart the application
|
|
334
|
+
4. **Check the `env` field** in `~/.claude/settings.json`:
|
|
335
|
+
```json
|
|
336
|
+
{
|
|
337
|
+
"env": {
|
|
338
|
+
"ANTHROPIC_BASE_URL": "https://api.anthropic.com",
|
|
339
|
+
"ANTHROPIC_AUTH_TOKEN": "sk-...",
|
|
340
|
+
"ANTHROPIC_API_KEY": "sk-..."
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
```
|
|
252
344
|
|
|
253
345
|
**ENV Mode**:
|
|
254
|
-
1. Check environment variables file
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
346
|
+
1. **Check environment variables file**:
|
|
347
|
+
```bash
|
|
348
|
+
cat ~/.config/ccconfig/current.env
|
|
349
|
+
```
|
|
350
|
+
2. **If using --permanent flag**:
|
|
351
|
+
- The tool will show a warning and ask for confirmation before modifying files
|
|
352
|
+
- Check your shell config file has ccconfig block:
|
|
353
|
+
```bash
|
|
354
|
+
# For bash/zsh
|
|
355
|
+
cat ~/.bashrc | grep -A 5 "ccconfig"
|
|
356
|
+
# For fish
|
|
357
|
+
cat ~/.config/fish/config.fish | grep -A 5 "ccconfig"
|
|
358
|
+
```
|
|
359
|
+
- Restart shell or run: `source ~/.bashrc` (or equivalent for your shell)
|
|
360
|
+
- Note: You can also use `-p` as a short form of `--permanent`
|
|
361
|
+
- To cancel the operation, type "no" when prompted
|
|
362
|
+
|
|
363
|
+
3. **If using manual configuration or eval command**:
|
|
364
|
+
- Confirm Shell configuration is correct: `cat ~/.bashrc | grep ccconfig`
|
|
365
|
+
- Restart Shell or use `eval $(ccconfig env bash)`
|
|
366
|
+
|
|
367
|
+
4. **Check process environment variables**:
|
|
368
|
+
```bash
|
|
369
|
+
ccconfig current
|
|
370
|
+
# Look at section 【3】Current Process Environment Variables
|
|
371
|
+
```
|
|
258
372
|
|
|
259
373
|
### Configuration Lost After Mode Switch
|
|
260
374
|
|
|
@@ -287,82 +401,6 @@ chmod 600 ~/.config/ccconfig/current.env
|
|
|
287
401
|
|
|
288
402
|
4. **Version Control**: If version controlling configurations, use encryption or private repositories
|
|
289
403
|
|
|
290
|
-
## Frequently Asked Questions
|
|
291
|
-
|
|
292
|
-
**Q: Which is better, Settings mode or ENV mode?**
|
|
293
|
-
|
|
294
|
-
A:
|
|
295
|
-
- **ENV mode** is recommended (default, better cross-shell support, instant apply)
|
|
296
|
-
- If you prefer not to configure shell startup files, **Settings mode** can be simpler (only needs Claude Code restart)
|
|
297
|
-
|
|
298
|
-
**Q: Can I use both modes simultaneously?**
|
|
299
|
-
|
|
300
|
-
A: Not recommended. Claude Code reads configuration based on priority:
|
|
301
|
-
- Settings mode: Reads directly from `settings.json`
|
|
302
|
-
- ENV mode: Reads from environment variables
|
|
303
|
-
|
|
304
|
-
Using both simultaneously may cause confusion.
|
|
305
|
-
|
|
306
|
-
**Q: How to use on Windows?**
|
|
307
|
-
|
|
308
|
-
A: Fully supported on Windows:
|
|
309
|
-
- Configuration file location: `%USERPROFILE%\.config\ccconfig\`
|
|
310
|
-
- Settings mode requires no additional configuration
|
|
311
|
-
- ENV mode uses PowerShell configuration
|
|
312
|
-
|
|
313
|
-
**Q: Do I need to restart after switching configurations?**
|
|
314
|
-
|
|
315
|
-
A:
|
|
316
|
-
- **Settings mode**: Need to restart Claude Code
|
|
317
|
-
- **ENV mode**: Need to restart Shell (or use `env` command for immediate effect)
|
|
318
|
-
|
|
319
|
-
**Q: Can I export configurations for team use?**
|
|
320
|
-
|
|
321
|
-
A: Yes, but be careful:
|
|
322
|
-
```bash
|
|
323
|
-
# Export configuration structure (excluding API keys)
|
|
324
|
-
cat ~/.config/ccconfig/profiles.json | \
|
|
325
|
-
jq '.profiles | map_values({baseUrl, description})' > team-config.json
|
|
326
|
-
|
|
327
|
-
# Team members manually add their own API keys after importing
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
## Development
|
|
331
|
-
|
|
332
|
-
### Project Structure
|
|
333
|
-
|
|
334
|
-
```
|
|
335
|
-
.
|
|
336
|
-
├── ccconfig.js # Core script
|
|
337
|
-
├── package.json # npm configuration
|
|
338
|
-
├── README.md # This document
|
|
339
|
-
└── .gitignore # Git ignore file
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
### Testing
|
|
343
|
-
|
|
344
|
-
```bash
|
|
345
|
-
# Test version output
|
|
346
|
-
node ccconfig.js --version
|
|
347
|
-
|
|
348
|
-
# Test adding configuration (interactive only)
|
|
349
|
-
node ccconfig.js add
|
|
350
|
-
|
|
351
|
-
# Test listing
|
|
352
|
-
node ccconfig.js list
|
|
353
|
-
|
|
354
|
-
# Test switching
|
|
355
|
-
node ccconfig.js use test
|
|
356
|
-
|
|
357
|
-
# Test status viewing
|
|
358
|
-
node ccconfig.js current
|
|
359
|
-
node ccconfig.js current --show-secret
|
|
360
|
-
|
|
361
|
-
# Test mode switching
|
|
362
|
-
node ccconfig.js mode
|
|
363
|
-
node ccconfig.js mode env
|
|
364
|
-
```
|
|
365
|
-
|
|
366
404
|
## License
|
|
367
405
|
|
|
368
406
|
MIT
|