Skip to content

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

Closed as not planned

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)

Activity

  1. github-actions commented on May 1, 2026

    @github-actions
    Contributor

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

    Please review those issues and consider closing this one if they cover the same problem.

  2. github-actions commented on Jul 3, 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