nikivdev/code · error

claude failed: {}

Error message

claude failed: {}

What it means

This error is thrown when the external `claude` CLI exits with a non-zero status during AI commit-message generation. The captured stderr is trimmed and embedded in the message via `bail!`. Note the placeholder is `{}` (not `{:?}`), so if the reported message literally reads "claude failed: {}" the stderr was empty and the real failure reason was lost.

Source

Thrown at src/commit.rs:12756

    if truncated {
        prompt.push_str("\n\n[Diff truncated]");
    }

    let status = status.trim();
    if !status.is_empty() {
        prompt.push_str("\n\nGit status:\n");
        prompt.push_str(status);
    }

    let output = Command::new("claude")
        .args(["-p", &prompt])
        .output()
        .context("failed to run claude for commit message")?;

    if !output.status.success() {
        let stderr = String::from_utf8_lossy(&output.stderr);
        bail!("claude failed: {}", stderr.trim());
    }

    let message = String::from_utf8_lossy(&output.stdout).trim().to_string();

    if message.is_empty() {
        bail!("claude returned empty commit message");
    }

    Ok(trim_quotes(&message))
}

/// Generate commit message using Rise daemon (local AI proxy).
fn generate_commit_message_rise(
    diff: &str,
    status: &str,
    truncated: bool,
    model: &str,
) -> Result<String> {

View on GitHub (pinned to a747e741ae)

Solutions

  1. Run `claude -p "test"` manually to see the raw stderr and fix the underlying CLI issue (usually `claude login`).
  2. Verify the claude CLI is installed and on PATH (`which claude`).
  3. Re-authenticate with `claude login` and retry the commit flow.
  4. Check for CLI version changes that may have altered the `-p` flag and update the tool.

Example fix

// before
bail!("claude failed: {}", stderr.trim());
// after
bail!("claude failed: {}", if stderr.trim().is_empty() { format!("exit status {}", output.status) } else { stderr.trim().to_string() });
Defensive patterns

Strategy: try-catch

Validate before calling

// Rust: check claude availability before generating
if which::which("claude").is_err() {
    return Err(anyhow!("claude CLI not found on PATH"));
}

Type guard

fn claude_failure_clean(stderr: &str, status: &std::process::ExitStatus) -> String {
    if status.success() { return String::new(); }
    let s = stderr.trim();
    if s.is_empty() { format!("exit status {}", status) } else { s.to_string() }
}

Try / catch

match generate_claude_commit_message(&diff) {
    Ok(msg) => msg,
    Err(e) if e.to_string().starts_with("claude failed") => {
        eprintln!("Run `claude login` and retry: {e}");
        fallback_to_manual_message()
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Any invocation of `claude -p <prompt>` in the claude commit-message generator that returns a non-zero exit code: claude not authenticated, invalid CLI flags, network failure reaching Anthropic, rate limiting, or the process crashing.

Common situations: User logged out of Claude (`claude logout` or expired session); claude CLI updated and `-p` behavior changed; claude not installed or not on PATH; prompt rejected by content filtering; network/proxy failure.

Related errors


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