nikivdev/code · error

ai not found in PATH

Error message

ai not found in PATH

What it means

This error is raised by `run_fix_f_commit_ai` when the external `ai` CLI executable cannot be located on PATH via `which::which("ai")`. The library depends on this external tool to perform AI-assisted secret redaction and aborts the fix flow early with a clear message rather than failing mid-execution.

Source

Thrown at src/commit.rs:475

    let agent_name =
        env::var("FLOW_FIX_COMMIT_AGENT").unwrap_or_else(|_| "fix-f-commit".to_string());
    let handoff_enabled = agent_name.trim().to_lowercase() != "off";
    let ai_available = which::which("ai").is_ok();
    if !handoff_enabled && !ai_available {
        return Ok(false);
    }

    git_run(&["add", "."])?;
    ensure_no_internal_staged(repo_root)?;
    ensure_no_unwanted_staged(repo_root)?;
    gitignore_policy::enforce_staged_policy(repo_root)?;

    Ok(!scan_diff_for_secrets(repo_root).is_empty())
}

fn run_fix_f_commit_ai(repo_root: &Path, task: &str) -> Result<()> {
    if which::which("ai").is_err() {
        bail!("ai not found in PATH");
    }

    let status = Command::new("ai")
        .args(["--prompt", task])
        .current_dir(repo_root)
        .stdin(Stdio::inherit())
        .stdout(Stdio::inherit())
        .stderr(Stdio::inherit())
        .status()
        .context("failed to run ai")?;

    if !status.success() {
        bail!("ai auto-fix failed");
    }

    Ok(())
}

View on GitHub (pinned to a747e741ae)

Solutions

  1. Install the `ai` CLI (e.g. via your package manager or its official installer).
  2. Ensure its install directory is on PATH: `export PATH="$HOME/.local/bin:$PATH"` and verify with `which ai`.
  3. If you do not want AI fixing, set `FLOW_FIX_COMMIT_AGENT=off` and fix the findings manually instead.
  4. Run the commit flow from a shell where `which ai` succeeds.

Example fix

// before: command not found
// $ flow commit ...
// Error: ai not found in PATH
// after
export PATH="$HOME/.local/bin:$PATH"
which ai  # /home/user/.local/bin/ai
Defensive patterns

Strategy: fallback

Validate before calling

// check availability before entering the AI fix path
if which::which("ai").is_err() {
    eprintln!("ai CLI missing; fix findings manually or install it");
    std::process::exit(1);
}

Try / catch

match run_fix_f_commit_ai(repo_root, task) {
    Err(e) if e.to_string().contains("ai not found in PATH") => {
        // fallback: remediate manually instead of the AI path
        eprintln!("falling back to manual redaction of findings");
    }
    Err(e) => return Err(e),
    Ok(_) => {}
}

Prevention

When it happens

Trigger: `warn_secrets_in_diff` selects the AI fix path (interactive TTY, FLOW_FIX_COMMIT_AGENT enabled) and calls `run_fix_f_commit_ai`, but the `ai` binary is not installed or not on the PATH of the current process.

Common situations: AI CLI never installed; installed in a user-local bin dir (e.g. ~/.local/bin, ~/.cargo/bin) missing from PATH; running the commit tool from an IDE terminal, cron, or CI where PATH differs from the interactive shell; the tool named differently after a version change.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/22f50b045d94ff52. Report an issue: GitHub.