Note: This issue was prepared with AI assistance (via prompts) using opencode and the model xai/grok-build-0.1.
Summary
opencode export <id> | jq (and similar commands) produces truncated or invalid JSON when the output is piped and the data volume is large. Writing to a file first works correctly.
This is a recurring problem. Previous reports include:
A previous attempt to address the export case (#3049) changed the implementation from console.log to process.stdout.write, but the issue persists.
Reproduction
# Fails with parse error
opencode export <large-session-id> | jq .
# Works
opencode export <large-session-id> > /tmp/out.json && cat /tmp/out.json | jq .
The problem is data-size and backpressure dependent.
Workaround
Always redirect large machine-readable output to a file instead of piping directly.
Additional Context
The truncation occurs because large stdout writes are not fully flushed before the process exits. The same pattern exists across multiple CLI commands that produce significant output.
Summary
opencode export <id> | jq(and similar commands) produces truncated or invalid JSON when the output is piped and the data volume is large. Writing to a file first works correctly.This is a recurring problem. Previous reports include:
opencode exportopencode exportoutputs truncated JSON when pipedopencode debug skillreturns before output is complete #26399:opencode debug skillreturns before output is complete (still open)A previous attempt to address the export case (#3049) changed the implementation from
console.logtoprocess.stdout.write, but the issue persists.Reproduction
The problem is data-size and backpressure dependent.
Workaround
Always redirect large machine-readable output to a file instead of piping directly.
Additional Context
The truncation occurs because large stdout writes are not fully flushed before the process exits. The same pattern exists across multiple CLI commands that produce significant output.