Skip to content

bug: run --file hardcodes text/plain MIME type for all files #16723

Closed as not planned

Description

@alexey-pelykh

Problem

The run command's --file flag hardcodes text/plain MIME type for all non-directory files, making binary file attachments (images, audio, video) non-functional.

In packages/opencode/src/cli/cmd/run.ts:

const mime = (await Filesystem.isDir(resolvedPath))
  ? "application/x-directory"
  : "text/plain"

Expected behavior

MIME type should be detected from the file (e.g. via extension or magic bytes) so that opencode run --file image.png -m "describe this" correctly passes the image as image/png.

Reproduction

opencode run --format json --file photo.jpg -m "describe this image"

The file is sent as text/plain regardless of actual content type, so the model receives corrupted/unusable binary data.

Suggested fix

Use file extension or content-based MIME detection (e.g. mime-types package or Node's built-in detection) instead of the hardcoded "text/plain" fallback.

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 9, 2026
  2. andrea-tomassi commented on Apr 18, 2026

    @andrea-tomassi

    I've been debugging this while working on a vision pipeline that uses opencode run --file screenshot.png with a vLLM-hosted multimodal model via the openai-compatible provider.

    Root cause in run.ts: Line 331 hardcodes mime: "text/plain" for all --file arguments. This causes prompt.ts to route images through the text/Read path (line 1065) instead of the binary/base64 multimodal path (line 1184+).

    I noticed PR #23291 adds MIME sniffing via magic bytes in message-v2.ts and read.ts, but the run.ts --file code path isn't covered there — so this issue would remain open even after that PR merges.

    Additional downstream issue: Even after fixing the MIME in run.ts, there's a second bug in @ai-sdk/[email protected]. The provider at line 158 constructs data:${mediaType};base64,${convertToBase64(part.data)}, but part.data arrives as a full data URL string (e.g. data:image/png;base64,...) from convertToModelMessages. Since convertToBase64() returns strings as-is, the result is double-encoded: data:image/png;base64,data:image/png;base64,.... This doesn't affect the dedicated @ai-sdk/openai or @ai-sdk/anthropic providers (they have their own message conversion), which likely explains why it's gone unnoticed — it only impacts openai-compatible users sending images via file attachment.

    I'm planning to file the AI SDK issue on vercel/ai separately. Happy to submit a PR for the run.ts fix here if that's welcome.

  3. assigned and unassigned on Apr 26, 2026
  4. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  5. added a commit that references this issue on May 7, 2026
    42ad864
  6. antl3x commented on May 7, 2026

    @antl3x
  7. github-actions commented on Jul 7, 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