rtk-ai/rtk · error

--codex cannot be combined with --opencode

Error message

--codex cannot be combined with --opencode

What it means

`rtk init` validates that mutually exclusive flag combinations are not used together. Codex mode installs its own specific set of files/hooks, so `--codex` cannot be combined with `--opencode` (or `--claude-md`/`--hook-only`, which have their own messages). Passing both flags fails fast with this error before any files are written.

Solutions

  1. Run `rtk init --codex` alone (drop --opencode) if you want Codex mode.
  2. Run two separate invocations — `rtk init --codex` and `rtk init --opencode` — if you need both editors configured.
  3. Check `rtk init --help` for the compatible flag combinations before composing a command.

Example fix

// before
rtk init --codex --opencode

// after
rtk init --codex
rtk init --opencode  # separate run
Defensive patterns

Strategy: validation

Validate before calling

let args: Vec<String> = std::env::args().collect();
if args.contains(&"--codex".to_string()) && args.contains(&"--opencode".to_string()) {
    eprintln!("--codex and --opencode are mutually exclusive");
    std::process::exit(2);
}

Try / catch

match rtk_init(&args).err() {
    Some(e) if e.to_string().starts_with("--codex cannot be combined") => {
        eprintln!("run separate `rtk init` invocations per editor mode");
    }
    _ => {}
}

Prevention

When it happens

Trigger: Running `rtk init --codex --opencode` (run in src/hooks/init.rs, guarded by the `if codex { if install_opencode { bail!(...) } }` validation).

Common situations: A shell alias or install script that always appends `--opencode` while a user adds `--codex`; guessing that multiple editor integrations can be initialized in one command; copied command lines from docs targeting different editors.

Understand the failure class

Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.

Related errors


AI-assisted analysis of rtk-ai/rtk@0924356b4c (2026-09-19). Data as JSON: /api/errors/2ef9aeff235d42a7. Report an issue: GitHub.

Appendix: source

Thrown at src/hooks/init.rs:398

#[allow(clippy::too_many_arguments)]
pub fn run(
    global: bool,
    install_claude: bool,
    install_opencode: bool,
    install_cursor: bool,
    install_windsurf: bool,
    install_cline: bool,
    claude_md: bool,
    hook_only: bool,
    codex: bool,
    patch_mode: PatchMode,
    ctx: InitContext,
) -> Result<()> {
    let InitContext { dry_run, .. } = ctx;
    // Validation: Codex mode conflicts
    if codex {
        if install_opencode {
            anyhow::bail!("--codex cannot be combined with --opencode");
        }
        if claude_md {
            anyhow::bail!("--codex cannot be combined with --claude-md");
        }
        if hook_only {
            anyhow::bail!("--codex cannot be combined with --hook-only");
        }
        if matches!(patch_mode, PatchMode::Auto) {
            anyhow::bail!("--codex cannot be combined with --auto-patch");
        }
        if matches!(patch_mode, PatchMode::Skip) {
            anyhow::bail!("--codex cannot be combined with --no-patch");
        }
        run_codex_mode(global, ctx)?;
    } else {
        // Validation: Global-only features
        if install_opencode && !global {
            anyhow::bail!("OpenCode plugin is global-only. Use: rtk init -g --opencode");

View on GitHub (pinned to 0924356b4c)