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 --from-file # Import from ~/.claude/settings.json
cc-switch add my-config --from-file ./other.json # Import from an explicit JSON file
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)
CODEX CONFIGURATIONS:
cc-switch codex add work --from-file # Import from ~/.codex/auth.json
cc-switch codex add work --from-file ~/other/auth.json # Import from an explicit path
cc-switch codex add personal -i # Interactive mode
cc-switch codex list
cc-switch codex use work # Switch and launch Codex
OMP CONFIGURATIONS:
cc-switch omp add work --from-file # Import from ~/.omp/agent/.env
cc-switch omp add work --from-file ~/other/.env # Import from an explicit path
cc-switch omp add personal -i # Interactive mode
cc-switch omp add gpt --api-key sk-... --slow-model gpt-5.3-codex
cc-switch omp add gw --api-key sk-... --base-url https://api.example.com/v1 --slow-model gpt-4o # OpenAI-compatible gateway
cc-switch omp list
cc-switch omp use work # Switch and launch OMP
cc-switch omp remove work
GROK CONFIGURATIONS:
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-...
cc-switch grok add gpt --model gpt-4o --base-url https://api.openai.com/v1 --env-key OPENAI_API_KEY
cc-switch grok add work --from-file # Import a [model.work] entry from ~/.grok/config.toml
cc-switch grok add personal -i # Interactive mode
cc-switch grok list
cc-switch grok use opus # Switch default model and launch grok
cc-switch grok remove opus
SHELL COMPLETION AND ALIASES:
cc-switch completion fish # Generates shell completions
Recommended aliases:
- cs='cc-switch' # Quick access to cc-switch
- cx='cc-switch codex' # Quick access to cc-switch codex
- co='cc-switch omp' # Quick access to cc-switch omp
- cg='cc-switch grok' # Quick access to cc-switch grok
Install permanently:
cc-switch completion fish > ~/.config/fish/completions/cc-switch.fish
echo \"alias cs='cc-switch'\" >> ~/.config/fish/config.fish
echo \"alias cx='cc-switch codex'\" >> ~/.config/fish/config.fish
echo \"alias co='cc-switch omp'\" >> ~/.config/fish/config.fish
echo \"alias cg='cc-switch grok'\" >> ~/.config/fish/config.fish
Then use:
cs current # Instead of cc-switch current
cx use work # Instead of cc-switch codex use work
co use work # Instead of cc-switch omp use work
cg use opus # Instead of cc-switch grok use opus"
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
#[arg(long = "list-aliases", hide = true)]
pub list_aliases: bool,
#[arg(long = "list-codex-aliases", hide = true)]
pub list_codex_aliases: bool,
#[arg(long = "list-omp-aliases", hide = true)]
pub list_omp_aliases: bool,
#[arg(long = "list-grok-aliases", hide = true)]
pub list_grok_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')")]
alias_name: String,
#[arg(
long = "token",
short = 't',
help = "API token (ANTHROPIC_AUTH_TOKEN, mutually exclusive with --api-key)"
)]
token: Option<String>,
#[arg(
long = "api-key",
short = 'k',
help = "API key (ANTHROPIC_API_KEY, mutually exclusive with --token)"
)]
api_key: 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 = "disable-prompt-caching",
help = "Disable prompt caching flag (optional)"
)]
disable_prompt_caching: Option<u32>,
#[arg(
long = "disable-experimental-betas",
help = "Disable experimental betas flag (optional)"
)]
claude_code_disable_experimental_betas: Option<u32>,
#[arg(
long = "disable-autoupdater",
help = "Disable auto-updater flag (optional)"
)]
disable_autoupdater: Option<u32>,
#[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",
num_args = 0..=1,
value_name = "PATH",
help = "Import configuration from JSON file (defaults to ~/.claude/settings.json if no path)"
)]
from_file: Option<Option<String>>,
},
Remove {
#[arg(required = true)]
alias_names: Vec<String>,
},
List {
#[arg(long = "plain", short = 'p')]
plain: bool,
#[arg(long = "name", short = 'n')]
name: 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>,
},
Codex {
#[command(subcommand)]
command: Option<CodexCommands>,
},
Omp {
#[command(subcommand)]
command: Option<OmpCommands>,
},
Grok {
#[command(subcommand)]
command: Option<GrokCommands>,
},
#[command(name = "statusline")]
Statusline {
#[arg(value_enum, default_value = "install")]
action: StatuslineAction,
},
}
#[derive(Clone, Copy, clap::ValueEnum)]
pub enum StatuslineAction {
Install,
Uninstall,
}
#[derive(Subcommand)]
pub enum CodexCommands {
Add {
#[arg(help = "Configuration alias name")]
alias_name: String,
#[arg(long = "api-key", help = "OpenAI API key (optional)")]
api_key: Option<String>,
#[arg(long = "force", short = 'f', help = "Overwrite existing configuration")]
force: bool,
#[arg(
long = "interactive",
short = 'i',
help = "Enter configuration values interactively"
)]
interactive: bool,
#[arg(
long = "from-file",
num_args = 0..=1,
value_name = "PATH",
help = "Import from auth.json (defaults to ~/.codex/auth.json if no path)"
)]
from_file: Option<Option<String>>,
},
List {
#[arg(long = "plain", short = 'p')]
plain: bool,
#[arg(long = "name", short = 'n', help = "Show only name and auth mode")]
name: bool,
},
#[command(trailing_var_arg = true)]
Use {
alias_name: String,
#[arg(long = "continue", short = 'c')]
r#continue: bool,
#[arg(long = "resume", short = 'r')]
resume: Option<String>,
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
prompt: Vec<String>,
},
Remove {
#[arg(required = true)]
alias_names: Vec<String>,
},
}
#[derive(Subcommand)]
pub enum OmpCommands {
Add {
#[arg(help = "Configuration alias name")]
alias_name: String,
#[arg(long = "api-key", help = "OpenAI API key")]
api_key: Option<String>,
#[arg(long = "force", short = 'f', help = "Overwrite existing configuration")]
force: bool,
#[arg(
long = "interactive",
short = 'i',
help = "Enter configuration values interactively"
)]
interactive: bool,
#[arg(
long = "from-file",
num_args = 0..=1,
value_name = "PATH",
help = "Import from .env file (defaults to ~/.omp/agent/.env if no path)"
)]
from_file: Option<Option<String>>,
#[arg(
long = "base-url",
help = "ANTHROPIC_BASE_URL value (for Anthropic-compatible endpoints)"
)]
base_url: Option<String>,
#[arg(long = "slow-model", help = "PI_SLOW_MODEL value (optional)")]
slow_model: Option<String>,
#[arg(long = "smol-model", help = "PI_SMOL_MODEL value (optional)")]
smol_model: Option<String>,
#[arg(long = "plan-model", help = "PI_PLAN_MODEL value (optional)")]
plan_model: Option<String>,
},
List {
#[arg(long = "plain", short = 'p')]
plain: bool,
#[arg(long = "name", short = 'n', help = "Show only name and auth mode")]
name: bool,
},
#[command(trailing_var_arg = true)]
Use {
alias_name: String,
#[arg(long = "continue", short = 'c')]
r#continue: bool,
#[arg(long = "resume", short = 'r')]
resume: Option<String>,
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
prompt: Vec<String>,
},
Remove {
#[arg(required = true)]
alias_names: Vec<String>,
},
}
#[derive(Subcommand)]
pub enum GrokCommands {
Add {
#[arg(help = "Configuration alias name (used as the [model.<alias>] id)")]
alias_name: String,
#[arg(long = "model", help = "Underlying model id (e.g. claude-opus-4-6)")]
model: Option<String>,
#[arg(long = "base-url", help = "API endpoint base URL")]
base_url: Option<String>,
#[arg(long = "name", help = "Human-friendly display name")]
name: Option<String>,
#[arg(
long = "api-backend",
help = "API backend: chat_completions | responses | messages"
)]
api_backend: Option<String>,
#[arg(long = "context-window", help = "Context window size")]
context_window: Option<u32>,
#[arg(
long = "api-key",
help = "API key written directly to config (optional)"
)]
api_key: Option<String>,
#[arg(
long = "env-key",
help = "Environment variable name to read the key from (repeatable)"
)]
env_key: Vec<String>,
#[arg(
long = "header",
value_name = "KEY=VALUE",
help = "Extra HTTP header for the model, e.g. x-api-key=sk-ant-... (repeatable)"
)]
header: Vec<String>,
#[arg(long = "force", short = 'f', help = "Overwrite existing configuration")]
force: bool,
#[arg(
long = "interactive",
short = 'i',
help = "Enter configuration values interactively"
)]
interactive: bool,
#[arg(
long = "from-file",
num_args = 0..=1,
value_name = "PATH",
help = "Import from config.toml (defaults to ~/.grok/config.toml if no path)"
)]
from_file: Option<Option<String>>,
},
List {
#[arg(long = "plain", short = 'p')]
plain: bool,
#[arg(long = "name", short = 'n', help = "Show only alias name and model")]
name: bool,
},
#[command(trailing_var_arg = true)]
Use {
alias_name: String,
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
prompt: Vec<String>,
},
Remove {
#[arg(required = true)]
alias_names: Vec<String>,
},
}