@supertiny99/cc-switch 1.0.2 → 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.en.md +342 -0
- package/README.md +2 -0
- package/dist/lib/config/creator.js +1 -1
- package/dist/lib/config/creator.js.map +1 -1
- package/package.json +2 -1
package/README.en.md
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
# cc-switch
|
|
2
|
+
|
|
3
|
+
[English](README.en.md) | [中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
> A TUI tool for quickly switching Claude Code API providers
|
|
6
|
+
|
|
7
|
+
When your token quota is exhausted, you can quickly switch to another provider/token.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 🔄 **Quick Switch** - Complete provider switch in 1-2 seconds
|
|
12
|
+
- 🎨 **Interactive Selection** - Friendly interface with fuzzy search support
|
|
13
|
+
- 🔒 **Auto Backup** - Automatically backs up config before each switch
|
|
14
|
+
- 📦 **Extensible** - Reserved interfaces for MCP, skills, and plugin switching
|
|
15
|
+
- 🌍 **Multi-provider** - Supports any Anthropic API-compatible provider
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Global Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g @supertiny99/cc-switch
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Local Development
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone <repo-url>
|
|
29
|
+
cd cc-switch
|
|
30
|
+
npm install
|
|
31
|
+
npm link # Link to local environment
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
### 1. Check Current Configuration
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
cc-switch current
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Output:
|
|
43
|
+
```
|
|
44
|
+
Current Configuration:
|
|
45
|
+
Provider: zhipu
|
|
46
|
+
Base URL: https://open.bigmodel.cn/api/anthropic
|
|
47
|
+
Haiku Model: GLM-4.5-Air
|
|
48
|
+
Sonnet Model: GLM-4.7
|
|
49
|
+
Opus Model: GLM-4.7
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. List All Providers
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
cc-switch list
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 3. Interactive Switch
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
cc-switch
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Type `zh` to quickly locate "Zhipu AI", then press Enter to confirm.
|
|
65
|
+
|
|
66
|
+
### 4. Direct Switch
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
cc-switch use anthropic
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Configuration Files
|
|
73
|
+
|
|
74
|
+
Provider profiles are located in `~/.claude/profiles/`:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
~/.claude/
|
|
78
|
+
├── settings.json # Current Claude Code configuration
|
|
79
|
+
├── profiles/ # Provider configuration directory
|
|
80
|
+
│ ├── zhipu.json # Zhipu AI (GLM)
|
|
81
|
+
│ ├── anthropic.json # Anthropic Official
|
|
82
|
+
│ └── custom.json # Custom provider
|
|
83
|
+
└── cc-switch-backups/ # Auto backup directory
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Creating a Custom Provider
|
|
87
|
+
|
|
88
|
+
Create a JSON file in `~/.claude/profiles/`:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"id": "my-provider",
|
|
93
|
+
"name": "My Provider",
|
|
94
|
+
"description": "Custom API provider",
|
|
95
|
+
"icon": "🚀",
|
|
96
|
+
"config": {
|
|
97
|
+
"env": {
|
|
98
|
+
"ANTHROPIC_AUTH_TOKEN": "your_token_here",
|
|
99
|
+
"ANTHROPIC_BASE_URL": "https://your-api-endpoint.com",
|
|
100
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "model-name",
|
|
101
|
+
"ANTHROPIC_DEFAULT_OPUS_MODEL": "model-name",
|
|
102
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL": "model-name"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Command Reference
|
|
109
|
+
|
|
110
|
+
| Command | Description |
|
|
111
|
+
|---------|-------------|
|
|
112
|
+
| `cc-switch` | Interactive provider selection |
|
|
113
|
+
| `cc-switch use <id>` | Switch directly to specified provider |
|
|
114
|
+
| `cc-switch list` | List all available providers |
|
|
115
|
+
| `cc-switch current` | Display current configuration |
|
|
116
|
+
| `cc-switch history` | View backup history |
|
|
117
|
+
| `cc-switch restore <file>` | Restore from backup |
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
### Project Structure
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
cc-switch/
|
|
125
|
+
├── src/
|
|
126
|
+
│ ├── index.ts # CLI entry point
|
|
127
|
+
│ ├── lib/
|
|
128
|
+
│ │ └── config/
|
|
129
|
+
│ │ ├── schema.ts # Type definitions
|
|
130
|
+
│ │ ├── loader.ts # Config reading
|
|
131
|
+
│ │ └── writer.ts # Config writing (with backup)
|
|
132
|
+
│ └── ui/
|
|
133
|
+
│ └── quick-select.ts # Interactive selection
|
|
134
|
+
├── package.json
|
|
135
|
+
├── tsconfig.json
|
|
136
|
+
└── README.md
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Development Commands
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# Install dependencies
|
|
143
|
+
npm install
|
|
144
|
+
|
|
145
|
+
# Development mode (hot reload)
|
|
146
|
+
npm run dev list
|
|
147
|
+
|
|
148
|
+
# Build
|
|
149
|
+
npm run build
|
|
150
|
+
|
|
151
|
+
# Local testing
|
|
152
|
+
npm link
|
|
153
|
+
cc-switch list
|
|
154
|
+
|
|
155
|
+
# Run tests
|
|
156
|
+
npm test
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Adding New Features
|
|
160
|
+
|
|
161
|
+
1. **Add CLI Command** - Add in `src/index.ts`:
|
|
162
|
+
```typescript
|
|
163
|
+
program
|
|
164
|
+
.command('my-command')
|
|
165
|
+
.description('My command')
|
|
166
|
+
.action(async () => {
|
|
167
|
+
// Your logic
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
2. **Add Config Items** - Extend types in `src/lib/config/schema.ts`
|
|
172
|
+
|
|
173
|
+
3. **Add UI Components** - Create new files in `src/ui/`
|
|
174
|
+
|
|
175
|
+
## Testing
|
|
176
|
+
|
|
177
|
+
### Manual Testing Checklist
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# 1. Test listing providers
|
|
181
|
+
cc-switch list
|
|
182
|
+
|
|
183
|
+
# 2. Test displaying current config
|
|
184
|
+
cc-switch current
|
|
185
|
+
|
|
186
|
+
# 3. Test switching providers
|
|
187
|
+
cc-switch use anthropic
|
|
188
|
+
cc-switch current # Verify switch
|
|
189
|
+
|
|
190
|
+
# 4. Test backup function
|
|
191
|
+
cc-switch history
|
|
192
|
+
|
|
193
|
+
# 5. Test restoring backup
|
|
194
|
+
cc-switch restore settings-2025-01-29T14-30-22-123Z.json
|
|
195
|
+
|
|
196
|
+
# 6. Test interactive selection
|
|
197
|
+
cc-switch # Press Ctrl+C to cancel
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Unit Tests (To Be Implemented)
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
npm test
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Publishing to npm
|
|
207
|
+
|
|
208
|
+
### 1. Prepare for Release
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
# Ensure build is complete
|
|
212
|
+
npm run build
|
|
213
|
+
|
|
214
|
+
# Check package.json configuration
|
|
215
|
+
cat package.json
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 2. npm Account Setup
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# Login to npm (first time only)
|
|
222
|
+
npm login
|
|
223
|
+
|
|
224
|
+
# Or login using token
|
|
225
|
+
npm token create
|
|
226
|
+
npm logout
|
|
227
|
+
npm login --registry=https://registry.npmjs.org --auth-only
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 3. Check Package Name Availability
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
npm search @supertiny99/cc-switch
|
|
234
|
+
# Or visit https://www.npmjs.com/package/@supertiny99/cc-switch
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### 4. Release Process
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
# 1. Update version number
|
|
241
|
+
npm version patch # 1.0.0 -> 1.0.1
|
|
242
|
+
npm version minor # 1.0.0 -> 1.1.0
|
|
243
|
+
npm version major # 1.0.0 -> 2.0.0
|
|
244
|
+
|
|
245
|
+
# 2. Publish to npm
|
|
246
|
+
npm publish
|
|
247
|
+
|
|
248
|
+
# 3. Verify release
|
|
249
|
+
npm view @supertiny99/cc-switch
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### 5. Release Options
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
# Public release (default)
|
|
256
|
+
npm publish
|
|
257
|
+
|
|
258
|
+
# Publish as scoped package (@scope/package-name)
|
|
259
|
+
npm publish --access public
|
|
260
|
+
|
|
261
|
+
# Dry run (don't actually publish)
|
|
262
|
+
npm publish --dry-run
|
|
263
|
+
|
|
264
|
+
# Publish with specific tag
|
|
265
|
+
npm publish --tag beta
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### 6. Post-Release Verification
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Global installation test
|
|
272
|
+
npm install -g @supertiny99/cc-switch
|
|
273
|
+
|
|
274
|
+
# Or run directly with npx
|
|
275
|
+
npx @supertiny99/cc-switch list
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Release Checklist
|
|
279
|
+
|
|
280
|
+
- [ ] Update package.json version number
|
|
281
|
+
- [ ] Run `npm run build` to ensure successful build
|
|
282
|
+
- [ ] Update README.md documentation
|
|
283
|
+
- [ ] Add LICENSE file
|
|
284
|
+
- [ ] Test all commands work properly
|
|
285
|
+
- [ ] Confirm package name is not taken
|
|
286
|
+
- [ ] Check .npmignore excludes unnecessary files
|
|
287
|
+
|
|
288
|
+
## Troubleshooting
|
|
289
|
+
|
|
290
|
+
### Command Not Found
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
# Re-link
|
|
294
|
+
npm link
|
|
295
|
+
|
|
296
|
+
# Or check global path
|
|
297
|
+
which cc-switch
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Configuration File Error
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
# View backups
|
|
304
|
+
cc-switch history
|
|
305
|
+
|
|
306
|
+
# Restore backup
|
|
307
|
+
cc-switch restore <backup-file>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Permission Issues
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
# macOS/Linux may need sudo
|
|
314
|
+
sudo npm link
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## Compatibility
|
|
318
|
+
|
|
319
|
+
- Node.js >= 16.0.0
|
|
320
|
+
- macOS, Linux, Windows
|
|
321
|
+
|
|
322
|
+
## License
|
|
323
|
+
|
|
324
|
+
MIT
|
|
325
|
+
|
|
326
|
+
## Contributing
|
|
327
|
+
|
|
328
|
+
Issues and Pull Requests are welcome!
|
|
329
|
+
|
|
330
|
+
## Roadmap
|
|
331
|
+
|
|
332
|
+
- [ ] MCP server switching
|
|
333
|
+
- [ ] Skill enable/disable
|
|
334
|
+
- [ ] Plugin management
|
|
335
|
+
- [ ] Full TUI interface (using Ink)
|
|
336
|
+
- [ ] Configuration validation
|
|
337
|
+
- [ ] Unit tests
|
|
338
|
+
|
|
339
|
+
## Related Links
|
|
340
|
+
|
|
341
|
+
- [Claude Code](https://github.com/anthropics/claude-code)
|
|
342
|
+
- [Anthropic API](https://docs.anthropic.com/)
|
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"creator.js","sourceRoot":"","sources":["../../../src/lib/config/creator.ts"],"names":[],"mappings":";;;;;;AAuEA,kCAOC;AAED,gCAIC;AAED,0DAiDC;AAED,sCAGC;AA5ID,wDAA0B;AAC1B,gDAAwB;AACxB,4CAAoB;AAGpB,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;AACtD,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAe1C,QAAA,gBAAgB,GAAqB;IAChD;QACE,EAAE,EAAE,WAAW;QACf,IAAI,EAAE,sBAAsB;QAC5B,WAAW,EAAE,wBAAwB;QACrC,IAAI,EAAE,IAAI;QACV,aAAa,EAAE;YACb,KAAK,EAAE,2BAA2B;YAClC,MAAM,EAAE,4BAA4B;YACpC,IAAI,EAAE,0BAA0B;SACjC;KACF;IACD;QACE,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,uBAAuB;QAC7B,WAAW,EAAE,wBAAwB;QACrC,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,wCAAwC;QACjD,aAAa,EAAE;YACb,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"creator.js","sourceRoot":"","sources":["../../../src/lib/config/creator.ts"],"names":[],"mappings":";;;;;;AAuEA,kCAOC;AAED,gCAIC;AAED,0DAiDC;AAED,sCAGC;AA5ID,wDAA0B;AAC1B,gDAAwB;AACxB,4CAAoB;AAGpB,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAA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AAC;QACf,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,6BAA6B,GAAG,UAAU,CAAC;IAChE,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,YAAY,IAAI,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC;IACzE,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,8BAA8B,GAAG,WAAW,CAAC;IAClE,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,IAAI,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC;IACnE,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,GAAG,SAAS,CAAC;IAC9D,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAEM,KAAK,UAAU,aAAa,CAAC,EAAU;IAC5C,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAC1D,OAAO,kBAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AACpC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supertiny99/cc-switch",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Quick TUI for switching Claude Code API providers - fast provider/token switching when quota is exhausted",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"build": "tsc",
|
|
16
16
|
"dev": "ts-node src/index.ts",
|
|
17
17
|
"link": "npm link",
|
|
18
|
+
"link:global": "npm run build && npm link -g cc-switch",
|
|
18
19
|
"prepublishOnly": "npm run build",
|
|
19
20
|
"pretest": "npm run build",
|
|
20
21
|
"test": "echo \"Error: no test specified\" && exit 1",
|