Skip to content

TUI: pasting a file path attaches the whole file even when it can't fit the model's context; no way to paste the path as text #57162

Open

Description

@iceteaSA

What happened: I pasted the path of a PDF into the TUI prompt, meaning to give the agent the path. The TUI turned the paste into a [PDF 1] attachment and sent the whole document. The request came to about 1.37M tokens, and the provider rejected it with prompt is too long: 1368578 tokens > 1000000 maximum. Recovering took a manual revert of that message. The PDF was well under the 20 MB local-attachment cap.

Current behaviour (checked on dev, packages/tui/src/component/prompt/local-attachment.ts): when the pasted text resolves to local files, they become attachments, up to 32 paths and MAX_LOCAL_ATTACHMENT_BYTES = 20 MB in total. The cap is in bytes. Nothing compares the attachment's likely token cost with the active model's context window, so a few-MB PDF can exceed a 1M-token model.

Requests:

  1. Before attaching, estimate the token cost (for PDFs, at least page count × a per-page estimate). If it won't fit the active model's remaining context, insert the path as plain text or ask, instead of sending a request that's bound to fail.
  2. A way to paste a path literally: a modifier, a setting, or an undo-to-text right after the paste. This overlaps Pasting an image file loses the original path — model only gets an inline data: URL #48190, which notes the path is lost once it becomes an attachment.

Related: #45558 (large attachments failing validation), #48190.

Activity

  1. opencode-agent commented on Oct 19, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report and for checking the code on dev.

    To restate: when a pasted path resolves to a local file, the TUI attaches the whole file and only checks its size in bytes, not its likely token cost against the active model's context window. You're asking for two things:

    1. Estimate the token cost before attaching (for PDFs, e.g. page count × a per-page estimate). If it won't fit the remaining context, insert the path as text or ask first.
    2. A way to paste a path as plain text: a modifier, a setting, or undo-to-text right after the paste.

    Right now the paste handling works as designed, so I've filed this as a feature request. Maintainers will consider it. This isn't something a plugin can do today, because plugins can't step into the TUI's paste-to-attachment handling.

    Related:

  2. beenotung commented on Oct 21, 2026

    @beenotung

    Related: #57698 reports the same root behaviour (a pasted PDF path becomes a [PDF 1] attachment) but a different failure mode.

    So they are not duplicates, but a "paste path as text" option (request 2 here) or an "attach images only" policy (proposed in #57698) would address both. Cross-linking so the relationship is explicit.

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