Start typing to search the documentation.

Docs navigation

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:

InputModel receivesExample
UTF-8 text fileFilename and decoded textREADME.md
DirectoryNon-recursive listing of immediate files and directoriesfile:///home/me/
PNG, JPEG, GIF, or WebPImage mediadiagram.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:

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:

FieldDefaultBehavior
auto_resizetrueResize an image over a configured limit; when false, reject the image.
max_width2000Maximum width in pixels; must be a positive integer.
max_height2000Maximum height in pixels; must be a positive integer.
max_base64_bytes5242880Maximum bytes in the Base64-encoded image; must be a positive integer.

For example, this rejects rather than resizes an image wider than 1200 pixels:

opencode.jsonc
{
  "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

LimitValue or behaviorExample
Direct attachment20 MiB decoded per item; clients may impose lower limitsTwo 12 MiB files pass the per-item limit
Desktop picker selection20 MiB totalTwo 12 MiB files exceed the selection limit
max_base64_bytesEncoded Base64 only, excluding the complete data: URLSGVsbG8= counts as 8 bytes
Provider image limitsApply after OpenCode processingA provider may reject an accepted image
Text attachment model supportDoes not require a multimodal modelnotes.txt is inserted as prompt text
read text limitsUses separate paging and truncation limitsRead 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.