use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "cc-switch")]
#[command(about = "A CLI tool for managing Claude API configurations")]
#[command(version)]
#[command(disable_help_subcommand = true)]
#[command(
long_about = "cc-switch helps you manage multiple Claude API configurations and switch between them easily.
EXAMPLES:
cc-switch add my-config sk-ant-xxx https://api.anthropic.com
cc-switch add my-config -t sk-ant-xxx -u https://api.anthropic.com
cc-switch add my-config -t sk-ant-xxx -u https://api.anthropic.com -m claude-3-5-sonnet-20241022
cc-switch add my-config -t sk-ant-xxx -u https://api.anthropic.com --small-fast-model claude-3-haiku-20240307
cc-switch add my-config -t sk-ant-xxx -u https://api.anthropic.com --max-thinking-tokens 8192
cc-switch add my-config -i # Interactive mode
cc-switch add my-config --force # Overwrite existing config
cc-switch list
cc-switch remove config1 config2 config3
cc-switch current # Interactive mode to view and switch configurations
cc-switch # Enter interactive mode (same as 'current' without arguments)
SHELL COMPLETION AND ALIASES:
cc-switch completion fish # Generates shell completions
cc-switch alias fish # Generates aliases for eval
These aliases are available:
- cs='cc-switch' # Quick access to cc-switch
- ccd='claude --dangerously-skip-permissions' # Quick Claude launch
To use aliases immediately:
eval \"$(cc-switch alias fish)\" # Add aliases to current session
Or add them permanently:
cc-switch completion fish > ~/.config/fish/completions/cc-switch.fish
echo \"alias cs='cc-switch'\" >> ~/.config/fish/config.fish
echo \"alias ccd='claude --dangerously-skip-permissions'\" >> ~/.config/fish/config.fish
Then use:
cs current # Instead of cc-switch current
ccd # Quick Claude launch"
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
#[arg(long = "list-aliases", hide = true)]
pub list_aliases: bool,
#[arg(
long = "migrate",
help = "Migrate old config path to new path and exit"
)]
pub migrate: bool,
#[arg(
long = "store",
help = "Storage mode for writing configuration (env: write to env field, config: write to root with camelCase)",
global = true
)]
pub store: Option<String>,
}
#[derive(Subcommand)]
#[allow(clippy::large_enum_variant)]
pub enum Commands {
Add {
#[arg(
help = "Configuration alias name (cannot be 'cc')",
required_unless_present = "from_file"
)]
alias_name: Option<String>,
#[arg(
long = "token",
short = 't',
help = "API token (optional if not using interactive mode)"
)]
token: Option<String>,
#[arg(
long = "url",
short = 'u',
help = "API endpoint URL (optional if not using interactive mode)"
)]
url: Option<String>,
#[arg(long = "model", short = 'm', help = "Custom model name (optional)")]
model: Option<String>,
#[arg(
long = "small-fast-model",
help = "Haiku-class model for background tasks (optional)"
)]
small_fast_model: Option<String>,
#[arg(
long = "max-thinking-tokens",
help = "Maximum thinking tokens limit (optional)"
)]
max_thinking_tokens: Option<u32>,
#[arg(
long = "api-timeout-ms",
help = "API timeout in milliseconds (optional)"
)]
api_timeout_ms: Option<u32>,
#[arg(
long = "disable-nonessential-traffic",
help = "Disable non-essential traffic flag (optional)"
)]
claude_code_disable_nonessential_traffic: Option<u32>,
#[arg(
long = "default-sonnet-model",
help = "Default Sonnet model name (optional)"
)]
anthropic_default_sonnet_model: Option<String>,
#[arg(
long = "default-opus-model",
help = "Default Opus model name (optional)"
)]
anthropic_default_opus_model: Option<String>,
#[arg(
long = "default-haiku-model",
help = "Default Haiku model name (optional)"
)]
anthropic_default_haiku_model: Option<String>,
#[arg(
long = "subagent-model",
help = "Subagent model name (optional)"
)]
claude_code_subagent_model: Option<String>,
#[arg(
long = "disable-nonstreaming-fallback",
help = "Disable non-streaming fallback flag (optional)"
)]
claude_code_disable_nonstreaming_fallback: Option<u32>,
#[arg(
long = "effort-level",
help = "Effort level for Claude Code (optional, e.g., 'max')"
)]
claude_code_effort_level: Option<String>,
#[arg(
long = "force",
short = 'f',
help = "Overwrite existing configuration with same alias"
)]
force: bool,
#[arg(
long = "interactive",
short = 'i',
help = "Enter configuration values interactively"
)]
interactive: bool,
#[arg(help = "API token (if not using -t flag)")]
token_arg: Option<String>,
#[arg(help = "API endpoint URL (if not using -u flag)")]
url_arg: Option<String>,
#[arg(
long = "from-file",
short = 'j',
help = "Import configuration from a JSON file (filename becomes alias name)"
)]
from_file: Option<String>,
},
Remove {
#[arg(required = true)]
alias_names: Vec<String>,
},
List {
#[arg(long = "plain", short = 'p')]
plain: bool,
},
#[command(alias = "C")]
Completion {
#[arg(default_value = "fish")]
shell: String,
},
#[command(trailing_var_arg = true)]
Use {
alias_name: String,
#[arg(long, short = 'r')]
resume: Option<String>,
#[arg(long, short = 'c')]
r#continue: bool,
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
prompt: Vec<String>,
},
}