Hmbown/CodeWhale · error

--worktree-repo and --branch must be provided together

Error message

--worktree-repo and --branch must be provided together

What it means

When parsing worktree lane options in crates/cli/src/lib.rs, `--worktree-repo` and `--branch` form a pair: providing exactly neither is fine, but providing only one is ambiguous, so the match arm `_ => bail!(...)` rejects it. The library cannot infer whether the lone flag should pair with a default repo/branch, so it fails loudly.

Solutions

  1. Pass both flags together: `--worktree-repo <repo> --branch <branch>`.
  2. Pass neither flag if you don't want a worktree lane.
  3. Fix the script so both variables are set or both flags are omitted (e.g. pair them behind one condition).

Example fix

// before
codewhale lane --worktree-repo ~/src/proj
// after
codewhale lane --worktree-repo ~/src/proj --branch feature/x
Defensive patterns

Strategy: validation

Validate before calling

if (!!repo !== !!branch) throw new Error('--worktree-repo and --branch must be provided together');

Prevention

When it happens

Trigger: Running a lane command with `--worktree-repo <repo>` but no `--branch`, or `--branch <name>` but no `--worktree-repo`; the (Some/None or None/Some) pattern match falls into `_`.

Common situations: Users thinking `--branch` alone implies the current repo; scripts where one of the two flags is set conditionally and the other is missing due to an unset environment variable.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/2d241be054c636d2. Report an issue: GitHub.

Appendix: source

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

        environment,
        cwd,
    } = request;
    let kind = RuntimeBackendKind::parse(&runtime)?;
    let reg = LaneRegistry::open_default()?;
    let mut record = reg.create_pending(workflow, fleet, issue, goal, kind, worktree_ttl_secs)?;
    let worktree = match (worktree_repo, branch) {
        (Some(repo_root), Some(branch_name)) => {
            let path = worktree_path
                .unwrap_or_else(|| repo_root.join(".codewhale").join("lanes").join(&record.id));
            Some(WorktreeProvision {
                repo_root,
                branch: branch_name,
                path,
                base_ref: None,
            })
        }
        (None, None) => None,
        _ => bail!("--worktree-repo and --branch must be provided together"),
    };
    let cmd = if command.is_empty() {
        vec![
            "sh".into(),
            "-c".into(),
            format!("echo lane {} started", record.id),
        ]
    } else {
        command
    };
    let spec = LaneStartSpec {
        command: cmd,
        cwd,
        environment,
        log_proxy: (kind == RuntimeBackendKind::Tmux)
            .then(std::env::current_exe)
            .transpose()
            .context("resolve current Codewhale executable for tmux log proxy")?,

View on GitHub (pinned to 73e0f67d83)