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
Read tool fails to read image files even with vision-capable models (paste works) #11306
When using a vision-capable model through OpenCode, the Read tool fails to read image files from disk, reporting that the model cannot read images. However, pasting the same image directly into the chat works perfectly.
Steps to Reproduce
Configure a vision-capable model (e.g., Gemini 3 Pro, Claude Sonnet 4.5) with proper modalities:
Ask the model to read the image file using the Read tool
Observe error: "Failed to read image: [path], model may not be able to read images"
Paste the same image directly into chat - it works fine
Expected Behavior
The Read tool should recognize that the model supports vision input (via modalities config) and successfully read image files, just like pasted images work.
Actual Behavior
Pasted/dragged images: Works
@image.png syntax: Works
read(image.png) via Read tool: Fails with model capability error
Configuration
Models already have correct modalities configured:
This issue might be a duplicate of existing issues. Please check:
Unable to read images for some models #5359: Unable to read images for some models - Similar issue with pasted images showing the model cannot read images despite being image-capable
Hey @OpeOginni, apologies for the confusion - I wasn't using the antigravity provider. I'm experiencing this issue with Kimi K2.5 through the MoonshotAI provider via OpenRouter.
Reference an image using @path/to/image.png → Works fine
Ask the agent to "read more images in that folder"
Agent autonomously uses the Read tool to access images → Blows out context window
The Issue
Method
Result
Manual copy-paste
✅ Works
@path/to/image.png explicit reference
✅ Works
Agent autonomously calls Read tool on image path
❌ Blows out context window
The problem only occurs when the agent autonomously decides to read an image - not when I explicitly reference it with @ or paste directly. This suggests the Read tool may be encoding/sending images differently than the explicit @ reference mechanism.
Reacted by Damian S, Daniel Mondragón and Felipe Santos
I conducted an exhaustive investigation using parallel subagents and sequential thinking, and I believe I've identified the root cause of this issue.
Summary
Root Cause: Tool output attachments are converted to a non-standard type: "media" format that bypasses modality validation and causes providers to incorrectly tokenize base64 image data as text, resulting in 500-600x context window explosion.
Modality Bypass: unsupportedParts() in transform.ts:213 only checks type: "file" and type: "image", not type: "media" - so images bypass vision capability validation
Format Mismatch: OpenRouter expects type: "image_url" but receives type: "media"
Provider Fallback: Unknown "media" type triggers JSON.stringify fallback
Text Tokenization: Base64 image data (e.g., 10KB = 13,333 chars) is tokenized as text (~13,333 tokens) instead of as image (~1,500-2,000 tokens)
Why Paste/@ Works
Both use type: "file" which:
Passes through modality check in transform.ts:unsupportedParts()
Gets converted to proper type: "image_url" format by existing conversion pipeline
Provider recognizes format correctly
Proposed Fix
Preserve type: "file" instead of converting to type: "media":
// AFTER (FIXED):
...attachments.map((attachment)=>({type: "file",// ← Preserve standard typemime: attachment.mime,// ← Keep mimeurl: attachment.url,// ← Keep full data URL with prefixfilename: attachment.filename||"image"// ← Add filename}))
This single change:
✅ Reuses existing modality check
✅ Reuses existing conversion pipeline
✅ Prevents context blowout
✅ Works for all providers
I've written a comprehensive analysis report with more details: Desktop Report
I encountered a similar issue. I am using qwen3.5 9b. It can describe image and put the description into the session/chat title, but its response said the model can not receive image input. I'm confused lol.
Activity
github-actions commentedon Jan 30, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if your specific case differs or involves additional context.
OpeOginni commentedon Jan 30, 2026
Hey @deleon626 does this nly happen while using
antigravityas your model provider?deleon626 commentedon Jan 31, 2026
Hey @OpeOginni, apologies for the confusion - I wasn't using the
antigravityprovider. I'm experiencing this issue with Kimi K2.5 through the MoonshotAI provider via OpenRouter.Configuration
Environment
Reproduction Steps
moonshotai/kimi-k2.5model@path/to/image.png→ Works fineReadtool to access images → Blows out context windowThe Issue
@path/to/image.pngexplicit referenceReadtool on image pathThe problem only occurs when the agent autonomously decides to read an image - not when I explicitly reference it with
@or paste directly. This suggests the Read tool may be encoding/sending images differently than the explicit@reference mechanism.deleon626 commentedon Jan 31, 2026
Potential Root Cause Identified
I conducted an exhaustive investigation using parallel subagents and sequential thinking, and I believe I've identified the root cause of this issue.
Summary
Root Cause: Tool output attachments are converted to a non-standard
type: "media"format that bypasses modality validation and causes providers to incorrectly tokenize base64 image data as text, resulting in 500-600x context window explosion.Bug Location
File:
packages/opencode/src/session/message-v2.ts:464The
toModelOutput()function unnecessarily convertstype: "file"attachments totype: "media":Why This Causes Context Blowout
unsupportedParts()intransform.ts:213only checkstype: "file"andtype: "image", nottype: "media"- so images bypass vision capability validationtype: "image_url"but receivestype: "media"Why Paste/@ Works
Both use
type: "file"which:transform.ts:unsupportedParts()type: "image_url"format by existing conversion pipelineProposed Fix
Preserve
type: "file"instead of converting totype: "media":This single change:
I've written a comprehensive analysis report with more details: Desktop Report
Would you like me to open a PR with this fix?
zuojianghua commentedon Feb 3, 2026
same issue at v1.1.48. it read image binary data. then llm context oversized
bupthcp commentedon Feb 26, 2026
Still got the problem on opencode version v1.2.15. Tested it both on Mac and ubuntu 22.04.
giricahunik commentedon Mar 8, 2026
I encountered a similar issue. I am using qwen3.5 9b. It can describe image and put the description into the session/chat title, but its response said the model can not receive image input. I'm confused lol.
mtomas7 commentedon Mar 10, 2026
Please see if this config tip will help: #15728 (comment)
humarobot commentedon Mar 12, 2026
@mtomas7 Excellent!This works!