You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CLI: JSON stream output truncated when process exits quickly (stdout buffer not flushed) #29866
When using opencode run <task> --format json and redirecting the output to a file or piping it to another command, the final JSON events (typically text or step_finish) are frequently missing. The output often stops after the initial step_start event.
Steps to Reproduce:
Run a simple task with JSON output redirected to a file:
Observe that the file often contains only the {"type":"step_start", ...} line, missing the subsequent {"type":"text", ...} and {"type":"step_finish", ...} events.
Compare with piping to jq:
opencode run "Please reply Hello" --format json | jq .
While more stable, this also occasionally fails to show the final events if the process exits too quickly.
Expected Behavior:
All JSON Lines events, including the final text response and step_finish marker, should be consistently written to stdout and successfully captured by redirection or pipes.
Actual Behavior:
The stdout buffer appears to not be fully flushed before the opencode process terminates. This is a classic race condition where the process exits before the OS writes the remaining buffered data to the file or pipe.
Environment:
OS: macOS 15.7.4
Node.js Version: [Insert your Node version, e.g., v22.x]
OpenCode Version: [Insert your opencode version, e.g., run opencode --version]
Suggested Fix:
Ensure that the CLI explicitly waits for process.stdout to drain before exiting. In Node.js, this can be achieved by:
process.stdout.write(lastChunk);process.stdout.on('drain',()=>{process.exit(0);});// Or ensure all streams are properly ended and drained in the shutdown logic.
Workaround for Users:
Currently, the most reliable way to capture full output in scripts is to implement a retry mechanism with content validation:
#!/bin/bashforiin {1..3};do
opencode run "$TASK" --format json | tee output.jsonl > /dev/null
if grep -q '"type":"text"' output.jsonl;thenexit 0
fidoneecho"Failed to capture complete output after retries."exit 1
If your issue is distinct (e.g. reproducible even on simple single-turn prompts with no tool calls), please add a note clarifying how it differs from #27697.
Activity
github-actions commentedon May 29, 2026
This issue might be a duplicate of an existing issue. Please check:
opencode run --format jsondrops post-tool-call assistant text for github-copilot/claude-* models #27697: Also reportsopencode run --format jsonoutput being truncated/dropped — in that case post-tool-call assistant text is silently missing, which overlaps with the stdout not being fully captured before process exit described here.If your issue is distinct (e.g. reproducible even on simple single-turn prompts with no tool calls), please add a note clarifying how it differs from #27697.
rekram1-node commentedon Jun 10, 2026
think this was fixed