abhigyanpatwari/GitNexus · error · Error

claude CLI returned empty output

Error message

claude CLI returned empty output

What it means

The claude CLI was found and executed (`claude -p --output-format text --no-session-persistence`) and returned without error, but the captured stdout content was empty. The subprocess succeeded at the transport level, yet produced no answer text for the prompt (system prompt prepended, separated by '---').

Source

Thrown at gitnexus/src/core/wiki/local-cli-client.ts:114

  prompt: string,
  config: LocalCLIConfig,
  systemPrompt?: string,
  options?: CallLLMOptions,
): Promise<LLMResponse> {
  const commandInfo = getDetectedCommand('claude');
  if (!commandInfo) {
    throw new Error('Claude CLI not found. Install Claude Code and ensure `claude` is on PATH.');
  }

  const args = ['-p', '--output-format', 'text', '--no-session-persistence'];
  if (config.model) {
    args.push('--model', config.model);
  }
  const fullPrompt = systemPrompt ? `${systemPrompt}\n\n---\n\n${prompt}` : prompt;

  const response = await runLocalCLI('claude', commandInfo, args, config, fullPrompt, options);
  if (!response.content) {
    throw new Error('claude CLI returned empty output');
  }
  return response;
}

export async function callCodexLLM(
  prompt: string,
  config: LocalCLIConfig,
  systemPrompt?: string,
  options?: CallLLMOptions,
): Promise<LLMResponse> {
  const commandInfo = getDetectedCommand('codex');
  if (!commandInfo) {
    throw new Error('Codex CLI not found. Install Codex CLI and ensure `codex` is on PATH.');
  }

  const outputDir = await fs.mkdtemp(path.join(os.tmpdir(), 'gitnexus-wiki-codex-'));
  const outputPath = path.join(outputDir, 'last-message.txt');
  const workingDirectory = config.workingDirectory || process.cwd();

View on GitHub (pinned to aac7515d2a)

Solutions

  1. Verify the CLI works manually: `claude -p 'say hi' --output-format text` — if empty, fix auth/install first
  2. Re-run `claude` interactively to complete login/consent, then retry wiki generation
  3. Update Claude Code if a version regression changed -p output behavior
  4. Retry with `-v/--verbose` to see the raw command and response; if it recurs on one module, split/shrink that prompt

Example fix

# before
gitnexus wiki --provider claude   # empty output

# after
claude -p 'say hi'   # verify non-empty
gitnexus wiki --provider claude -v
Defensive patterns

Strategy: retry

Try / catch

try {
  await callClaudeLLM(prompt, config);
} catch (err) {
  if (err instanceof Error && err.message === 'claude CLI returned empty output') {
    return callClaudeLLM(prompt, config); // one retry — transient empty turns happen
  }
  throw err;
}

Prevention

When it happens

Trigger: The model refuses or returns an empty turn (safety refusal with empty text output, empty response bug); session/auth state causing the CLI to print nothing; prompt too large or truncated by CLI limits; stdout swallowed when --output-format/flags change in a Claude Code update.

Common situations: Unauthenticated Claude Code printing an empty/interactive message in print mode; version upgrades changing default output behavior; refusal cases on security-heavy repo content; very large module prompts hitting CLI input limits.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@aac7515d2a (2026-08-20). Data as JSON: /api/errors/0fb98077782cb2af. Report an issue: GitHub.