@cc-x/cc-x 0.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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 删繁LESS (becomeless)
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.
22
+
23
+
package/README.en.md ADDED
@@ -0,0 +1,339 @@
1
+ # ccx
2
+
3
+ > [简体中文](README.md) | English
4
+
5
+ **A Claude Code API switcher** (terminal command: `xx`). Quickly switch Claude Code
6
+ between the official account and third-party Anthropic-compatible APIs (DeepSeek,
7
+ Zhipu GLM, Xiaomi MiMo, etc.).
8
+
9
+ What makes it different: **it never writes any Claude Code config file**. API switching works
10
+ purely through environment variables, so it is **physically incapable of clobbering your MCP servers,
11
+ plugins, or hooks** — and it lets **multiple terminals each run a different API at the
12
+ same time, without interfering with one another**.
13
+
14
+ > 🌍 **Cross-platform:** one `npm install -g @cc-x/cc-x` installs it on **Windows / macOS / Linux**
15
+ > (the command is still `xx`; the npm package is `@cc-x/cc-x`), with a built-in **English / Chinese
16
+ > UI toggle**. A PowerShell edition is still available on Windows (see [Install](#install)).
17
+
18
+ ---
19
+
20
+ ## Why it exists
21
+
22
+ Claude Code can talk to different API backends via environment variables, but switching
23
+ by hand is tedious: editing `settings.json` or typing long `export`s, plus third-party
24
+ APIs need **model mappings** (they only know their own model names), and there's no neat
25
+ way to give each of several parallel terminals a different API. ccx folds all of that
26
+ into one command, `xx`: pick a provider, then either **use it for this terminal only** or
27
+ **set it as the default** for future terminals.
28
+
29
+ ## ccx vs cc-switch
30
+
31
+ cc-switch is an excellent all-in-one **GUI** — if you want a graphical app, want to manage
32
+ MCP centrally, and also switch Codex / Gemini and other CLIs, it fits better. ccx takes the
33
+ opposite, **minimal** approach:
34
+
35
+ | | ccx (command `xx`) | cc-switch |
36
+ |---|---|---|
37
+ | Form | Terminal command (lightweight) | Desktop GUI (full-featured) |
38
+ | Scope | Only switches the API | API + MCP + multiple CLIs + prompts… |
39
+ | Touches config files? | **No** (env vars only) | Rewrites config files from its own DB |
40
+ | Can lose MCP / plugins? | **Impossible by design** | Users have reported it overwriting them |
41
+ | Different API per terminal | **Native** (process-level isolation) | Global switch; sessions can interfere |
42
+
43
+ **ccx fits you if you** live in the terminal, often run **several terminals with different
44
+ APIs in parallel**, have been burned by a switcher corrupting your config/MCP, or simply
45
+ want the one job done with zero extra features.
46
+
47
+ **cc-switch fits you if you** want a GUI, need to manage MCP and several AI CLIs in one
48
+ place, or prefer an all-in-one tool.
49
+
50
+ ## Safety
51
+
52
+ - **Writes no Claude Code config files.** It never touches `~/.claude/settings.json`, and never opens
53
+ `~/.claude.json` (where your MCP config lives). MCP / plugins / hooks / permissions
54
+ cannot be affected.
55
+ - It only ever sets/clears these 7 "managed" variables, nothing else:
56
+ `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_API_KEY`,
57
+ `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`,
58
+ `ANTHROPIC_DEFAULT_HAIKU_MODEL`, `CLAUDE_CODE_EFFORT_LEVEL`.
59
+ - On switch it clears the managed variables the target profile doesn't use (the two auth
60
+ fields are mutually exclusive), so nothing leaks from the previous provider.
61
+
62
+ > 💡 **About `settings.json` and other Claude Code config files:** don't manage them with
63
+ > third-party tools (ccx deliberately doesn't either). To change them, use Claude Code's own
64
+ > `/update-config` and just describe what you want in natural language (e.g. "allow npm
65
+ > commands", "switch to dark theme") — Claude Code maintains the file itself, which is safer
66
+ > than letting an external tool rewrite it.
67
+
68
+ ## Requirements
69
+
70
+ - **Node.js ≥ 18** — needed by the cross-platform npm edition (`cc-x`). Claude Code itself
71
+ depends on Node, so you most likely already have it.
72
+ - **Claude Code installed (`claude` on PATH)** — "Use this session" launches `claude`.
73
+ - *(optional, legacy)* PowerShell 7+ — the PowerShell edition is still offered on Windows.
74
+
75
+ > Fully verified on **Windows**; "Set as default" on **macOS / Linux** (writing the shell
76
+ > startup file) is the new cross-platform capability, while "Use this session" is identical
77
+ > everywhere. Feedback on other platforms is welcome.
78
+
79
+ ## Install
80
+
81
+ **Option 1: npm (recommended, cross-platform)**
82
+
83
+ ```bash
84
+ npm install -g @cc-x/cc-x
85
+ ```
86
+
87
+ Then type `xx` in any terminal. Update with `npm update -g @cc-x/cc-x`; remove with
88
+ `npm uninstall -g @cc-x/cc-x`. (The npm package is `@cc-x/cc-x`; the terminal command is `xx`.)
89
+
90
+ **Option 2: PowerShell Gallery (Windows, legacy)**
91
+
92
+ ```powershell
93
+ Install-Module ccx
94
+ ```
95
+
96
+ Then type `xx` in any terminal (the module auto-loads). Update with `Update-Module ccx`;
97
+ remove with `Uninstall-Module ccx`.
98
+
99
+ **Option 3: from source (dev / custom)**
100
+
101
+ ```bash
102
+ # npm edition
103
+ git clone https://github.com/becomeless/cc-x
104
+ cd ccx && npm install && npm run build && npm link # then `xx` is available
105
+
106
+ # or the PowerShell edition
107
+ pwsh -ExecutionPolicy Bypass -File .\ccx\install.ps1 # registers an xx function in $PROFILE (idempotent)
108
+ ```
109
+
110
+ **Open a new terminal afterwards.**
111
+
112
+ ## Quick start
113
+
114
+ 1. Open a new terminal and run `xx`. On first run it creates 4 default profiles in
115
+ `~/.cc-mini/providers.json` (official + DeepSeek + Zhipu GLM + Xiaomi MiMo) with
116
+ **empty keys**.
117
+ 2. Use ↑↓ to pick a profile → Enter → "Edit" → enter your **API key** (done locally).
118
+ 3. Then either choose **Set as default** (open a new terminal, bare `claude` uses it) or
119
+ **Use this session** (launches Claude in the current terminal immediately).
120
+
121
+ ## The two activation modes (core concept)
122
+
123
+ Which API Claude uses is ultimately decided by **environment variables**. ccx offers two
124
+ scopes:
125
+
126
+ | | Use this session | Set as default |
127
+ |---|---|---|
128
+ | Mechanism | Sets env vars in **the current process only**, then launches `claude` | Writes **user environment variables** |
129
+ | Scope | This terminal only, **gone when it closes** | Future **newly opened** terminals' bare `claude` |
130
+ | Effect on other / running sessions | **None** | **None** (env is fixed at process start) |
131
+ | Typical use | Parallel terminals, each on a different API | Your usual "main" API |
132
+
133
+ **Parallel example:** open 4 terminals and run `xx 官方 -Session`, `xx DeepSeek -Session`,
134
+ `xx 智谱GLM -Session`, `xx 小米MiMo -Session` — four Claude sessions running at once, each
135
+ on its own API, independent.
136
+
137
+ **Why not switch via a global config file?** Because `settings.json` is global and editing
138
+ it can disturb **running** sessions (e.g. another terminal suddenly erroring with
139
+ `... cannot be parsed as a URL`). ccx avoids this with env vars: per-process isolation plus
140
+ a user-level default.
141
+
142
+ ## Menu
143
+
144
+ Run `xx` for the interactive menu (`↑↓` move, `Enter` select, `q`/`Esc` quit; number keys
145
+ also work). With a profile highlighted, press **`Shift+↑↓` (or `PgUp`/`PgDn`) to move it
146
+ up/down and reorder** — saved instantly:
147
+
148
+ - **Select a profile → Enter** opens the action menu:
149
+ - **Use this session** — sets env for this terminal and launches Claude now.
150
+ - **Set as default** — writes user env vars; **open a new terminal** for bare `claude` to
151
+ pick it up; running sessions unaffected.
152
+ - **Edit** — opens the form (below).
153
+ - **Delete** — removes the profile (with confirmation; keep "官方").
154
+ - **Back**.
155
+ - **+ New profile**.
156
+ - **🌐 语言 / Language** — toggle the UI between English and Chinese instantly (remembered;
157
+ written back to `lang` in `~/.cc-mini/providers.json`).
158
+ - **Quit**.
159
+
160
+ **Edit form:** `↑↓` to pick a field, `Enter` to edit it; scroll past the fields to choose
161
+ "Save & return" / "Discard". Inside a field, **Enter = keep unchanged**, `-` = clear,
162
+ `Esc` = cancel that field. The first field is **"Provider"**: pick a provider (from the
163
+ catalog) and it **auto-fills** the API URL, the three model mappings, and the auth field
164
+ (if the provider has multiple API URLs — e.g. Xiaomi MiMo's pay-as-you-go API vs TokenPlan —
165
+ you choose one). "Note" is free text. "API URL" can also be opened on its own to override
166
+ (catalog + already-used URLs + manual entry).
167
+
168
+ > "Provider" is a picker — press `Esc` to cancel in one key. "Note" uses plain input
169
+ > (Enter = keep, `-` = clear; CJK input-method friendly).
170
+
171
+ ## CLI usage
172
+
173
+ ```bash
174
+ xx # interactive menu
175
+ xx DeepSeek # "Set as default" to the profile named DeepSeek
176
+ xx DeepSeek -s # "Use this session" and launch Claude (--session)
177
+ xx -l # list all profiles and their status (--list)
178
+ xx --lang en # UI in English for this run (zh / en)
179
+ xx --help # show all options
180
+ ```
181
+
182
+ - The **npm edition** uses `-s/--session`, `-l/--list`, `--lang`, `--help`; the **PowerShell
183
+ edition** uses `-Session`, `-List` (no `--lang`).
184
+
185
+ ## Profile fields
186
+
187
+ | Field | Env var | Notes |
188
+ |---|---|---|
189
+ | Provider | — | Picked from the catalog; auto-fills API URL / models / auth field. Also the profile's unique id — collisions get a ` 2`/` 3`… suffix (see "Multiple accounts") |
190
+ | Note | — | Free text; tells apart multiple profiles of the same provider |
191
+ | API URL | `ANTHROPIC_BASE_URL` | Third-party endpoint; empty = official login |
192
+ | Auth field | — | Whether the key goes into `AUTH_TOKEN` or `API_KEY` |
193
+ | API key | `ANTHROPIC_AUTH_TOKEN` / `ANTHROPIC_API_KEY` | Value for the chosen auth field |
194
+ | opus → model | `ANTHROPIC_DEFAULT_OPUS_MODEL` | model the `opus` tier maps to |
195
+ | sonnet → model | `ANTHROPIC_DEFAULT_SONNET_MODEL` | model the `sonnet` tier maps to |
196
+ | haiku → model | `ANTHROPIC_DEFAULT_HAIKU_MODEL` | model for `haiku`; **also used by background tasks** |
197
+ | effort | `CLAUDE_CODE_EFFORT_LEVEL` | thinking depth (see below) |
198
+
199
+ > ccx deliberately does **not** set `ANTHROPIC_MODEL` nor touch the `model` field in
200
+ > `settings.json`. Pick a tier live with `/model opus|sonnet|haiku`; the mapping translates
201
+ > it to the provider's model.
202
+
203
+ ## Model mapping & effort
204
+
205
+ Third-party APIs **must** have model mappings, because they only accept their own model
206
+ names while Claude Code defaults to `claude-*`. Background tasks use the `haiku` tier, so
207
+ **`haiku → model` must be set too** (otherwise background calls fail).
208
+
209
+ **effort:** `low < medium < high < xhigh < max`; higher = smarter but slower / more tokens;
210
+ `auto` = the model's default; empty = unset. effort is a Claude-model feature — whether a
211
+ third party honors it depends on its implementation.
212
+
213
+ | Profile | BASE_URL | OPUS / SONNET | HAIKU | effort |
214
+ |---|---|---|---|---|
215
+ | 官方 (official) | (empty = login) | — | — | empty / `auto` |
216
+ | DeepSeek | `https://api.deepseek.com/anthropic` | `deepseek-v4-pro` | `deepseek-v4-flash` | `max` (per their docs) |
217
+ | Zhipu GLM | `https://open.bigmodel.cn/api/anthropic` | `GLM-4.7` | `glm-4.5-air` | empty |
218
+ | Xiaomi MiMo | `https://api.xiaomimimo.com/anthropic` (pay-as-you-go)<br>`https://token-plan-cn.xiaomimimo.com/anthropic` (TokenPlan) | `mimo-v2.5-pro` | `mimo-v2.5-pro` | empty |
219
+
220
+ > Model names change as providers update; follow each provider's official docs.
221
+
222
+ ## Auth field: AUTH_TOKEN vs API_KEY
223
+
224
+ | Option | Actual header | Used by |
225
+ |---|---|---|
226
+ | `ANTHROPIC_AUTH_TOKEN` (default) | `Authorization: Bearer <key>` | most third-party relays |
227
+ | `ANTHROPIC_API_KEY` | `x-api-key: <key>` | official API and a few relays |
228
+
229
+ Some endpoints accept only one; the wrong one yields 401. Switch it in the Edit form;
230
+ ccx clears the other on switch to avoid conflicts.
231
+
232
+ ## Multiple accounts
233
+
234
+ For multiple accounts of the same vendor (e.g. personal vs work DeepSeek keys): **just
235
+ create multiple profiles**. Picking the same provider a second time auto-names it
236
+ `DeepSeek 2`; use the **Note** field to mark "personal / work". The list shows them as
237
+ "Provider — Note", easy to tell apart.
238
+
239
+ ## Maintaining the provider catalog
240
+
241
+ `presets.json` (ships with the tool) is the **provider catalog** — the "Provider" choices
242
+ when creating/editing a profile come from here. Add a provider, no code change. Each entry:
243
+
244
+ ```json
245
+ [
246
+ {
247
+ "name": "DeepSeek",
248
+ "auth": "AUTH_TOKEN",
249
+ "effort": "max",
250
+ "urls": [ { "label": "Anthropic-compatible", "url": "https://api.deepseek.com/anthropic" } ],
251
+ "models": { "opus": "deepseek-v4-pro", "sonnet": "deepseek-v4-pro", "haiku": "deepseek-v4-flash" }
252
+ }
253
+ ]
254
+ ```
255
+
256
+ - `urls` may contain **multiple** entries (e.g. a vendor splitting its API and TokenPlan
257
+ across different addresses) — you pick one when choosing that provider.
258
+ - `models` are the **recommended** opus/sonnet/haiku mappings, auto-filled on pick (still
259
+ editable afterwards).
260
+ - `auth` (`AUTH_TOKEN`/`API_KEY`) and `effort` are optional and carried over on pick.
261
+
262
+ The "API URL" pick list also **auto-collects** URLs already used in your `providers.json`
263
+ (tagged `(已有:name)`).
264
+
265
+ ## First run: skipping login / onboarding
266
+
267
+ With a third-party API (token auth) Claude Code may still show the login/onboarding screen
268
+ on first launch, because it hasn't recorded that onboarding is done. One-time fix: add
269
+ `"hasCompletedOnboarding": true` to `~/.claude.json`.
270
+
271
+ File location:
272
+
273
+ - Windows: `C:\Users\<you>\.claude.json`
274
+ - macOS / Linux: `~/.claude.json`
275
+
276
+ **Important: this file also holds your MCP config — only ADD the key, don't overwrite the
277
+ whole file.** If it doesn't exist, create it as `{ "hasCompletedOnboarding": true }`.
278
+
279
+ > ccx deliberately does **not** edit this file for you — it's exactly the file no tool
280
+ > should mess with. One-time step (some versions may need more; follow official docs).
281
+
282
+ ## Files & data
283
+
284
+ - Profiles (with keys, stored **in plaintext** locally — don't share): `~/.cc-mini/providers.json`
285
+ (also holds the UI `lang`).
286
+ - Provider catalog: the shipped `presets.json`; you can also drop a **custom catalog** at
287
+ `~/.cc-mini/presets.json` to override it (highest priority).
288
+ - "Set as default" writes **user environment variables** (not a Claude config file):
289
+ - **Windows** → registry `HKCU\Environment` + a single change broadcast;
290
+ - **macOS / Linux** → a `# >>> xx >>>` … `# <<< xx <<<` marker block in your shell startup
291
+ file (chosen by `$SHELL`: `~/.zshrc` / `~/.bash_profile` / `~/.bashrc` / `~/.profile`).
292
+ - Same semantics either way: **only affects newly opened terminals**; switching to "官方"
293
+ clears all managed variables.
294
+ - **No Claude config file is ever modified.**
295
+
296
+ ## FAQ
297
+
298
+ **Will switching in one terminal affect another running terminal?** No. "Use this session"
299
+ is per-process; "Set as default" writes user env vars that only apply to **newly started**
300
+ processes.
301
+
302
+ **I "set as default" but the current terminal still uses the old API.** Expected — open a
303
+ **new** terminal.
304
+
305
+ **I saw `... cannot be parsed as a URL`.** A profile's API URL was set to an invalid value;
306
+ fix or delete that profile in Edit.
307
+
308
+ **effort has no effect on a third party.** It's a Claude-model feature; third parties may
309
+ not support it. DeepSeek recommends `max`; leave others empty.
310
+
311
+ ## Uninstall
312
+
313
+ - **Clear env vars first**: run `xx` → Set as default → 官方 to clear all managed variables.
314
+ - Remove the tool itself:
315
+ - npm edition → `npm uninstall -g @cc-x/cc-x`;
316
+ - PowerShell edition → `Uninstall-Module ccx`, or delete the `# >>> xx >>>` … `# <<< xx <<<`
317
+ block from your `$PROFILE`;
318
+ - on macOS / Linux, also remove the `# >>> xx >>>` marker block from your shell startup file
319
+ if you ever used "Set as default".
320
+ - Delete the data dir `~/.cc-mini/`.
321
+
322
+ ## Philosophy
323
+
324
+ ccx was born out of my own friction using cc-switch. This isn't a criticism — cc-switch is
325
+ powerful and capable; I just wanted a lighter path.
326
+
327
+ So ccx follows a single principle: **the simpler, the better.**
328
+
329
+ - Do one thing — switch the API — and do it well;
330
+ - Touch as little as possible — above all, **never write Claude Code config files**
331
+ (`~/.claude/settings.json`, `~/.claude.json`);
332
+ - Before adding any feature, ask first: can we *not* add it?
333
+
334
+ Issues / PRs welcome. But remember: **a change that makes ccx simpler is more welcome than one
335
+ that makes it more powerful.** Any change that writes Claude Code config files will not be accepted.
336
+
337
+ ## License
338
+
339
+ [MIT](LICENSE)