Skip to main content
grep and rg can ask your VFS which files or lines may hold the text, instead of reading every file. Mirage still matches each line itself, so the output is the same. Return None (TypeScript: null) when your search cannot answer, and Mirage reads the file. For example, with Chroma at /knowledge/, grep -r refund /knowledge/ asks Chroma which documents contain refund and reads only those.

When grep and rg call these methods

Only when every match contains a plain text of 3 or more characters, such as refund in grep 'refund.*2026', or a -w or -x word of any length. They never call them with these flags, and read every file instead: grep and rg:
  • -v: print lines that do not match
  • -f FILE: read patterns from a file
grep only:
  • -i, when the text has a non-ASCII letter, or in a UTF-8 locale an i, k or s
rg only:
  • -i, or -S with a lowercase pattern, when the text has a k, an s or a non-ASCII letter and more than 16 ways to write its case
  • --passthru: print every line
  • --files-without-match: list files with no match
  • --json: print JSON
  • --stats: print statistics
  • -z: search compressed files
  • -L: follow symlinks
  • --pre COMMAND: preprocess each file
  • -E ENCODING: read files in an encoding
  • -c or --count-matches, with --include-zero

files_containing

Which files under a folder may contain a text.
Under rg -i, a text with a k, an s or a non-ASCII letter is asked once per way to write its case, with ignore_case False, since rg also matches k to the Kelvin sign K and s to ſ: rg -i café asks for café, CAFÉ and 14 other spellings. These commands call files_containing:
  • grep -r, grep -R, grep -d recurse
  • rg on a folder
A file named on the line is always read. This example extends NotesVFS from Custom VFS:
grep -rn mirage /notes then reads only the pages that contain mirage. mounted_path turns a name below the mount into a path.

lines_containing

Which lines of one file may contain a text.
Mirage matches your lines instead of reading the file for grep and rg with no flag, or with:
  • -c: count matching lines
  • -l: list files with a match
  • -q: print nothing, exit 0 on a match
  • -o: print only the matched text
  • -m N: stop after N matches
  • -i: ignore case
  • -w: match whole words
  • -x: match whole lines
  • -F: match the text literally
  • -r: search folders
  • -L: list files with no match (grep only)
Mirage reads the file only if your lines hold a match, and skips it if not, for grep and rg with:
  • -n: print line numbers
  • -b: print byte offsets
  • -A N, -B N, -C N: print lines around each match
  • more than one pattern, such as -e a -e b or 'a|b'
  • -z: lines end with NUL (grep only; --null-data in rg)
  • --column: print column numbers (rg only)
  • --vimgrep: print every match with its position (rg only)
  • -U: match across lines (rg only)
This example extends the same NotesVFS:
grep mirage /notes/todo.txt and grep -c mirage /notes/todo.txt then read nothing. grep -n mirage /notes/todo.txt reads the page, since it holds a match.

before_full_walk

Whether a command may copy, compare, change or remove every file under a folder.
These commands call before_full_walk: tar -c, zip -r, cp -r, rm -r, chmod -R, chown -R, chgrp -R, mv to another mount and diff -r. Mirage refuses more than the command’s walk_limit files before it asks, so the default lets the walk run.

walk_limit

The most files one command walks under a folder (TypeScript: walkLimit), a field of command_limits. A search counts only the files it reads, so a file files_containing rules out costs nothing. A listing counts every entry it lists, folders included. Each command exits as it does when some files could not be read, so a script treats a walk cut short as one with an error. A glob, a copy and a removal are refused instead of cut short, since running on part of what they name would look complete later. A glob in a for list stops the line with bash: /notes/*: matches more than <N> files (walk_limit); narrow the path. A walk that crosses into another mount counts that mount’s files against its own limit, and names that mount’s folder where it stops. Codex’s fs/walk (exec-server) lists the same way and returns truncated: true where it stops. It is 1000 unless your VFS starts at another value or a command_limits entry sets it:
grep -r mirage /notes on a folder of 600 pages that files_containing cannot narrow then prints the matches in the first 500 pages, and:

Built-in VFSs

These VFSs answer grep -r and rg with their service’s search. A pattern outside Searches, or a VFS not listed, reads every file. A search that can miss a match leaves out a file that holds the text, so grep does not print it. Every built-in VFS starts at 1000, or 5000 on GitHub, where each file is one request, and 10000 on disk, RAM and OPFS. A mount’s command_limits change it: the "@all" entry, for every command, else the workspace’s, sets the mount’s own walk_limit, and an entry named for one command, such as find, changes only how far that command walks. On the VFSs above from Google Drive to GitHub, the mount’s own -1 also turns the service’s search off, so every file is read and no match is missed:
grep -rw refund /slack/channels/ then asks Slack’s search which days mention refund and reads only those. grep -r refund /slack/channels/, which Slack cannot narrow, reads the first 5000 days and stops there.