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)
Bug description
When attaching files with the
--file/-fflag, all files are hardcoded astext/plainregardless 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 properdata:image/...URLs to the LLM.Root cause
In
packages/opencode/src/cli/cmd/run.ts(~line 323):Every file that is not a directory gets
text/plain. The downstream pipeline already handles non-text MIME types correctly (reads binary, base64-encodes, createsdata:URLs atsession/prompt.tsline 1155) — it is simply never reached.Impact
--file— vision models receive garbagegetImageMimeType()infile/index.ts) but it is not used at the CLI entry pointProposed fix
Replace the hardcoded
text/plainfallback with a helper that maps known file extensions to MIME types, defaulting totext/plainfor unknown extensions.Environment