Attachments
Attach
Attach a local file, then ask OpenCode to use it in your prompt. In the desktop or web client, choose Attach file, paste a file, or drag it into the prompt.
Summarize the attached README.md and list the required setup steps.
Desktop file-picker selections can total up to 20 MiB. Other interfaces may apply lower client-side limits.
Syntax
V2 prompt and command inputs describe an attachment with a uri and optional
name and description:
{
"uri": "file:///home/me/project/src/server.ts",
"name": "server.ts",
"description": "HTTP server entrypoint"
}
Use an absolute file: URL for a file or directory that is available to the
server. For text files, positive start and end parameters select one-based
lines.
file:///home/me/project/src/server.ts?start=20&end=60
Use a data: URL to send content inline:
{
"uri": "data:text/plain;base64,SGVsbG8sIE9wZW5Db2RlIQ==",
"name": "greeting.txt"
}
HTTP and HTTPS attachment URLs are not supported. See the generated API reference for programmatic prompt submission.
Formats
Current V2 sessions make these attachment types visible to the model:
| Input | Model receives | Example |
|---|---|---|
| UTF-8 text file | Filename and decoded text | README.md |
| Directory | Non-recursive listing of immediate files and directories | file:///home/me/ |
| PNG, JPEG, GIF, or WebP | Image media | diagram.png |
SVG is treated as text. PDF, AVIF, BMP, audio, video, and other binary prompt
attachments are not included in the model request. Convert an unsupported
binary to text or a supported image first; for example, export a PDF page as
page-1.png before attaching it.
OpenCode reads each attachment before admitting the prompt. It rejects invalid
URLs, unreadable paths, paths other than files or directories, and decoded
attachments over 20 MiB. Media type is detected from the bytes, so changing a
filename or data: URL media type does not make an unsupported binary visible.
Images
Configure image normalization in opencode.json or opencode.jsonc:
{
"$schema": "https://opencode.ai/config.json",
"media": {
"image": {
"auto_resize": true,
"max_width": 2000,
"max_height": 2000,
"max_base64_bytes": 5242880,
},
},
}All fields are optional:
| Field | Default | Behavior |
|---|---|---|
auto_resize | true | Resize an image over a configured limit; when false, reject the image. |
max_width | 2000 | Maximum width in pixels; must be a positive integer. |
max_height | 2000 | Maximum height in pixels; must be a positive integer. |
max_base64_bytes | 5242880 | Maximum bytes in the Base64-encoded image; must be a positive integer. |
For example, this rejects rather than resizes an image wider than 1200 pixels:
{
"media": {
"image": {
"auto_resize": false,
"max_width": 1200,
},
},
}These settings apply both to supported images attached to prompts and to images
returned by the built-in read tool.
Processing
The read tool recognizes PNG, JPEG, GIF, and WebP by their contents and reads
up to 20 MiB of source image data. It checks width, height, and Base64 length
against the configured image limits.
With auto_resize: true, OpenCode preserves the aspect ratio and scales down
to the dimension limits. It then tries progressively smaller PNG and JPEG
encodings until the Base64 limit is met, so the output media type can change.
Input: 4000 × 2000 WebP
Limits: 2000 × 2000
Output: 2000 × 1000 PNG or JPEG
If no encoding fits, processing fails. With auto_resize: false, an image that
exceeds any limit fails without modification; an image that cannot be decoded
also fails.
Input: 2400 × 1600 JPEG
Limit: max_width = 2000, auto_resize = false
Result: Image processing fails
If the image resizer is unavailable, OpenCode passes the original image through unchanged. Image settings are therefore processing limits, not an upload or security boundary.
Limits
| Limit | Value or behavior | Example |
|---|---|---|
| Direct attachment | 20 MiB decoded per item; clients may impose lower limits | Two 12 MiB files pass the per-item limit |
| Desktop picker selection | 20 MiB total | Two 12 MiB files exceed the selection limit |
max_base64_bytes | Encoded Base64 only, excluding the complete data: URL | SGVsbG8= counts as 8 bytes |
| Provider image limits | Apply after OpenCode processing | A provider may reject an accepted image |
| Text attachment model support | Does not require a multimodal model | notes.txt is inserted as prompt text |
read text limits | Uses separate paging and truncation limits | Read a large log in pages |
A client accepting a file does not guarantee that its contents reach the model. The attachment must use a model-visible format and satisfy both OpenCode and provider limits.