Dive

Guides

Work with files

Keep the files MCP tools return, of any type, save text as files, and pass them to models and other tools by reference.

When an MCP tool returns a file, such as a browser screenshot or a CSV export, Dive stores it and gives the agent a short reference to it instead of the bytes. The agent can pass that reference to another tool, and Dive hands the tool the file in the form it expects.

[mcp.browser]
command = "npx"
args = ["-y", "@playwright/mcp"]
files = "path"

[storage.files]
backend = "s3"
endpoint = "https://s3.example.com"
bucket = "dive-files"
region = "us-east-1"
access_key_id = "${DIVE_S3_KEY_ID}"
secret_access_key = "${DIVE_S3_SECRET}"

What a tool's result looks like

Dive stores every file in a tool's result: inline image and audio content, embedded resources with binary or text contents, and resource_link items of any type, which Dive reads from the server, up to 50 MB each. The result lists them under files, next to whatever text or structured content the tool returned:

{
  "text": "Captured https://example.com",
  "files": [
    {
      "ref": "blob:sha256-5d41402abc4b2a76b9719d911017c592a7c1d1d4b2fb7b1f9d1c1e1e2c1a3f4e.png",
      "mime": "image/png",
      "bytes": 48213,
      "width": 1280,
      "height": 800
    }
  ]
}

When the tool's result isn't an object, or already has its own files key, Dive puts it under result instead, as {"result": …, "files": […]}.

A reference's extension carries the file's type: any lowercase extension of up to 16 letters and digits, such as .png, .css or .parquet. A type Dive doesn't recognize keeps its extension and reads as application/octet-stream.

A reference names the file by its SHA-256 hash, so the same image stored twice is kept once. It stays the same wherever the file is kept, and threads and plan results that mention it keep working if you move file storage to another backend and copy the files across.

Deleting a thread removes the files no other thread refers to, except in S3 storage, where other machines may share the bucket. Files kept in S3 or in memory are copied to a local cache when a tool needs a path. The cache holds up to 512 MB and drops the least recently used files past that.

What the model sees

Every model that reads a file reference sees the image, not just the reference: a conversation agent and its subagents, an agent step, builtin__infer, an infer gate, the solver, a prompt tool, and a decision model behind a decide gate, builtin__decide, builtin__rank or a decision tool. Dive finds the references in what the model reads (the messages, tool results, a step's input, an instruction) and sends each image with the request:

  • Attached images: images attached to a message you send. The model also gets their references, so it can pass them to builtin__generate_image to edit them.
  • Tool images: images in a tool's result, wherever a reference to one appears.
  • Images a plan passes on: a reference rendered into a step's input or an instruction, such as "Is there a pricing table on this page? {{shot.files.0.ref}}". A reference counts whether it's the whole value or part of longer text.

PNG, JPEG, GIF and WebP files are sent this way, and so are PDFs, as documents, to Anthropic models; providers without PDF input leave them out with a warning in the log. Every image stays in the conversation and is sent again on each turn.

A text file, such as JSON, CSS, HTML, Markdown or CSV, is read as text when its reference appears in a message or instruction a model reads: an infer question, an agent step's task, a prompt tool's prompt or a message you send. Its content follows the text, headed by [file <ref> · <type> · <size>], up to 100 KB; past that it's cut off with a note to read the rest with builtin__read_file. A text file's reference in a tool result is not expanded, so an agent that keeps references in its context doesn't carry every file's content; it reads one with builtin__read_file when it needs it.

A model role takes images unless it says otherwise. For a text-only model, set images = false on its role, or on one of its fallbacks:

config.toml
[models.judge]
provider = "local"
model = "qwen3:8b"
images = false

Requests to that model carry a note naming the images it wasn't sent, instead of the images. The note goes with the message or tool result that names them, under images_not_sent in a tool result, so earlier turns stay the same from one call to the next and the provider's prompt cache keeps working. The call's recorded input lists the refs under images_not_sent too, which is how the desktop app marks them in a call's detail. Plan validation reports a step that sends a file to such a role, wherever the tool's output schema or recorded shape shows the value is a file. When a recorded shape's example is shown to a model, through describe_tool or a builder's tool list, each ref in it reads blob:sha256-<hash>.png. The model sees the shape of the result without being sent the file.

Chat models get an image as it is when it fits: at most 2576 pixels a side, the most a Claude model looks at, or 2000 when a request carries more than 20 images, and under 3.75 MB, which is 5 MB once encoded. A larger one, such as a full-page screenshot of a long site, is shrunk to fit with its shape kept, and a PNG, GIF or WebP that needs shrinking is sent as a PNG. The stored file stays at full size.

Decision models get images through TypeSafe, which needs a Jev model that accepts images. Dive sends PNG and JPEG as they are, converts GIF and WebP to PNG, and scales each image to between 280 and 1568 pixels a side.

Show a file in a reply

Every conversation agent is told about files and refs in its system prompt, after its own system_prompt. To show the user a file, an agent writes it into its reply as a markdown image with the ref as the URL:

The pricing page highlights the Team plan:

![The Acme pricing page](blob:sha256-5d41402abc4b2a76b9719d911017c592a7c1d1d4b2fb7b1f9d1c1e1e2c1a3f4e.png)

The desktop app draws the image in the message. In a terminal the markdown shows as written. The agent chooses which files to show, so a screenshot it only used to read the page stays in the tool's result.

Save and read text

builtin__save_file stores text or JSON a plan or agent already has, and returns its reference. builtin__read_file returns a text file's content, and its JSON when it parses:

plan.yaml
- id: backup
  tool_name: builtin__save_file
  input:
    name: "{{input.project_id}}-css.json"
    content: "{{project.customCss}}"
- id: restore
  tool_name: builtin__read_file
  input:
    ref: "{{backup.ref}}"

Files a step writes

Some tools write a file to disk and return only a path or a link as text, such as Playwright's browser_evaluate and browser_take_screenshot with a filename. A plan step declares those files under files, and Dive picks them up after the call:

plan.yaml
- id: shot
  tool_name: playwright__browser_evaluate
  files:
    snapshot: { name: snapshot.json }
  input:
    function: "() => document.title"
    filename: "{{files.snapshot.path}}"
- id: read
  tool_name: builtin__read_file
  input:
    ref: "{{shot.files.snapshot.ref}}"
  1. Before the call, Dive makes a directory for it under .dive/files/tmp/ in the project (~/.config/dive/files/tmp/ in the global workspace) and fills the step's files root: {{files.<name>.path}} is the file's path in that directory, and {{files.<name>.dir}} the directory. Each call gets its own, so a map running items in parallel never mixes them up.
  2. Pass the path to the tool's own option for where to write, here Playwright's filename.
  3. After the call, each declared file is stored and listed under the result's files with its name: {{shot.files.snapshot.ref}}. If the tool also returned the same file, the two are one entry. The directory is then removed.

A name with * or ?, such as page-*.png, collects every file in the directory that matches, in natural order (page-10.png after page-9.png), as a list: {{pages.files.pages}}, or {{pages.files.pages.0.ref}} for the first. Pass {{files.<name>.dir}} for a pattern, so the tool names the files itself.

A declared file the tool didn't write, or a pattern with no match, fails the step, unless the declaration says optional: true. Plan validation reports a declaration whose path or directory the step never passes, .path on a pattern, two declarations that can match the same file, and a name no step declared.

Dive tells MCP servers that the project directory is their workspace, through the MCP roots list, so a server that only writes inside its workspace, like Playwright, accepts these paths. Servers on another machine can't write to them; they need to return the file in their result.

Pass a file to another tool

Any argument whose whole value is a reference is replaced before Dive calls the tool. A reference inside longer text is left as it is. Each server's files setting decides what the tool receives:

filesThe tool receives
path (default)A path to the file on this machine. Files kept in S3 or in memory are copied to a local cache first.
urlA link the server can fetch: a presigned link valid for an hour when files are in S3, otherwise a file:// URL.
base64The file's contents, base64-encoded.
offThe reference text unchanged.

Use url for a server running on another machine, which can't read your local paths, and base64 for a server that only accepts file contents in its arguments. Most local servers take a path.

If Dive can't read a referenced file, the tool isn't called and the agent gets an error naming the reference.

Files in your own tools

An exec tool takes files the same way. Give an input property format: blob, or an array whose items have it, and a reference passed there reaches the command as a local path.

The files the command writes are declared under files, like a plan step's: pass {{files.<name>.path}} in args, and the file comes back under the result's files with its name:

tools/thumbnail.yaml
version: 4
name: thumbnail
description: Shrinks an image to 256 pixels wide and returns the copy.
kind: exec
command: sips
args: ["-Z", "256", "{{input.image}}", "--out", "{{files.thumb.path}}"]
output: text
files:
  thumb: { name: thumb.png }
input_schema:
  type: object
  required: [image]
  properties:
    image: { type: string, format: blob }

A plan reads it as {{shrink.files.thumb.ref}}. For an unknown number of files, declare a pattern such as page-*.png and pass {{files.pages.dir}}; the matching files come back as a list, in natural order. Each call gets its own empty directory, which Dive removes once the call ends. A declared file the command didn't write is a tool error unless the declaration says optional: true, and loading the tool fails when a declared file never appears in args.

Tools written before version 4 can still write to the directory in $DIVE_OUT; whatever lands there is listed under files without a name. Plan validation reports a step that passes a file reference to an exec input that isn't format: blob, which would reach the command as text. builtin__generate_image returns the images it draws as references too, under images; see Image models.

Where files are kept

Without a [storage.files] table, files follow [storage].backend: under <data_dir>/files for file, and in memory for memory, which keeps nothing between runs.

To keep files somewhere else, set [storage.files].backend:

  • file keeps files under <data_dir>/files.
  • memory keeps files only for the length of the run.
  • s3 keeps files in an S3 bucket, or a bucket on an S3-compatible server such as Garage or MinIO. Set endpoint for an S3-compatible server, and region to the region it expects. Files are kept under files/ in the bucket, or under <prefix>/files/ when you set prefix, so several stores can share a bucket.

Credentials expand ${NAME} references like the rest of config.toml, so you can keep them in the OS credential store with dive secret set DIVE_S3_SECRET. When access_key_id and secret_access_key are omitted, Dive reads the standard AWS_* environment variables. If a referenced secret isn't set, Dive still starts. A tool call that receives a file then fails naming the missing variable, and files a tool returns are left out of its result, with a warning in the log.