nikivdev/code · error

`gh` is installed but not working

Error message

`gh` is installed but not working

What it means

The tool checks GitHub CLI availability by running `gh --version` before using gh. This error means the `gh` binary exists (it was found on PATH and could be executed) but exits non-zero even for `--version`, so it is installed but broken/unusable. The library bails rather than attempting authenticated gh API calls that would fail anyway.

Source

Thrown at src/commit.rs:8503

}

fn jj_bin() -> String {
    env::var("FLOW_JJ_BIN")
        .ok()
        .map(|v| v.trim().to_string())
        .filter(|v| !v.is_empty())
        .unwrap_or_else(|| "jj".to_string())
}

fn ensure_gh_available() -> Result<()> {
    let status = Command::new("gh")
        .args(["--version"])
        .stdout(Stdio::null())
        .stderr(Stdio::null())
        .status()
        .context("failed to run `gh` (GitHub CLI)")?;
    if !status.success() {
        bail!("`gh` is installed but not working");
    }
    Ok(())
}

fn gh_capture_in(repo_root: &Path, args: &[&str]) -> Result<String> {
    let output = Command::new("gh")
        .current_dir(repo_root)
        .args(args)
        .output()
        .with_context(|| format!("failed to run gh {}", args.join(" ")))?;
    if !output.status.success() {
        bail!(
            "gh {} failed: {}",
            args.join(" "),
            String::from_utf8_lossy(&output.stderr).trim()
        );
    }
    Ok(String::from_utf8_lossy(&output.stdout).to_string())

View on GitHub (pinned to a747e741ae)

Solutions

  1. Reinstall gh: `brew reinstall gh` or the equivalent for your package manager
  2. Test manually: `gh --version` should print a version and exit 0
  3. Check `which gh` for shadowing by a broken binary earlier on PATH
  4. If gh is not actually needed, ensure the code path that requires it is not triggered

Example fix

// before
$ gh --version
zsh: abort (core dumped)  gh --version
Error: `gh` is installed but not working
// after
$ brew reinstall gh
$ gh --version
gh version 2.62.0
$ tool create-review  # proceeds
Defensive patterns

Strategy: validation

Validate before calling

fn gh_works() -> bool {
    Command::new("gh")
        .arg("--version")
        .stdout(Stdio::null())
        .stderr(Stdio::null())
        .status()
        .map(|s| s.success())
        .unwrap_or(false)
}
if !gh_works() { eprintln!("reinstall gh before continuing"); }

Try / catch

if let Err(e) = result {
    if e.to_string().contains("installed but not working") {
        eprintln!("gh is present but broken; run `gh --version` to confirm, then reinstall");
    }
    return Err(e);
}

Prevention

When it happens

Trigger: `ensure_gh()` runs `Command::new("gh").arg("--version")...status()` and the returned ExitStatus is not success — i.e. gh exits with an error code even on the trivial version command.

Common situations: Corrupted or partially upgraded gh installation; incompatible dynamic libraries on Linux; gh installed via a package manager that shipped a broken build; architecture mismatch (e.g. x86 binary on ARM).

Related errors


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