# How to Override CodeWhale Provider and Model Using CLI Flags

> Learn to override CodeWhale provider and model using CLI flags without altering your config file. Seamlessly test different settings for single invocations.

- Repository: [Hunter Bown/CodeWhale](https://github.com/Hmbown/CodeWhale)
- Tags: how-to-guide
- Published: 2026-06-02

---

**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`](https://github.com/Hmbown/CodeWhale/blob/main/crates/cli/src/lib.rs). Two optional fields handle provider and model overrides:

- **`--provider <NAME>`** — Accepts a `ProviderArg` that maps to the internal `ProviderKind` enum
- **`--model <NAME>`** — Accepts a `String` representing the specific model ID

The struct definition declares these fields at lines 82 and 84:

```rust
#[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`](https://github.com/Hmbown/CodeWhale/blob/main/crates/cli/src/lib.rs) at line 489:

```rust
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:

```rust
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):

```rust
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:

```bash

# 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`](https://github.com/Hmbown/CodeWhale/blob/main/crates/cli/src/lib.rs) (line 1908) verifies this parsing behavior:

```rust
let cli = parse_ok(&["deepseek", "model", "list", "--provider", "openai"]);
assert_eq!(cli.provider, Some(ProviderArg::OpenAI));

```

## Summary

- **Temporary overrides**: The `--provider` and `--model` flags affect only the current invocation and do not modify `~/.codewhale/config.toml`.
- **Source location**: Flag definitions reside in [`crates/cli/src/lib.rs`](https://github.com/Hmbown/CodeWhale/blob/main/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.