1use clap::{Parser, Subcommand};
2
3#[derive(Parser)]
5#[command(name = "cc-switch")]
6#[command(about = "A CLI tool for managing Claude API configurations")]
7#[command(version)]
8#[command(disable_help_subcommand = true)]
9#[command(
10 long_about = "cc-switch helps you manage multiple Claude API configurations and switch between them easily.
11
12EXAMPLES:
13 cc-switch add my-config sk-ant-xxx https://api.anthropic.com
14 cc-switch add my-config -t sk-ant-xxx -u https://api.anthropic.com
15 cc-switch add my-config -t sk-ant-xxx -u https://api.anthropic.com -m claude-3-5-sonnet-20241022
16 cc-switch add my-config -t sk-ant-xxx -u https://api.anthropic.com --small-fast-model claude-3-haiku-20240307
17 cc-switch add my-config -t sk-ant-xxx -u https://api.anthropic.com --max-thinking-tokens 8192
18 cc-switch add my-config -i # Interactive mode
19 cc-switch add my-config --from-file # Import from ~/.claude/settings.json
20 cc-switch add my-config --from-file ./other.json # Import from an explicit JSON file
21 cc-switch add my-config --force # Overwrite existing config
22 cc-switch list
23 cc-switch remove config1 config2 config3
24 cc-switch current # Interactive mode to view and switch configurations
25 cc-switch # Enter interactive mode (same as 'current' without arguments)
26
27CODEX CONFIGURATIONS:
28 cc-switch codex add work --from-file # Import from ~/.codex/auth.json
29 cc-switch codex add work --from-file ~/other/auth.json # Import from an explicit path
30 cc-switch codex add personal -i # Interactive mode
31 cc-switch codex list
32 cc-switch codex use work # Switch and launch Codex
33OMP CONFIGURATIONS:
34 cc-switch omp add work --from-file # Import from ~/.omp/agent/.env
35 cc-switch omp add work --from-file ~/other/.env # Import from an explicit path
36 cc-switch omp add personal -i # Interactive mode
37 cc-switch omp add gpt --api-key sk-... --slow-model gpt-5.3-codex
38 cc-switch omp add gw --api-key sk-... --base-url https://api.example.com/v1 --slow-model gpt-4o # OpenAI-compatible gateway
39 cc-switch omp list
40 cc-switch omp use work # Switch and launch OMP
41 cc-switch omp remove work
42
43GROK CONFIGURATIONS:
44 cc-switch grok add opus --model claude-opus-4-6 --base-url https://api.anthropic.com/v1 --api-backend messages --header x-api-key=sk-ant-...
45 cc-switch grok add gpt --model gpt-4o --base-url https://api.openai.com/v1 --env-key OPENAI_API_KEY
46 cc-switch grok add work --from-file # Import a [model.work] entry from ~/.grok/config.toml
47 cc-switch grok add personal -i # Interactive mode
48 cc-switch grok list
49 cc-switch grok use opus # Switch default model and launch grok
50 cc-switch grok remove opus
51
52SHELL COMPLETION AND ALIASES:
53 cc-switch completion fish # Generates shell completions
54
55 Recommended aliases:
56 - cs='cc-switch' # Quick access to cc-switch
57 - cx='cc-switch codex' # Quick access to cc-switch codex
58 - co='cc-switch omp' # Quick access to cc-switch omp
59 - cg='cc-switch grok' # Quick access to cc-switch grok
60
61 Install permanently:
62 cc-switch completion fish > ~/.config/fish/completions/cc-switch.fish
63 echo \"alias cs='cc-switch'\" >> ~/.config/fish/config.fish
64 echo \"alias cx='cc-switch codex'\" >> ~/.config/fish/config.fish
65 echo \"alias co='cc-switch omp'\" >> ~/.config/fish/config.fish
66 echo \"alias cg='cc-switch grok'\" >> ~/.config/fish/config.fish
67
68 Then use:
69 cs current # Instead of cc-switch current
70 cx use work # Instead of cc-switch codex use work
71 co use work # Instead of cc-switch omp use work
72 cg use opus # Instead of cc-switch grok use opus"
73)]
74pub struct Cli {
75 #[command(subcommand)]
76 pub command: Option<Commands>,
77
78 #[arg(long = "list-aliases", hide = true)]
80 pub list_aliases: bool,
81
82 #[arg(long = "list-codex-aliases", hide = true)]
84 pub list_codex_aliases: bool,
85 #[arg(long = "list-omp-aliases", hide = true)]
87 pub list_omp_aliases: bool,
88 #[arg(long = "list-grok-aliases", hide = true)]
90 pub list_grok_aliases: bool,
91
92 #[arg(
94 long = "migrate",
95 help = "Migrate old config path to new path and exit"
96 )]
97 pub migrate: bool,
98
99 #[arg(
101 long = "store",
102 help = "Storage mode for writing configuration (env: write to env field, config: write to root with camelCase)",
103 global = true
104 )]
105 pub store: Option<String>,
106}
107
108#[derive(Subcommand)]
110#[allow(clippy::large_enum_variant)]
111pub enum Commands {
112 Add {
116 #[arg(help = "Configuration alias name (cannot be 'cc')")]
118 alias_name: String,
119
120 #[arg(
122 long = "token",
123 short = 't',
124 help = "API token (ANTHROPIC_AUTH_TOKEN, mutually exclusive with --api-key)"
125 )]
126 token: Option<String>,
127
128 #[arg(
130 long = "api-key",
131 short = 'k',
132 help = "API key (ANTHROPIC_API_KEY, mutually exclusive with --token)"
133 )]
134 api_key: Option<String>,
135
136 #[arg(
138 long = "url",
139 short = 'u',
140 help = "API endpoint URL (optional if not using interactive mode)"
141 )]
142 url: Option<String>,
143
144 #[arg(long = "model", short = 'm', help = "Custom model name (optional)")]
146 model: Option<String>,
147
148 #[arg(
150 long = "small-fast-model",
151 help = "Haiku-class model for background tasks (optional)"
152 )]
153 small_fast_model: Option<String>,
154
155 #[arg(
157 long = "max-thinking-tokens",
158 help = "Maximum thinking tokens limit (optional)"
159 )]
160 max_thinking_tokens: Option<u32>,
161
162 #[arg(
164 long = "api-timeout-ms",
165 help = "API timeout in milliseconds (optional)"
166 )]
167 api_timeout_ms: Option<u32>,
168
169 #[arg(
171 long = "disable-nonessential-traffic",
172 help = "Disable non-essential traffic flag (optional)"
173 )]
174 claude_code_disable_nonessential_traffic: Option<u32>,
175
176 #[arg(
178 long = "default-sonnet-model",
179 help = "Default Sonnet model name (optional)"
180 )]
181 anthropic_default_sonnet_model: Option<String>,
182
183 #[arg(
185 long = "default-opus-model",
186 help = "Default Opus model name (optional)"
187 )]
188 anthropic_default_opus_model: Option<String>,
189
190 #[arg(
192 long = "default-haiku-model",
193 help = "Default Haiku model name (optional)"
194 )]
195 anthropic_default_haiku_model: Option<String>,
196
197 #[arg(long = "subagent-model", help = "Subagent model name (optional)")]
199 claude_code_subagent_model: Option<String>,
200
201 #[arg(
203 long = "disable-nonstreaming-fallback",
204 help = "Disable non-streaming fallback flag (optional)"
205 )]
206 claude_code_disable_nonstreaming_fallback: Option<u32>,
207
208 #[arg(
210 long = "effort-level",
211 help = "Effort level for Claude Code (optional, e.g., 'max')"
212 )]
213 claude_code_effort_level: Option<String>,
214
215 #[arg(
217 long = "auto-compact-window",
218 help = "Auto compact window size for Claude Code (optional, e.g., '950000')"
219 )]
220 claude_code_auto_compact_window: Option<String>,
221
222 #[arg(
224 long = "disable-prompt-caching",
225 help = "Disable prompt caching flag (optional)"
226 )]
227 disable_prompt_caching: Option<u32>,
228
229 #[arg(
231 long = "disable-experimental-betas",
232 help = "Disable experimental betas flag (optional)"
233 )]
234 claude_code_disable_experimental_betas: Option<u32>,
235
236 #[arg(
238 long = "disable-autoupdater",
239 help = "Disable auto-updater flag (optional)"
240 )]
241 disable_autoupdater: Option<u32>,
242
243 #[arg(
245 long = "force",
246 short = 'f',
247 help = "Overwrite existing configuration with same alias"
248 )]
249 force: bool,
250
251 #[arg(
253 long = "interactive",
254 short = 'i',
255 help = "Enter configuration values interactively"
256 )]
257 interactive: bool,
258
259 #[arg(help = "API token (if not using -t flag)")]
261 token_arg: Option<String>,
262
263 #[arg(help = "API endpoint URL (if not using -u flag)")]
265 url_arg: Option<String>,
266
267 #[arg(
272 long = "from-file",
273 num_args = 0..=1,
274 value_name = "PATH",
275 help = "Import configuration from JSON file (defaults to ~/.claude/settings.json if no path)"
276 )]
277 from_file: Option<Option<String>>,
278
279 #[arg(
283 long = "from-json",
284 value_name = "TEXT",
285 help = "Import configuration from JSON/text string containing env vars"
286 )]
287 from_json: Option<String>,
288
289 #[arg(
293 long = "from-stdin",
294 help = "Import configuration from piped stdin input"
295 )]
296 from_stdin: bool,
297 },
298 Remove {
302 #[arg(required = true)]
304 alias_names: Vec<String>,
305 },
306 List {
310 #[arg(long = "plain", short = 'p')]
312 plain: bool,
313 #[arg(long = "name", short = 'n')]
315 name: bool,
316 },
317 #[command(alias = "C")]
321 Completion {
322 #[arg(default_value = "fish")]
324 shell: String,
325 },
326 #[command(trailing_var_arg = true)]
333 Use {
334 alias_name: String,
336
337 #[arg(long, short = 'r')]
339 resume: Option<String>,
340
341 #[arg(long, short = 'c')]
343 r#continue: bool,
344
345 #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
347 prompt: Vec<String>,
348 },
349 Codex {
351 #[command(subcommand)]
352 command: Option<CodexCommands>,
353 },
354 Omp {
356 #[command(subcommand)]
357 command: Option<OmpCommands>,
358 },
359 Grok {
361 #[command(subcommand)]
362 command: Option<GrokCommands>,
363 },
364 #[command(name = "statusline")]
373 Statusline {
374 #[arg(value_enum, default_value = "install")]
376 action: StatuslineAction,
377 },
378}
379
380#[derive(Clone, Copy, clap::ValueEnum)]
382pub enum StatuslineAction {
383 Install,
385 Uninstall,
387}
388
389#[derive(Subcommand)]
391pub enum CodexCommands {
392 Add {
394 #[arg(help = "Configuration alias name")]
395 alias_name: String,
396 #[arg(long = "api-key", help = "OpenAI API key (optional)")]
397 api_key: Option<String>,
398 #[arg(long = "force", short = 'f', help = "Overwrite existing configuration")]
399 force: bool,
400 #[arg(
401 long = "interactive",
402 short = 'i',
403 help = "Enter configuration values interactively"
404 )]
405 interactive: bool,
406 #[arg(
411 long = "from-file",
412 num_args = 0..=1,
413 value_name = "PATH",
414 help = "Import from auth.json (defaults to ~/.codex/auth.json if no path)"
415 )]
416 from_file: Option<Option<String>>,
417 },
418 List {
419 #[arg(long = "plain", short = 'p')]
420 plain: bool,
421 #[arg(long = "name", short = 'n', help = "Show only name and auth mode")]
422 name: bool,
423 },
424 #[command(trailing_var_arg = true)]
425 Use {
426 alias_name: String,
427 #[arg(long = "continue", short = 'c')]
428 r#continue: bool,
429 #[arg(long = "resume", short = 'r')]
430 resume: Option<String>,
431 #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
432 prompt: Vec<String>,
433 },
434 Remove {
435 #[arg(required = true)]
436 alias_names: Vec<String>,
437 },
438}
439#[derive(Subcommand)]
441pub enum OmpCommands {
442 Add {
444 #[arg(help = "Configuration alias name")]
445 alias_name: String,
446 #[arg(long = "api-key", help = "OpenAI API key")]
447 api_key: Option<String>,
448 #[arg(long = "force", short = 'f', help = "Overwrite existing configuration")]
449 force: bool,
450 #[arg(
451 long = "interactive",
452 short = 'i',
453 help = "Enter configuration values interactively"
454 )]
455 interactive: bool,
456 #[arg(
461 long = "from-file",
462 num_args = 0..=1,
463 value_name = "PATH",
464 help = "Import from .env file (defaults to ~/.omp/agent/.env if no path)"
465 )]
466 from_file: Option<Option<String>>,
467 #[arg(
468 long = "base-url",
469 help = "ANTHROPIC_BASE_URL value (for Anthropic-compatible endpoints)"
470 )]
471 base_url: Option<String>,
472 #[arg(long = "slow-model", help = "PI_SLOW_MODEL value (optional)")]
473 slow_model: Option<String>,
474 #[arg(long = "smol-model", help = "PI_SMOL_MODEL value (optional)")]
475 smol_model: Option<String>,
476 #[arg(long = "plan-model", help = "PI_PLAN_MODEL value (optional)")]
477 plan_model: Option<String>,
478 },
479 List {
480 #[arg(long = "plain", short = 'p')]
481 plain: bool,
482 #[arg(long = "name", short = 'n', help = "Show only name and auth mode")]
483 name: bool,
484 },
485 #[command(trailing_var_arg = true)]
486 Use {
487 alias_name: String,
488 #[arg(long = "continue", short = 'c')]
489 r#continue: bool,
490 #[arg(long = "resume", short = 'r')]
491 resume: Option<String>,
492 #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
493 prompt: Vec<String>,
494 },
495 Remove {
496 #[arg(required = true)]
497 alias_names: Vec<String>,
498 },
499}
500
501#[derive(Subcommand)]
503pub enum GrokCommands {
504 Add {
506 #[arg(help = "Configuration alias name (used as the [model.<alias>] id)")]
507 alias_name: String,
508 #[arg(long = "model", help = "Underlying model id (e.g. claude-opus-4-6)")]
509 model: Option<String>,
510 #[arg(long = "base-url", help = "API endpoint base URL")]
511 base_url: Option<String>,
512 #[arg(long = "name", help = "Human-friendly display name")]
513 name: Option<String>,
514 #[arg(
515 long = "api-backend",
516 help = "API backend: chat_completions | responses | messages"
517 )]
518 api_backend: Option<String>,
519 #[arg(long = "context-window", help = "Context window size")]
520 context_window: Option<u32>,
521 #[arg(
522 long = "api-key",
523 help = "API key written directly to config (optional)"
524 )]
525 api_key: Option<String>,
526 #[arg(
527 long = "env-key",
528 help = "Environment variable name to read the key from (repeatable)"
529 )]
530 env_key: Vec<String>,
531 #[arg(
532 long = "header",
533 value_name = "KEY=VALUE",
534 help = "Extra HTTP header for the model, e.g. x-api-key=sk-ant-... (repeatable)"
535 )]
536 header: Vec<String>,
537 #[arg(long = "force", short = 'f', help = "Overwrite existing configuration")]
538 force: bool,
539 #[arg(
540 long = "interactive",
541 short = 'i',
542 help = "Enter configuration values interactively"
543 )]
544 interactive: bool,
545 #[arg(
550 long = "from-file",
551 num_args = 0..=1,
552 value_name = "PATH",
553 help = "Import from config.toml (defaults to ~/.grok/config.toml if no path)"
554 )]
555 from_file: Option<Option<String>>,
556 },
557 List {
558 #[arg(long = "plain", short = 'p')]
559 plain: bool,
560 #[arg(long = "name", short = 'n', help = "Show only alias name and model")]
561 name: bool,
562 },
563 #[command(trailing_var_arg = true)]
564 Use {
565 alias_name: String,
566 #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
567 prompt: Vec<String>,
568 },
569 Remove {
570 #[arg(required = true)]
571 alias_names: Vec<String>,
572 },
573}