# File Reading Tools

Tools that find, read and open files.

| Tool | Description |
|---|---|
| `find_files` | Locate files (`queries: [{dir, pattern, file_pattern, recursive}]`). `mode=list` returns a directory's entries (alphabetical), `mode=glob` matches paths against a filename pattern and, since v1.0.23, returns them most recently modified first, `mode=search` greps file contents by RE2 regex. Mode is inferred when omitted: `pattern` + `file_pattern` → search, `pattern` alone → glob, neither → list. Glob patterns must carry a literal — all-wildcard (`**/*`) is rejected. Matches merge and deduplicate across queries. `mode=list` and `mode=glob` are capped at 128 KiB in total and the tail reports how many entries were dropped. Since v1.0.11 `mode=search` is paged instead of truncated: `output=files` (the default) returns one `{path, count, lines}` row per matching file — since v1.0.23 `lines` carries the row numbers of its first five matches, ready for `read_files` `lines` — `output=content` returns the matching lines with their line numbers, `multiline=true` (v1.0.23) matches the regex against whole files so `.` crosses newlines and reports every row a match spans, `offset` / `limit` (default 256) walk the pages, and `context_lines` adds surrounding lines — marked `context: true` and not counted toward `offset` / `limit`. A single match line is cut at 512 bytes. Every page ends with `[files a-b of N ...]` / `[lines a-b of N ...]` carrying the next `offset`, or `last page`; the queries and `output` must stay identical between pages |
| `read_files` | Batched read of one or more files (`files: [{path, offset, limit, lines, context_lines, full}]`); text, PDF, DOCX, PPTX, CSV/TSV, image, or audio/video — a media file comes back as a verbatim transcript through the configured speech-to-text model, so there is no separate transcription tool. Reads up to 2048 lines by default (1 MiB cap for documents, 10 MiB for images); `offset`/`limit` page through larger files — page for PDF, slide for PPTX, row for CSV. Since v1.3.21 `lines` takes 1-based rows of a plain-text file and reads `context_lines` lines (default 64, `0` = the rows alone) on each side, merging overlapping windows and marking skipped text with a `...` line (`offset`/`limit` are then ignored), and the same path may appear more than once in `files`, its results joined in order. Since v1.0.11 a truncated text read ends with `[lines a-b of N; call again with offset=... for more]`, so the continuation offset never has to be guessed. Text lines arrive as `"<row>\t<line>"`; the number is added by the reader and is not in the file, so it must be stripped before a line is reused as an `write_file` anchor. Must be called before `write_file` changes an existing file: since v1.0.23 the edit is refused unless the file was read in this run and its modification time is unchanged since that read. Since v1.3.21 a decision model can filter the result against the task. At 16,384 runes or more, it checks individual blocks and marks omissions. Content is kept when no decision model is configured or the check fails. Set `full: true` on a file entry to bypass filtering without changing pagination or line selection; use it and read all pages before a full rewrite |
| `open_file` | Open a file or URL with the OS default handler (play a video, view an image, open a PDF viewer; since v1.2.1 also a link or a system settings pane such as `x-apple.systempreferences:...`). A URL always asks the user to confirm. Replaces `run_command` `open`/`xdg-open`, which the sandbox cannot reach. 10 s cap |

Removed in v1.3.21: `read_files` uses `lines` and `context_lines` in place of `around` and `context`; `find_files` uses `context_lines` in place of `context`; `write_file`, `remove_file`, and `restore_file` use `filename` in place of `path`.
