Skip to content

fix(run): add --no-stdin to skip reading piped stdin - #44557

Closed
gitRasheed wants to merge 3 commits into
anomalyco:devfrom
gitRasheed:fix/run-no-stdin
Closed

gitRasheed wants to merge 3 commits into
anomalyco:devfrom
gitRasheed:fix/run-no-stdin

Conversation

@gitRasheed

@gitRasheed gitRasheed commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #42064

Type of change

  • Bug fix

What does this PR do?

opencode run reads fd 0 to EOF when stdin is not a TTY (run.ts, await Bun.stdin.text()), even if the prompt is an argument. An inherited socket or pipe that never sends EOF (supervisor, CI runner) hangs the run; prompt length does not matter. The repo's own test harness dodges this by spawning with stdin: "ignore" in cli-process.ts.

I added a boolean stdin option that defaults to true, allowing yargs to provide --no-stdin through boolean negation. Piped input still appends to the prompt by default. Declaring "no-stdin" directly does not work because --no-stdin parses as noStdin=false.

How did you verify your code works?

mkfifo /tmp/hold && sleep 300 > /tmp/hold &
opencode run "hi" < /tmp/hold     # hangs without the flag; returns with --no-stdin

Three subprocess tests in test/cli/run/no-stdin.test.ts: default piping still appends, --no-stdin excludes piped data, --no-stdin completes on a stdin stream with no EOF. The --no-stdin tests fail unpatched; suite and typecheck pass.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found related PRs but no duplicates of PR #44557:

Related PRs addressing similar stdin/input handling issues:

  1. PR fix(tui): exit on empty non-interactive stdin #42235 - fix(tui): exit on empty non-interactive stdin

    • Related: Also handles stdin in non-interactive contexts, but focuses on TUI rather than the run command
  2. PR fix: keep tool child stdin closed and run tool commands non-interactively #42854 - fix: keep tool child stdin closed and run tool commands non-interactively

    • Related: Addresses stdin handling for tool execution, ensuring non-interactive mode works properly
  3. PR fix(run): apply the non-interactive deny rules to resumed sessions #44559 - fix(run): apply the non-interactive deny rules to resumed sessions

    • Related: Another recent run command fix, dealing with non-interactive sessions

These are related to stdin/input handling but address different aspects. Your PR #44557 is specifically about adding the --no-stdin flag to prevent the run command from hanging when stdin is piped but never sends EOF.

No duplicate PRs found

opencode run reads stdin to EOF whenever fd 0 is not a TTY, before the
session starts and even when the prompt was passed as an argument. A
harness that holds fd 0 open without EOF (an inherited socket or pipe)
blocks the run forever. --no-stdin skips the read; default behavior is
unchanged, so piped input still appends to the prompt.
@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference, author can ignore or act on any point.

Overall: good scoped fix for a genuine operational annoyance — inherited-but-silent fd 0 hanging non-interactive runs — and the Stream.never test proves the hang is gone rather than just asserting flag plumbing. Points:

  1. packages/opencode/src/cli/cmd/run.ts:421 — precedence is right (|| before ?:), but the expression now packs three concerns into one ternary. A tiny helper or two extra lines (if (!args.stdin) return resolveRunInput(...)) would make the TTY short-circuit vs explicit opt-out distinction clearer for the next reader. Behavior itself looks correct and backward compatible: default true keeps today's semantics, TTY still skips the read.

  2. packages/opencode/src/cli/cmd/run.ts:993 — runMini hardcodes stdin: true, so the mini entry point cannot benefit from --no-stdin even though it shares this exact stdin-read path; a held-open fd presumably hangs mini too. If fixing mini is out of scope for this PR, a code comment saying so would prevent it being mistaken for deliberate parity.

  3. packages/opencode/test/lib/cli-process.ts:213-224 — the fixture previously forced stdin: "ignore" with a comment explaining why; the new override keeps that as the default, good, but the old rationale comment ("so the child doesn't see a piped stdin and block") now coexists with tests deliberately piping streams. Worth merging/rewording the two comments so the intent (opt-in override for stdin tests only) is unambiguous.

Minor: with --no-stdin under a live writer (e.g. tail -f | opencode run --no-stdin), the writer blocks once the pipe buffer fills while the child exits immediately — surprising but inherent to "skip reading", and the help text ("disable with --no-stdin") is honest about it. Test coverage including the append-format assertion (prompt\n<sentinel>) is precise; nice work overall.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: let opencode run ignore an unused inherited stdin pipe

2 participants