abhigyanpatwari/GitNexus · error · Error
codex CLI returned empty output
Error message
codex CLI returned empty output
What it means
The codex CLI ran (`codex exec --sandbox read-only --cd <dir>`), then the client reads last-message.txt from the temp output dir and falls back to captured stdout; if both are empty/whitespace after trim, it throws. Codex is expected to write its final message to the output file — empty file plus empty stdout means the exec produced no final answer.
Source
Thrown at gitnexus/src/core/wiki/local-cli-client.ts:158
'-c',
'approval_policy="never"',
'--color',
'never',
'--output-last-message',
outputPath,
];
if (config.model) {
args.push('--model', config.model);
}
args.push('-');
try {
const response = await runLocalCLI('codex', commandInfo, args, config, fullPrompt, options);
const lastMessage = await fs.readFile(outputPath, 'utf-8').catch(() => '');
const content = (lastMessage || response.content).trim();
if (!content) {
throw new Error('codex CLI returned empty output');
}
return { content };
} finally {
await fs.rm(outputDir, { recursive: true, force: true }).catch(() => undefined);
}
}
interface OpenCodeEvent {
type?: string;
message?: string;
error?: {
message?: string;
name?: string;
data?: {
message?: string;
};
};
part?: {View on GitHub (pinned to aac7515d2a)
Solutions
- Verify the CLI produces output manually: `codex exec 'say hi'` and check a non-empty final message
- Complete `codex` login/consensus auth, then rerun the wiki command
- Update or pin a known-good Codex CLI version if a release changed exec output behavior
- Retry with `-v` (GITNEXUS_VERBOSE=1) to inspect the exact command and captured output
Example fix
# before gitnexus wiki --provider codex # empty output # after codex exec 'say hi' # confirm non-empty final message gitnexus wiki --provider codex -v
Defensive patterns
Strategy: retry
Try / catch
try {
await callCodexLLM(prompt, config);
} catch (err) {
if (err instanceof Error && err.message === 'codex CLI returned empty output') {
return callCodexLLM(prompt, config); // retry once — exec sometimes yields no final message
}
throw err;
} Prevention
- Confirm `codex exec` writes a final message for a trivial prompt before a long run
- Keep Codex CLI authenticated and updated; pin known-good versions in CI
- Treat one retry as routine for local-CLI providers; only escalate on repeated empties
When it happens
Trigger: Codex exec finishes without writing last-message.txt (auth failure, sandbox denial, model refusal with no text, or a CLI arg-schema change across versions making the invocation a no-op); stdout also empty so the fallback yields nothing.
Common situations: Codex CLI not signed in (exec exits quietly); version upgrades renaming the output-file convention or flags; read-only sandbox blocking a step the model insisted on, ending with no final message; prompt too large.
Related errors
- LLM returned empty response
- LLM returned empty streaming response
- claude CLI returned empty output
- Codex CLI not found. Install Codex CLI and ensure `codex` is
- --allow-insecure-connection / GITNEXUS_ALLOW_INSECURE_CONNEC
AI-assisted analysis of abhigyanpatwari/GitNexus@aac7515d2a (2026-08-20).
Data as JSON: /api/errors/ba567c41eb1273be.
Report an issue: GitHub.