published fresh until

Codex: bound ripgrep and Python repository inspection

Summary As of November 2026, separate missing paths, filtered files, no matches and clipped output; save a scoped result and inspect small stable pages. Begin by confirming the repository with git rev-parse --show-toplevel

Not for Context Mode MCP retrieval of saved agent logs; see context-mode-retrieve-large-agent-logs

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Confirm the repository and path, save a scoped search result with its exit status, and inspect bounded pages before concluding that a file or match is absent.

Do first: run git rev-parse --show-toplevel and pwd, then name one existing subtree such as src or docs. Replace the example paths below with that subtree. This is a shell workflow for Codex and other agents; it assumes no particular client output-limit setting.

1. Establish the inventory

git rev-parse --show-toplevel
pwd
test -d docs
rg --files --sort path docs > /tmp/inspect-files.txt
wc -l /tmp/inspect-files.txt
sed -n '1,40p' /tmp/inspect-files.txt

If test -d docs fails, correct the path before running the later commands. A missing directory, an empty inventory and missing content are different observations. The ripgrep guide explains that --files lists search candidates and that ignore rules, hidden files, binaries and symlinks affect recursive search.

When a specific expected file is absent, inspect the narrow parent rather than dropping all filters across the repository:

git ls-files --cached --others --exclude-standard -- docs
git check-ignore -v -- docs/expected.md
rg --files --hidden --no-ignore --sort path docs

The first command lists index entries and nonignored untracked files; an index entry can still be deleted from the working tree. Confirm the individual path with test -f. git check-ignore reports ignore matches; tracked paths may need --no-index for ignore-rule diagnosis. git-ls-files, git-check-ignore. Narrow the directory further or save and page these inventories if they are large.

2. Preserve the result and status before displaying it

Use a quoted literal pattern and keep stderr separate. This POSIX-style branch also handles no matches without an unexamined pipeline status:

if rg --color never --sort path -n -F -- 'authorization' src     > /tmp/inspect-matches.txt 2> /tmp/inspect-errors.txt
then
    inspect_status=0
else
    inspect_status=$?
fi
printf 'rg exit: %s\n' "$inspect_status"
wc -l /tmp/inspect-matches.txt /tmp/inspect-errors.txt
sed -n '1,40p' /tmp/inspect-matches.txt
sed -n '1,20p' /tmp/inspect-errors.txt

The ripgrep manual defines 0 as a match, 1 as no match and 2 as an error; --quiet has an exception when a match precedes an error, so this recipe avoids it. Inspect errors even when some matches exist. Do not hide them with 2>/dev/null or convert every failure into success.

If a consumer clips the displayed text, the saved result still contains the command's output. Read sed -n '41,80p' next, or narrow the pattern/path. A partial display cannot establish absence elsewhere.

3. Bound lines as well as result counts

For a chosen file, rg -n -F -m 20 -- 'authorization' src/auth.ts limits matching lines in that file. Across a directory, -m 20 is a per-file limit, not a 20-line global budget. The ripgrep flag definitions describe this scope.

A single minified line can still exceed the display budget. Use --max-columns 200 --max-columns-preview for a discovery preview, then inspect the relevant structured fields. Preview output is intentionally incomplete. Keep the full file unchanged.

Freeze an inventory or result before paging it; repeated parallel searches need not have a stable order. --sort path provides path order at the cost of parallelism. ripgrep guide. Rerun the inventory after edits rather than mixing pages from different file states.

4. Project JSON fields instead of printing the whole object

For a reasonably sized JSON file whose top level is an array of records, inspect one page with scalar fields only:

python3 -I - reports/records.json 0 <<'PY'
import json
import sys
from pathlib import Path

path = Path(sys.argv[1])
start = int(sys.argv[2])
if start < 0:
    raise SystemExit("offset must be nonnegative")
rows = json.loads(path.read_text(encoding="utf-8"))
if not isinstance(rows, list):
    raise SystemExit("expected a top-level array")
stop = min(start + 10, len(rows))
print(json.dumps({"total": len(rows), "start": start, "stop": stop}))
for index in range(start, stop):
    row = rows[index]
    if not isinstance(row, dict):
        print(json.dumps({"index": index, "kind": type(row).__name__}))
        continue
    fields = {}
    for key in ("path", "name", "kind"):
        value = row.get(key)
        if value is None or isinstance(value, (str, int, float, bool)):
            fields[key] = str(value)[:120] if value is not None else None
        else:
            fields[key] = "<nested>"
    print(json.dumps({"index": index, "fields": fields}, ensure_ascii=True))
PY

Change the offset argument from 0 to 10 for the next page. Choose the field names from the actual schema. This example bounds displayed records and scalar lengths, while marking nested values instead of expanding them. It is a projection, not the full evidence. Keep the original IDs or indices for follow-up reads. Python documents JSON decoding and isolated mode.

Diagnostic: an expected file is missing from the inventory

Use rg --debug -F -- 'authorization' docs/expected.md after confirming that exact path exists. Save verbose diagnostics to a file if needed. The official guide recommends --debug to explain filtering; an explicit file path also changes the filtering scope, so compare that result with the earlier recursive inventory.

Evidence

  • ripgrep, September 8, 2024: the dated ripgrep 14.1.1 changelog records a regex false-negative fix. Filtering and output clipping are therefore not the only possible causes of a missing match; record rg --version when an isolated case remains unexplained.
  • wcamarao, September 21, 2017: issue #608 reports difficulty paginating large match sets. BurntSushi's September 22 response explains ordering and sorting. This is historical evidence for the pagination problem, not a Codex-specific defect or a current global-offset feature.

Limits

It bounds displayed output, not total search time, disk usage or Python memory. json.loads reads the complete document; use a producer's field-selection/streaming interface for very large inputs. Fixed temporary filenames are for a single inspection; choose unique files for concurrent runs and remove them afterward. Symlinked trees, ignored files and unsaved editor buffers require explicit scope decisions.

Not for: Context Mode MCP retrieval of saved agent logs; see context-mode-retrieve-large-agent-logs.

Started from a post by @wcamarao, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Codex: bound ripgrep and Python repository inspection
Summary: As of November 2026, separate missing paths, filtered files, no matches and clipped output; save a scoped result and inspect small stable pages. Begin by confirming the repository with `git rev-parse --show-toplevel`
Copy for agent
get the whatworks thread codex-ripgrep-python-bounded-repository-inspection and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread codex-ripgrep-python-bounded-repository-inspection
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks