Search Files from the Terminal with grepaf
A grepaf command on your PATH that searches files and piped input with the grep flags you already use, and emits JSON for scripts and agents
The Result
You type grepaf where you would type grep. It searches a directory tree with no server and no index, and prints matches in the familiar path:line:text form:
grepaf --no-heading -n --sort path deadline notes
notes/launch.md:3:Code freeze deadline is Friday at noon.
notes/standup.md:4:Dev: no deadline pressure on docs this week.
Before You Start
macOS 15 or later on Apple silicon, or Linux on x86-64 or ARM64, with ~/.local/bin on your PATH:
echo "$PATH" | tr ':' '\n' | grep -x "$HOME/.local/bin"
If that prints nothing, add export PATH="$HOME/.local/bin:$PATH" to your shell profile and open a new terminal. You do not need Antfly running for anything in this guide.
Build It
1. Install grepaf
From a checkout of this project with Zig 0.17.0, build and install the executable directly:
(cd zig && zig build -Dgrep-only=true -Doptimize=fast --prefix "$HOME/.local" grepaf)
grepaf --version
Install a published release
Releases use tags of the form grepaf/v<version>. Once the first release under that prefix and the site's installer are available, install the binary, manpage, and shell completions with:
curl -fsSL https://antfly.io/grepaf/install.sh | sh
The site installer verifies the archive against the release's SHA256SUMS before running the installer inside it. Set GREPAF_VERSION to choose a published version, GREPAF_PREFIX to change the install prefix from ~/.local, or GREPAF_LIBC=gnu for the glibc 2.28+ Linux build used for in-process models.
To install by hand on Apple silicon, choose a published grepaf/v… tag from the GitHub Releases page. Enter the version without the tag prefix:
(
set -eu
printf 'Release version: '
read -r VERSION
ARCHIVE="grepaf_${VERSION}_Darwin_arm64.tar.gz"
BASE="https://github.com/antflydb/antfly/releases/download/grepaf/v${VERSION}"
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
cd "$WORK"
curl -fsSLO "$BASE/$ARCHIVE"
curl -fsSLO "$BASE/SHA256SUMS"
awk -v name="$ARCHIVE" '$2 == name' SHA256SUMS | shasum -a 256 --check
tar -xzf "$ARCHIVE"
./install.sh --prefix "$HOME/.local"
"$HOME/.local/bin/grepaf" --version
)
On Linux, use the Linux_x86_64 or Linux_arm64 archive suffix (add _gnu for the glibc build) and verify with sha256sum --check.
2. Search Files
Make two small files to search:
mkdir notes
cat > notes/launch.md <<'EOF'
# Launch plan
Code freeze deadline is Friday at noon.
Billing migration is not ready, so the launch moves one week.
Retry budget for the importer is three attempts.
EOF
cat > notes/standup.md <<'EOF'
# Standup
Maya: the pricing page needs a second review.
Dev: no deadline pressure on docs this week.
EOF
A pattern and a path search the tree recursively. Flags combine the way they do in grep, and the pattern is a regular expression unless you pass -F:
grepaf --no-heading -in 'RETRY|pricing' notes
notes/standup.md:3:Maya: the pricing page needs a second review.
notes/launch.md:5:Retry budget for the importer is three attempts.
Files are scanned concurrently, so the order of files in the output can change between runs. Pass --sort path when you need a stable order. -l lists matching files, -c counts matching lines per file, and -C 2 adds two lines of context.
3. Use It in Pipes and Scripts
With no path and input on stdin, grepaf searches the stream:
cat notes/launch.md | grepaf -n launch
4:Billing migration is not ready, so the launch moves one week.
The exit status is 0 when something matched, 1 when the search finished with no match, and 2 for an error or an incomplete search. A script can branch on that with -q, which prints nothing:
grepaf -q deadline notes && echo found
found
--json prints one JSON object per line: begin, match, and end events for each file, then a summary. This is the form to hand to a script or an agent:
grepaf --json deadline notes \
| jq -r 'select(.type == "match") | "\(.data.path.text):\(.data.line_number)"'
notes/standup.md:4
notes/launch.md:3
4. Hand It to a Coding Agent
Agents search with ripgrep by default. An opt-in hook for Codex rewrites simple local rg calls to grepaf, so the agent keeps typing what it knows. Copy the handler into your Codex hooks directory:
mkdir -p ~/.codex/hooks
curl -fsSL -o ~/.codex/hooks/grepaf_local_rg.py \
https://raw.githubusercontent.com/antflydb/antfly/main/zig/pkg/grepaf/examples/codex/local_rg.py
Register it in the project's .codex/hooks.json, merging with any hooks already there:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{ "type": "command", "command": "python3 ~/.codex/hooks/grepaf_local_rg.py" }
]
}
]
}
}
Open Codex in the project and run /hooks to review and trust it. You can check the handler without Codex by sending it the event it would receive:
echo '{"hook_event_name":"PreToolUse","tool_name":"Bash","tool_input":{"command":"rg -n deadline notes"}}' \
| python3 ~/.codex/hooks/grepaf_local_rg.py
{"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "allow", "updatedInput": {"command": "env -u GREPAF_TABLE_CONFIG /Users/you/.local/bin/grepaf --no-config -n deadline notes"}}}
The handler prints {} and leaves the command alone when it is anything other than a plain rg call: a pipe or other shell operator, a variable expansion, a flag it does not recognize, or a set RIPGREP_CONFIG_PATH.
Beyond local files
The same command searches other things once they are set up. Each needs configuration this guide does not cover:
| To search | Add | Needs |
|---|---|---|
| Files with a question in plain language | --ask 'Where is the retry budget set?' | A decision model: GREPAF_MODEL, and GREPAF_ENDPOINT if it is not the local default |
| Tables in an Antfly you run | --table-config tables.json --table NAME | A table profile file, and GREPAF_TABLE_TOKEN when the instance requires auth |
| Sources connected in Antfly Cloud | --source NAME, or --source all for every source | antfly-cloud login and a selected instance |
--source-list prints each connected source's ID, alias, and publication status, and --source-list --json prints the same as a JSON array. Run it first to see what --source accepts. Without a model, --ask stops with DecisionModelRequired and exit status 2.
The hook in step 4 covers local files only. For an agent that should also search connected sources, add this to the project's agent instructions: "For connected content, run grepaf --source-list --json, then search the chosen ID with grepaf --source ID PATTERN. Use --source all when the user requests all sources."
Next Steps
- Query Antfly with SQL and psql when you want to filter and aggregate a table, where grep only finds lines.
- Index recorded calls and podcasts to get recordings into a table as transcripts, which is the form
grepafcan search. - The grepaf source for the code, and its README for table profiles, model providers, and every flag.