Hmbown/CodeWhale · error

{flag} must be placed before `exec`. Use: codewhale {flag

Error message

{flag} must be placed before `exec`.

Use:
  codewhale {flag} exec "<prompt>"

What it means

`reject_exec_global_flags` scans the arguments before a `--` separator and rejects the global-only flags `--provider`, `--model`, `--api-key`, and `--base-url` when they appear after the `exec` subcommand. These flags configure the runtime globally and must precede `exec`; the message shows the corrected invocation with `{flag} <value>` moved in front.

Source

Thrown at crates/cli/src/lib.rs:2183

    forwarded.push(command.to_string());
    forwarded.extend(args.args);
    forwarded
}

fn setup_is_status_report(args: &TuiPassthroughArgs) -> bool {
    args.args.iter().any(|arg| arg == "--status")
}

fn reject_exec_global_flags(args: &[String]) -> Result<()> {
    const GLOBAL_ONLY_FLAGS: &[&str] = &["--provider", "--model", "--api-key", "--base-url"];

    for arg in args {
        if arg == "--" {
            break;
        }
        let flag = arg.split_once('=').map_or(arg.as_str(), |(flag, _)| flag);
        if GLOBAL_ONLY_FLAGS.contains(&flag) {
            bail!(
                "{flag} must be placed before `exec`.\n\nUse:\n  codewhale {flag} <value> exec \"<prompt>\""
            );
        }
    }

    Ok(())
}

fn run_login_command(store: &mut ConfigStore, args: LoginArgs) -> Result<()> {
    run_login_command_with_secrets(store, args, &Secrets::auto_detect())
}

fn run_login_command_with_secrets(
    store: &mut ConfigStore,
    args: LoginArgs,
    secrets: &Secrets,
) -> Result<()> {
    let provider: ProviderKind = args.provider.unwrap_or(ProviderArg::Deepseek).into();

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Move the flag before the subcommand: `codewhale --provider <value> exec "<prompt>"`
  2. For `=`-style flags, likewise hoist them: `codewhale --model=deepseek-v4-pro exec ...`
  3. If you truly need to pass a literal `--provider` token to the prompt, place it after `--`

Example fix

# before
$ codewhale exec --provider deepseek "review this diff"

# after
$ codewhale --provider deepseek exec "review this diff"
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
# hoist global flags in front of exec before invoking
provider="deepseek"; model="deepseek-v4-pro"; prompt="review this diff"
exec codewhale --provider "$provider" --model "$model" exec -- "$prompt"

Prevention

When it happens

Trigger: `codewhale exec --provider deepseek "..."`, `codewhale exec --model auto ...`, or any exec invocation carrying one of the four global flags (with or without `=`) before the `--` separator; also triggered by flags after `exec` but intended for the outer CLI.

Common situations: Muscle memory from CLIs where flags can go anywhere; scripts migrated from tools with per-subcommand provider flags; copy-pasting a provider flag into the prompt-adjacent position.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/2673cfe8c9f55391. Report an issue: GitHub.