How to Override CodeWhale Provider and Model Using CLI Flags
The CodeWhale CLI accepts --provider and --model flags that temporarily override your saved configuration for a single invocation without modifying ~/.codewhale/config.toml.
CodeWhale is a Rust-based AI coding assistant developed in the Hmbown/CodeWhale repository. Its command-line interface allows you to dynamically switch between LLM providers and model IDs at runtime. This article explains how these override flags are implemented in the source code and how to use them effectively.
CLI Flag Structure and Parsing
CodeWhale’s CLI is built with clap and defines a top-level argument struct in crates/cli/src/lib.rs. Two optional fields handle provider and model overrides:
--provider <NAME>— Accepts aProviderArgthat maps to the internalProviderKindenum--model <NAME>— Accepts aStringrepresenting the specific model ID
The struct definition declares these fields at lines 82 and 84:
#[arg(long)]
provider: Option<ProviderArg>,
#[arg(long)]
model: Option<String>,
These flags are defined as Option types, making them optional for every subcommand. When present, they take precedence over values stored in the persistent configuration file.
Runtime Propagation and Configuration Override
When you execute a command, the parsed Cli instance converts into a RuntimeConfig that the TUI engine consumes. This conversion occurs in crates/cli/src/lib.rs at line 489:
let runtime = RuntimeConfig {
provider: cli.provider.map(Into::into),
model: cli.model.clone(),
// ... other fields
};
The RuntimeConfig bridges the CLI arguments with the underlying engine. If you specified --provider or --model, those values replace the defaults loaded from disk.
For subcommands that delegate to the TUI binary, the delegate_to_tui helper function (line 540) forwards these overrides to the subprocess. It constructs the argument list dynamically, inserting the flags only when they are set:
match command {
Commands::Exec(args) => delegate_to_tui(&cli, &runtime, tui_args("exec", args)),
// ... other commands
}
Additionally, if a model is specified, CodeWhale exports it as the DEEPSEEK_MODEL environment variable for downstream processes (line 1549):
if let Some(model) = cli.model.as_ref() {
cmd.env("DEEPSEEK_MODEL", model);
}
This ensures that spawned child processes respect your temporary model selection even when invoked through subprocess delegation.
Usage Examples
The following commands demonstrate how to override CodeWhale provider and model CLI flags for various workflows:
# Execute a prompt using OpenAI instead of your default provider
codewhale exec "Refactor this function" --provider openai --model gpt-4
# List available models on the NVIDIA NIM provider
codewhale model list --provider nvidia-nim
# Resolve a specific DeepSeek model without changing defaults
codewhale model resolve deepseek-v4-pro --provider deepseek
The test suite in crates/cli/src/lib.rs (line 1908) verifies this parsing behavior:
let cli = parse_ok(&["deepseek", "model", "list", "--provider", "openai"]);
assert_eq!(cli.provider, Some(ProviderArg::OpenAI));
Summary
- Temporary overrides: The
--providerand--modelflags affect only the current invocation and do not modify~/.codewhale/config.toml. - Source location: Flag definitions reside in
crates/cli/src/lib.rs(lines 82–84), with runtime application at line 489. - Propagation path: Values flow from
Cli→RuntimeConfig→delegate_to_tui→ subprocess arguments or environment variables. - Broad applicability: These flags work across execution commands (
exec), model registry commands (list,resolve), and other subcommands.
Frequently Asked Questions
Do the --provider and --model flags persist to the configuration file?
No. These flags override only the current runtime configuration. They are intentionally ephemeral to allow experimentation without altering your saved defaults in ~/.codewhale/config.toml. To make permanent changes, edit the configuration file directly or use the codewhale config command.
Which providers can I specify with the --provider flag?
The flag accepts any variant of the internal ProviderKind enum, such as openai, deepseek, nvidia-nim, or other providers supported by your CodeWhale build. The value is parsed into a ProviderArg struct that validates against available implementations in the codebase.
Can I use these flags with model management commands?
Yes. The --provider and --model flags are honored by the model registry subcommands including codewhale model list and codewhale model resolve. This allows you to query model availability or resolve model IDs against specific providers without switching your default configuration.
How does CodeWhale pass the model override to underlying processes?
When the --model flag is provided, CodeWhale sets the DEEPSEEK_MODEL environment variable before spawning subprocesses through the delegate_to_tui function. This ensures that nested Rust processes or external tools receive the correct model identifier even when invoked indirectly.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →