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 openai/gpt-5.3-codex:high
38 cc-switch omp list
39 cc-switch omp use work # Switch and launch OMP
40 cc-switch omp remove work
41
42SHELL COMPLETION AND ALIASES:
43 cc-switch completion fish # Generates shell completions
44
45 Recommended aliases:
46 - cs='cc-switch' # Quick access to cc-switch
47 - cx='cc-switch codex' # Quick access to cc-switch codex
48 - co='cc-switch omp' # Quick access to cc-switch omp
49
50 Install permanently:
51 cc-switch completion fish > ~/.config/fish/completions/cc-switch.fish
52 echo \"alias cs='cc-switch'\" >> ~/.config/fish/config.fish
53 echo \"alias cx='cc-switch codex'\" >> ~/.config/fish/config.fish
54 echo \"alias co='cc-switch omp'\" >> ~/.config/fish/config.fish
55
56 Then use:
57 cs current # Instead of cc-switch current
58 cx use work # Instead of cc-switch codex use work
59 co use work # Instead of cc-switch omp use work"
60)]
61pub struct Cli {
62 #[command(subcommand)]
63 pub command: Option<Commands>,
64
65 #[arg(long = "list-aliases", hide = true)]
67 pub list_aliases: bool,
68
69 #[arg(long = "list-codex-aliases", hide = true)]
71 pub list_codex_aliases: bool,
72 #[arg(long = "list-omp-aliases", hide = true)]
74 pub list_omp_aliases: bool,
75
76 #[arg(
78 long = "migrate",
79 help = "Migrate old config path to new path and exit"
80 )]
81 pub migrate: bool,
82
83 #[arg(
85 long = "store",
86 help = "Storage mode for writing configuration (env: write to env field, config: write to root with camelCase)",
87 global = true
88 )]
89 pub store: Option<String>,
90}
91
92#[derive(Subcommand)]
94#[allow(clippy::large_enum_variant)]
95pub enum Commands {
96 Add {
100 #[arg(help = "Configuration alias name (cannot be 'cc')")]
102 alias_name: String,
103
104 #[arg(
106 long = "token",
107 short = 't',
108 help = "API token (ANTHROPIC_AUTH_TOKEN, mutually exclusive with --api-key)"
109 )]
110 token: Option<String>,
111
112 #[arg(
114 long = "api-key",
115 short = 'k',
116 help = "API key (ANTHROPIC_API_KEY, mutually exclusive with --token)"
117 )]
118 api_key: Option<String>,
119
120 #[arg(
122 long = "url",
123 short = 'u',
124 help = "API endpoint URL (optional if not using interactive mode)"
125 )]
126 url: Option<String>,
127
128 #[arg(long = "model", short = 'm', help = "Custom model name (optional)")]
130 model: Option<String>,
131
132 #[arg(
134 long = "small-fast-model",
135 help = "Haiku-class model for background tasks (optional)"
136 )]
137 small_fast_model: Option<String>,
138
139 #[arg(
141 long = "max-thinking-tokens",
142 help = "Maximum thinking tokens limit (optional)"
143 )]
144 max_thinking_tokens: Option<u32>,
145
146 #[arg(
148 long = "api-timeout-ms",
149 help = "API timeout in milliseconds (optional)"
150 )]
151 api_timeout_ms: Option<u32>,
152
153 #[arg(
155 long = "disable-nonessential-traffic",
156 help = "Disable non-essential traffic flag (optional)"
157 )]
158 claude_code_disable_nonessential_traffic: Option<u32>,
159
160 #[arg(
162 long = "default-sonnet-model",
163 help = "Default Sonnet model name (optional)"
164 )]
165 anthropic_default_sonnet_model: Option<String>,
166
167 #[arg(
169 long = "default-opus-model",
170 help = "Default Opus model name (optional)"
171 )]
172 anthropic_default_opus_model: Option<String>,
173
174 #[arg(
176 long = "default-haiku-model",
177 help = "Default Haiku model name (optional)"
178 )]
179 anthropic_default_haiku_model: Option<String>,
180
181 #[arg(long = "subagent-model", help = "Subagent model name (optional)")]
183 claude_code_subagent_model: Option<String>,
184
185 #[arg(
187 long = "disable-nonstreaming-fallback",
188 help = "Disable non-streaming fallback flag (optional)"
189 )]
190 claude_code_disable_nonstreaming_fallback: Option<u32>,
191
192 #[arg(
194 long = "effort-level",
195 help = "Effort level for Claude Code (optional, e.g., 'max')"
196 )]
197 claude_code_effort_level: Option<String>,
198
199 #[arg(
201 long = "disable-prompt-caching",
202 help = "Disable prompt caching flag (optional)"
203 )]
204 disable_prompt_caching: Option<u32>,
205
206 #[arg(
208 long = "disable-experimental-betas",
209 help = "Disable experimental betas flag (optional)"
210 )]
211 claude_code_disable_experimental_betas: Option<u32>,
212
213 #[arg(
215 long = "disable-autoupdater",
216 help = "Disable auto-updater flag (optional)"
217 )]
218 disable_autoupdater: Option<u32>,
219
220 #[arg(
222 long = "force",
223 short = 'f',
224 help = "Overwrite existing configuration with same alias"
225 )]
226 force: bool,
227
228 #[arg(
230 long = "interactive",
231 short = 'i',
232 help = "Enter configuration values interactively"
233 )]
234 interactive: bool,
235
236 #[arg(help = "API token (if not using -t flag)")]
238 token_arg: Option<String>,
239
240 #[arg(help = "API endpoint URL (if not using -u flag)")]
242 url_arg: Option<String>,
243
244 #[arg(
249 long = "from-file",
250 num_args = 0..=1,
251 value_name = "PATH",
252 help = "Import configuration from JSON file (defaults to ~/.claude/settings.json if no path)"
253 )]
254 from_file: Option<Option<String>>,
255 },
256 Remove {
260 #[arg(required = true)]
262 alias_names: Vec<String>,
263 },
264 List {
268 #[arg(long = "plain", short = 'p')]
270 plain: bool,
271 #[arg(long = "name", short = 'n')]
273 name: bool,
274 },
275 #[command(alias = "C")]
279 Completion {
280 #[arg(default_value = "fish")]
282 shell: String,
283 },
284 #[command(trailing_var_arg = true)]
291 Use {
292 alias_name: String,
294
295 #[arg(long, short = 'r')]
297 resume: Option<String>,
298
299 #[arg(long, short = 'c')]
301 r#continue: bool,
302
303 #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
305 prompt: Vec<String>,
306 },
307 Codex {
309 #[command(subcommand)]
310 command: Option<CodexCommands>,
311 },
312 Omp {
314 #[command(subcommand)]
315 command: Option<OmpCommands>,
316 },
317 #[command(name = "statusline")]
326 Statusline {
327 #[arg(value_enum, default_value = "install")]
329 action: StatuslineAction,
330 },
331}
332
333#[derive(Clone, Copy, clap::ValueEnum)]
335pub enum StatuslineAction {
336 Install,
338 Uninstall,
340}
341
342#[derive(Subcommand)]
344pub enum CodexCommands {
345 Add {
347 #[arg(help = "Configuration alias name")]
348 alias_name: String,
349 #[arg(long = "api-key", help = "OpenAI API key (optional)")]
350 api_key: Option<String>,
351 #[arg(long = "force", short = 'f', help = "Overwrite existing configuration")]
352 force: bool,
353 #[arg(
354 long = "interactive",
355 short = 'i',
356 help = "Enter configuration values interactively"
357 )]
358 interactive: bool,
359 #[arg(
364 long = "from-file",
365 num_args = 0..=1,
366 value_name = "PATH",
367 help = "Import from auth.json (defaults to ~/.codex/auth.json if no path)"
368 )]
369 from_file: Option<Option<String>>,
370 },
371 List {
372 #[arg(long = "plain", short = 'p')]
373 plain: bool,
374 #[arg(long = "name", short = 'n', help = "Show only name and auth mode")]
375 name: bool,
376 },
377 #[command(trailing_var_arg = true)]
378 Use {
379 alias_name: String,
380 #[arg(long = "continue", short = 'c')]
381 r#continue: bool,
382 #[arg(long = "resume", short = 'r')]
383 resume: Option<String>,
384 #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
385 prompt: Vec<String>,
386 },
387 Remove {
388 #[arg(required = true)]
389 alias_names: Vec<String>,
390 },
391}
392#[derive(Subcommand)]
394pub enum OmpCommands {
395 Add {
397 #[arg(help = "Configuration alias name")]
398 alias_name: String,
399 #[arg(long = "api-key", help = "API key (Anthropic or OpenAI)")]
400 api_key: Option<String>,
401 #[arg(long = "force", short = 'f', help = "Overwrite existing configuration")]
402 force: bool,
403 #[arg(
404 long = "interactive",
405 short = 'i',
406 help = "Enter configuration values interactively"
407 )]
408 interactive: bool,
409 #[arg(
414 long = "from-file",
415 num_args = 0..=1,
416 value_name = "PATH",
417 help = "Import from .env file (defaults to ~/.omp/agent/.env if no path)"
418 )]
419 from_file: Option<Option<String>>,
420 #[arg(
421 long = "base-url",
422 help = "ANTHROPIC_BASE_URL value (for Anthropic-compatible endpoints)"
423 )]
424 base_url: Option<String>,
425 #[arg(long = "slow-model", help = "PI_SLOW_MODEL value (optional)")]
426 slow_model: Option<String>,
427 #[arg(long = "smol-model", help = "PI_SMOL_MODEL value (optional)")]
428 smol_model: Option<String>,
429 #[arg(long = "plan-model", help = "PI_PLAN_MODEL value (optional)")]
430 plan_model: Option<String>,
431 },
432 List {
433 #[arg(long = "plain", short = 'p')]
434 plain: bool,
435 #[arg(long = "name", short = 'n', help = "Show only name and auth mode")]
436 name: bool,
437 },
438 #[command(trailing_var_arg = true)]
439 Use {
440 alias_name: String,
441 #[arg(long = "continue", short = 'c')]
442 r#continue: bool,
443 #[arg(long = "resume", short = 'r')]
444 resume: Option<String>,
445 #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
446 prompt: Vec<String>,
447 },
448 Remove {
449 #[arg(required = true)]
450 alias_names: Vec<String>,
451 },
452}