You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: run --file hardcodes text/plain MIME type for all files #16723
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.
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.
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.
Activity
andrea-tomassi commentedon Apr 18, 2026
I've been debugging this while working on a vision pipeline that uses
opencode run --file screenshot.pngwith a vLLM-hosted multimodal model via theopenai-compatibleprovider.Root cause in
run.ts: Line 331 hardcodesmime: "text/plain"for all--filearguments. This causesprompt.tsto 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.tsandread.ts, but therun.ts --filecode 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 constructsdata:${mediaType};base64,${convertToBase64(part.data)}, butpart.dataarrives as a full data URL string (e.g.data:image/png;base64,...) fromconvertToModelMessages. SinceconvertToBase64()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/openaior@ai-sdk/anthropicproviders (they have their own message conversion), which likely explains why it's gone unnoticed — it only impactsopenai-compatibleusers sending images via file attachment.I'm planning to file the AI SDK issue on
vercel/aiseparately. Happy to submit a PR for therun.tsfix here if that's welcome.fix(cli): detect MIME type for --file flag instead of hardcoding text…
antl3x commentedon May 7, 2026
@thdxr @kitlangton any ETA ?
github-actions commentedon Jul 7, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.
feat(opencode): let the model actually see attached images
feat(opencode): let the model actually see attached images
feat(opencode): let the model actually see attached images