tui: pasting a PDF path auto-attaches it, which text-only models cannot read · Issue #57698 · anomalyco/opencode · GitHub
Skip to content

tui: pasting a PDF path auto-attaches it, which text-only models cannot read #57698

Open

Description

@beenotung

Summary

Pasting a path to an existing PDF into the prompt auto-attaches the file as [PDF 1]. With a text-only model (no PDF input), sending the message fails, and there is no setting to disable this auto-attachment.

Environment

  • opencode version: 2.0.32
  • OS: Linux 7.2.9-arch1-1 (Arch Linux, x86_64)
  • Terminal: xterm-256color
  • Shell: /usr/bin/zsh
  • Install/channel: packaged binary at /usr/bin/opencode (latest)
  • Active plugins: none found in config

Reproduction

  1. Copy the absolute path of an existing PDF (e.g. /home/user/Downloads/paper.pdf).
  2. Paste it into the prompt.
  3. The prompt inserts a [PDF 1] attachment instead of the path text.
  4. Send the message with a model that does not accept PDF input.
  5. The request fails: this model does not support pdf input.

Reproducible consistently.

Expected Behavior

Pasting a document path should insert the path as text so the agent can read it with tools. Auto-attachment should be limited to images, which vision-capable models can consume — or there should be a setting to disable file-path auto-attachment.

Actual Behavior

Any pasted text that resolves to an existing binary file is attached. PDFs become [PDF n], which text-only models cannot read, so the turn fails instead of passing the path to the agent.

Additional Context

Relevant code: packages/tui/src/component/prompt/index.tsx

  • pasteInputText() computes pastedFilepath(text), calls readLocalAttachment(filepath), and for attachment.type === "binary" calls pasteAttachment().
  • pasteAttachment() labels PDFs as [PDF n] and images as [Image n].

Possible fixes (either):

  1. Only auto-attach images; insert everything else as text:
if (attachment?.type === "binary") {
  if (!attachment.mime.startsWith("image/")) {
    input.insertText(normalizedText)
    return
  }
  await pasteAttachment({ filename, filepath, mime: attachment.mime, content: ... })
  return
}
  1. Add a CLI setting (e.g. in ~/.config/opencode/cli.json), such as:
{ "prompt": { "paste_attach": "images" } }

with values images | all | never.

The second keeps the current behavior available for users who do want document attachments.

Activity

  1. opencode-agent commented on Oct 21, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report and the suggested fixes!

    To restate the request: when you paste a path to a local document such as a PDF, you'd like it inserted as plain text so the agent can read the file with its tools, instead of being turned into a [PDF n] attachment. You'd also like auto-attachment limited to images, or a setting such as prompt.paste_attach: images | all | never to control it.

    I checked the current code, and turning pasted image and PDF paths into attachments is intentional (packages/tui/src/component/prompt/local-attachment.ts). What's missing is a way to opt out, and any check of whether the active model accepts PDF input. So I've marked this as a feature request, and the maintainers will consider it. Note that the function names in your snippet don't quite match the current dev code (it now uses resolvePastedAttachments), so a patch would need adjusting. A plugin can't work around this today, because the plugin API has no hook into TUI paste handling.

    These open issues also cover pasted paths becoming attachments:

  2. beenotung commented on Oct 21, 2026

    @beenotung
    Author

    Related, but not a duplicate of #57162.

    Both stem from the same underlying behaviour — a pasted file path is auto-attached instead of inserted as text. A "paste as text" option would fix both, but the two reports document different user-facing failures and different triggers (document size vs. model capability), so neither is subsumed by the other.

  3. beenotung commented on Oct 21, 2026

    @beenotung
    Author

    Additional UX suggestion, in the same spirit as the existing pasted-text expansion:

    Make an auto-attached file chip expandable back to its source path.

    Today the TUI already has the pattern for long pastes: pasteText() stores the full text in the part and shows a virtual [Pasted ~N lines] placeholder (part.source.text.value), which is expanded back to the real text on submit (expandPastedTextPlaceholders in packages/tui/src/prompt/part.ts). A file attachment shows [PDF n] / [Image n] but has no way back.

    pasteAttachment() already keeps filepath on the file part, so the data needed for a reversal is present. Suggested behaviour:

    • Clicking the [PDF 1] chip (or a keybind / context action) detaches the file and replaces the chip with the path text, so the agent can read it with its tools.
    • Symmetrically, this could offer "attach instead" when a path is pasted as text.

    This gives an in-place recovery path for both failure modes: the context-size case in #57162 and the text-only-model case here — without needing to revert the message or re-type the path.

    It would also compose with the proposed prompt.paste_attach setting: the setting decides the default, and the chip lets the user override it per paste.

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