Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

opencode api truncates large output when stdout is a pipe (un-awaited write before process.exit)

Closed Beginner friendly
#57,816 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
bun, typescript
Domain
cli

Research direction

Read packages/cli/src/commands/handlers/api.ts and packages/cli/src/index.ts to trace the stdout write and the exit tap. Reproduce by piping opencode api GET /openapi.json to wc -c, then check that the full output is written before exit. The issue is done when piped output is complete and the CLI exits successfully.

Written by the indexing model from the issue text.

Description

pending close triaging

Version: opencode v2.0.32 (source read at that tag); the same write is still on the default branch
(packages/cli/src/commands/handlers/api.ts:46, fetched 2026-10-21).

Reproduce

for i in $(seq 10); do opencode api GET /openapi.json | wc -c; done   # 280292 bytes expected
opencode api GET /openapi.json > out.json; wc -c out.json            # always 280292

Piped, the count stops at exactly 262144 with exit status 0 in 1 of 8 and 4 of 10 runs (Linux, v2.0.32).
Redirected to a file it is complete every time. The silent exit 0 is what makes it hard to notice.

Cause (v2.0.32)

  • packages/cli/src/commands/handlers/api.ts:45-46: the handler reads response.text() and calls
    process.stdout.write(output + ...) once, with no callback and no drain.
  • packages/cli/src/index.ts:139: Effect.tap(() => Effect.sync(() => process.exit(process.exitCode ?? 0)))
    runs right after the handler.
  • Under Bun a write to a pipe larger than the pipe buffer is asynchronous, so process.exit discards what
    the reader has not drained. A write to a file is synchronous, hence complete. 262144 is the pipe buffer
    size, not a number in the source.

Suggested fix: wait for the write before exiting, e.g.
yield* Effect.promise(() => new Promise<void>((done) => process.stdout.write(out, () => done())))
in the handler, or have the exit tap wait for stdout to drain.

Workaround we use: redirect stdout to a file, never a pipe.

Dominant language
TypeScript
Stars
215k
Forks
28.9k
Avg merge
4h 21m
Merged PRs (30d)
476

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from anomalyco/opencode

All issues in anomalyco/opencode

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.