Skip to content

bug: --file flag hardcodes all attachments as text/plain, breaking image/vision uploads #25353

@dominusbelial

Description

@dominusbelial

Bug description

When attaching files with the --file / -f flag, all files are hardcoded as text/plain regardless of their actual type. This means image files (PNG, JPEG, WebP, etc.) are injected as raw binary text garbage into the prompt instead of being base64-encoded and passed as proper data:image/... URLs to the LLM.

Root cause

In packages/opencode/src/cli/cmd/run.ts (~line 323):

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

Every file that is not a directory gets text/plain. The downstream pipeline already handles non-text MIME types correctly (reads binary, base64-encodes, creates data: URLs at session/prompt.ts line 1155) — it is simply never reached.

Impact

  • Image attachments are unusable via --file — vision models receive garbage
  • Audio/video/PDF attachments would have the same problem
  • The codebase already has extension-based MIME detection (getImageMimeType() in file/index.ts) but it is not used at the CLI entry point

Proposed fix

Replace the hardcoded text/plain fallback with a helper that maps known file extensions to MIME types, defaulting to text/plain for unknown extensions.

Environment

  • OpenCode version: 1.14.28
  • Provider: ollama (vision models like gemma4, qwen3-vl)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions