Skip to content

tui: pasted text with a trailing newline submits the prompt on Windows #62899

Open

Description

@massjuan

Description

On Windows, a prompt pasted into the TUI can be submitted by itself, without pressing Enter. The pasted content is a single terminal command line that still carries its trailing line break, and after the paste the message is sent immediately: a new session is created and the text is recorded as a normal user message. From the user's side it looks like opencode sends a message on its own when it opens.

The prompt paste handler normalizes line endings but inserts the untrimmed text:

let it = clipboard.replace(/\r\n?/g, "\n"), ot = it.trim();
// ...
n.insertText(it) // inserts the text including the trailing newline

Two things look wrong: the trailing newline is kept for single-line content, and a newline inserted programmatically appears to reach input.submit instead of the multiline editor. Related newline handling reports in V2: #43222 and #43286 (Shift+Enter submits instead of inserting a newline).

Plugins

None. Only the 14 built-in CLI plugins are loaded (home.footer, prompt.footer, btw, sidebar.context, sidebar.limit, sidebar.mcp, sidebar.todo, sidebar.footer, notifications, plugins, stats, merman, latex, diffs). No plugin directories exist in the project or global config.

OpenCode version

2.2.5 (2.2.6 available)

Steps to reproduce

  1. Windows 11, TUI started with a plain opencode from the VS Code integrated terminal (PowerShell profile).
  2. Copy a single command line in a way that keeps the line break, e.g. VS Code Ctrl+C with no selection, which copies the whole line including the newline.
  3. Open opencode and paste into the empty prompt with Ctrl+V. Do not press Enter.
  4. The prompt is submitted immediately.

Expected behavior: the paste inserts the text and waits for an explicit Enter.

Actual behavior: the message sends itself. A session is created and the text becomes its first user message.

Screenshot

Not available.

Operating System

Windows 11 (10.0.26300.9711)

Terminal

VS Code 1.145.2 integrated terminal. TERM=xterm-256color, TERM_PROGRAM=vscode, COLORTERM=truecolor. In the affected launch the TUI's parent process was a cmd.exe started from VS Code's terminal.

Additional context

Observed timing in the affected session:

  • TUI process starts at 08:14:02.
  • Session is created at 08:14:05.879.
  • User message is recorded at 08:14:06.082, 203 ms later, with no keyboard interaction.

There is no stashed draft (prompt-stash.jsonl absent), no queued message for that session (session_inbox empty for it), and a plain opencode launch with OPENCODE_LOG_LEVEL=DEBUG created no session and sent no message, so the send needs an input event. The submitted text is a shell command (d:\dev\budget_cumi\.venv\Scripts\activate.bat) that the user did not intend to send, and the same user pastes terminal transcripts into the prompt regularly, which is why this only shows up intermittently.

Activity

  1. opencodejr commented on Nov 9, 2026

    @opencodejr

    Thanks for the detailed report and timings. I tried this on 2.2.5 on Linux and couldn't reproduce it there.

    • opencode turns on bracketed paste when it starts. A bracketed paste of d:\dev\x\.venv\Scripts\activate.bat with a trailing CRLF is inserted into the prompt and waits for Enter. The latest dev (524afbb) does the same.
    • The prompt is sent right away only when the same text arrives as plain typed keys, without the bracketed-paste markers. The trailing line break then works as Enter, as it would in any terminal app.

    So on your setup the paste probably reaches opencode as plain keystrokes. That could happen because of how the VS Code terminal, cmd.exe and ConPTY pass it through, or because the paste lands while the TUI is still starting up. Checking this needs Windows with the VS Code integrated terminal, which this sandbox doesn't have, so a maintainer with that setup will need to look.

    If you can, these would help:

    • Does it still happen if you wait until the prompt is fully drawn before pasting?
    • Does it happen when you run opencode directly from PowerShell in VS Code, without cmd.exe in between?
    • Does it happen in Windows Terminal?

    Related, but different triggers:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions