Skip to content

fix(opencode): keep TUI interactive with piped stdin#28540

Closed
LordMikkel wants to merge 4 commits into
anomalyco:devfrom
LordMikkel:fix/tui-stdin-pipe
Closed

fix(opencode): keep TUI interactive with piped stdin#28540
LordMikkel wants to merge 4 commits into
anomalyco:devfrom
LordMikkel:fix/tui-stdin-pipe

Conversation

@LordMikkel

@LordMikkel LordMikkel commented May 20, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #28538

Related to #387, #24195 and #3930.
The root cause was never addressed. This PR includes an actual fix.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When stdin is piped, the TUI renderer was reading input from the pipe
instead of the terminal, which broke keyboard control completely,
ANSI noise, no interaction.

The run command already handled this with resolveInteractiveStdin(),
but tui was missing it. This PR applies the same fix: pass the
controlling TTY (/dev/tty on Linux, CONIN$ on Windows) to the renderer
while still consuming the piped content as the prompt.

How did you verify your code works?

  • opencode < test-prompt.txt
  • echo "hello" | opencode
  • opencode --prompt "hello"
  • opencode run < test-prompt.txt

Screenshots / recordings

with the PR:
image

image

without the PR (looh the issue):

Image image

Checklist

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

@LordMikkel

Copy link
Copy Markdown
Author

Updated this against the latest dev, so it should be mergeable again.

I re-tested the stdin locally, including piped stdin and --prompt, and also ran typecheck plus the existing runtime.stdin tests.

@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.

@LordMikkel

LordMikkel commented Jun 20, 2026

Copy link
Copy Markdown
Author

Hi staff team! @simonklee @thdxr @kommander @rekram1-node

Could you please reopen this PR? 🙏

It was closed automatically by the bot due to age, but it fixes a real and reproducible bug that was previously reported that you wanted to be fixed since the last year: #28538, where the TUI loses interactivity and prints ANSI noise when stdin is piped. This also matches the older related reports #24195, #3871, and #6220.

The fix is small and follows the same approach already used by the run command: passing the controlling TTY (/dev/tty or CONIN$) to the renderer.

I recently updated it against the latest dev branch and re-tested it locally, so there are no conflicts.

It can be validated with a simple:

echo "hello" | opencode

I’d be very happy to contribute this fix to the project. Thanks for your time!

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.

TUI freeze and show stray ANSI escape codes with piped or redirected stdin

1 participant