Skip to content

Pasted text containing $ gets corrupted when expanding [Pasted ~N lines] placeholders #33699

Closed as not planned

Description

@itsybitsybootsy

Description

Pasting text into the TUI prompt collapses it into a [Pasted ~N lines] placeholder, with the real text stored on the prompt part. When that placeholder is expanded back to the full text, the pasted text is passed as the replacement string to String.prototype.replace. A string replacement interprets $ sequences ($$, $&, $`, $'), so pasted code that contains them comes back altered.

Two flows are affected: copying the prompt back to the clipboard, and opening the prompt in the external editor. The submit path is fine because it uses the range-based expander.

Examples (pasted text on the left, what you get back on the right):

  • const x = ${a}$$ becomes const x = ${a}$ (the $$ collapses to one $)
  • echo $&done becomes echo [Pasted ~N lines]done ($& re-inserts the placeholder string into the code)
  • $` and $' are mangled the same way (they pull in text from around the placeholder)

OpenCode version

dev (1.17.9)

Steps to reproduce

  1. Paste a multi-line block containing $$ or $& (shell or template-literal code, for example) into the prompt so it collapses to [Pasted ~N lines].
  2. Copy the prompt to the clipboard, or open it in the external editor.
  3. The text you get back differs from what you pasted.

Activity

  1. github-actions commented on Jun 24, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. github-actions commented on Aug 24, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

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