agentleFS
MicrosoftKnown publishermicrosoft/tgrep/AGENTS.md

tgrep

AGENTS.md3.4k starsChanged 2 months agoMITView on GitHub

A short guide for AI agents (and the humans who wire them up) that want to use tgrep as a fast search tool inside a repository. It complements the README, which documents every flag; this file covers the few things an agent has to get right. tgrep is ripgrep with a pre-built trigram index and an optional server. A search resolves in this order: 1. Server running for this tree: query it over TCP. Fastest. A file watcher keeps the…

  • Installs packages

Trending

Quiet since September.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 6 mentionsSep 2026: 30 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the microsoft/tgrep repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about microsoft/tgrep

The biggest 5 of 36 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 36

Talked about on GitHub, Bluesky and Hacker News (36 times).

On GitHub · 25

20 more on GitHub

On Bluesky · 7

2 more on Bluesky

On Hacker News · 4

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

The file

We split this AGENTS.md into the rules it gives an agent

11 rules. About 0 are common, 2 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check that a server is up:

    line 61
  2. Very specific:

    If your agent framework cannot keep a background process alive, skip serve and run tgrep index .

    line 67
  3. Very specific:

    Prefer -F: when the query is a symbol or a string the user typed.

    line 98
  4. Very specific:

    Narrow with -t or -g: before adding -m. Both keep compatible indexes in use.

    line 100
  5. Very specific:

    Use -C 2 or -C 3: when you need to read the surrounding code.

    line 105
  6. Very specific:

    Use -q: when you only need a yes/no answer.

    line 106
  7. Distinctive:

    Avoid these on large repositories unless you need them.

    line 154
  8. Very specific:

    Use --no-index when the very latest edit must be visible.

    line 188
  9. Very specific:

    If you expose tgrep to a model as a tool, a minimal schema is:

    line 235
  10. Very specific:

    Before invoking tgrep, canonicalize path beneath the configured repository root and reject paths that resolve outside it.

    line 253
  11. Very specific:

    Always return stderr: the "no index" warning can arrive with code 0 or 1.

    line 258

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

tgrep for coding agents

A short guide for AI agents (and the humans who wire them up) that want to use tgrep as a fast search tool inside a repository. It complements the README, which documents every flag; this file covers the few things an agent has to get right.

The mental model

tgrep is ripgrep with a pre-built trigram index and an optional server.

tgrep index .        # once: build the index into ./.tgrep
tgrep serve .        # once per session: keep the index warm and watch for changes
tgrep "pattern" .    # every search: finds the server, answers in milliseconds

A search resolves in this order:

  1. Server running for this tree: query it over TCP. Fastest. A file watcher keeps the index close to the filesystem, though a silently missed notification is repaired only by periodic reconciliation (scheduled hourly and deferrable for up to four hours while queried); --no-watch disables it.
  2. On-disk index but no server: read .tgrep/ directly. Fast, but only as fresh as the last successful index publication. Legacy indexes without hidden-file coverage metadata and incomplete builds fall back to scanning. Rebuild with tgrep index . or resume tgrep serve . to enable indexed queries.
  3. No index: scan every file, like grep. Correct but slow on large trees. tgrep prints a warning on stderr when this happens.

An agent never has to choose between these; the command is the same. Results can differ, though. An on-disk index omits changes since its last build. A server started with no index, a partial index, or legacy hidden-file coverage lets clients fall back to scanning until it establishes the full corpus. tgrep status . shows Hidden coverage: complete once indexed queries are available, and Indexing: complete once the initial build is done. Do not read either as a freshness signal: a server that starts on an existing index reconciles it against the filesystem in the background while already reporting complete, and it never covers watcher events missed later. When a search must reflect current file contents, pass --no-index. It reads every eligible file from disk instead of consulting the index, still applying the normal ignore, hidden-file, binary and size rules. It is slow on large trees, so use it deliberately.

Setup

brew install tgrep                      # macOS, Linux
cargo install --path tgrep-cli --locked # from a checkout

Then, from the repository root, once:

tgrep serve . &

serve builds the index if none exists and answers queries while it builds. It writes .tgrep/serve.json (PID and port) so clients can find it. Do not commit .tgrep/; add it to .gitignore.

Check that a server is up:

tgrep status .

If your agent framework cannot keep a background process alive, skip serve and run tgrep index . instead. Searches then use the on-disk index. That index is not updated by searches or edits, so re-run tgrep index . after any change a later search has to see, including your own edits.

Searching

The command line follows ripgrep. The common rg flags are supported with the same names; an unsupported flag is rejected with an error rather than ignored. The full list is in the README. Three accepted flags only take effect on a full scan: -L/--follow, --one-file-system and --ignore-file. An indexed search ignores them silently, so pair them with --no-index.

tgrep -- "fn parse_config" .                 # regex, default
tgrep -F -- "Vec<Option<T>>" .               # literal string
tgrep -w -t rust -- handle .                 # whole word, Rust files only
tgrep -g "src/**" -C 2 -- "TODO|FIXME" .     # glob scope, 2 lines of context
tgrep -l -- "impl .* for Server" .           # file names only
tgrep -c -- deprecated .                     # count per file
tgrep --files -t py .                        # list searchable Python files

Rules of thumb for agents:

  • Put -- before the pattern and pass the search root explicitly. Shell quotes do not stop the parser from reading a bare index, serve, search, status, count-files or help as a subcommand; tgrep -- serve . searches for the word. Everything after -- is read as the pattern and paths, so all flags must come before it.
  • Prefer -F when the query is a symbol or a string the user typed. It avoids regex-escaping mistakes.
  • Narrow with -t or -g before adding -m. Both keep compatible indexes in use; globs filter the indexed corpus rather than reinclude ignored files. -m only trims output.
  • Use -l first on a broad query, then search the specific files. This keeps output small.
  • Use -C 2 or -C 3 when you need to read the surrounding code.
  • Use -q when you only need a yes/no answer; read the exit code.

Machine-readable output

--json emits one JSON object per line, in ripgrep's format. Record types are begin, match, context, end, and summary.

Real output, run from a checkout of this repository:

tgrep --json -F -- "fn main" tgrep-cli/build.rs
{"data":{"path":{"text":"tgrep-cli/build.rs"}},"type":"begin"}
{"data":{"absolute_offset":400,"line_number":11,"lines":{"text":"fn main() {\n"},"path":{"text":"tgrep-cli/build.rs"},"submatches":[{"end":7,"match":{"text":"fn main"},"start":0}]},"type":"match"}
{"data":{"binary_offset":null,"path":{"text":"tgrep-cli/build.rs"},"stats":{"bytes_printed":260,"bytes_searched":1775,"elapsed":{"human":"0.000010s","nanos":9709,"secs":0},"matched_lines":1,"matches":1,"searches":1,"searches_with_match":1}},"type":"end"}
{"data":{"elapsed_total":{"human":"0.000470s","nanos":469542,"secs":0},"stats":{"bytes_printed":515,"bytes_searched":1775,"elapsed":{"human":"0.000470s","nanos":469542,"secs":0},"matched_lines":1,"matches":1,"searches":1,"searches_with_match":1}},"type":"summary"}

Any parser written for rg --json works as is, with one exception: on a line that is not valid UTF-8, ripgrep emits base64 lines.bytes, while tgrep always emits lines.text with each bad byte replaced by U+FFFD. A consumer that depends on the raw bytes of such lines will see repaired text instead.

--vimgrep gives file:line:col:text, one row per match, which is the easiest format to feed into a "jump to location" step.

Exit codes

CodeMeaning
0At least one match
1No match
2Error (unreadable path, bad regex, ...)

A match plus an error yields 2, unless -q is set, which yields 0. Same as ripgrep.

When the index is not used

These fall back to a full scan even with a server running:

  • --no-ignore and variants, -u/-uu/-uuu
  • -a/--text, --binary, non-auto -E/--encoding
  • --no-index (explicit)
  • naming a single file instead of a directory

Avoid these on large repositories unless you need them.

index and serve include hidden, non-ignored files by default; passing --hidden to either is redundant. Queries without --hidden still apply normal hidden-file filtering, including Windows hidden attributes. --hidden searches and --files --hidden use compatible local/server indexes without disabling ignore rules. Git's .git directory subtrees are excluded from indexes by default, even with --hidden; use --no-ignore consistently on index and serve to include them. Explicit --no-index scans retain normal hidden and ignore behavior and can inspect Git internals without rebuilding the index. Positive and negative --glob/--iglob patterns also stay indexed, for both content searches and --files. They filter the indexed corpus only, so a positive glob does not reinclude ignored files in indexed mode. Use --no-index when those matches are needed; filesystem scans retain ripgrep-style glob overrides. Negative globs such as --glob '!.git' exclude entire matching directory subtrees. The configured index directory and all its staging/retired generations are excluded from indexing, watcher processing, and query filesystem walks, even with a custom path.

Legacy or incomplete indexes, and older servers that cannot confirm hidden-file coverage, fall back to scanning. A current server upgrades legacy coverage by reconciling the tree; tgrep index . can rebuild it explicitly.

New indexes have a format boundary that older local readers reject instead of exposing hidden paths without filtering. Downgrading requires rebuilding with the older binary, preferably using a separate --index-path. New readers retain legacy-format support for migration.

Freshness

  • With a server, results reflect the last watcher event the indexing worker has processed. Events are queued and applied asynchronously, so a search issued right after an edit can run before the index has caught up. Use --no-index when the very latest edit must be visible.
  • With only an on-disk index, results reflect the last tgrep index. Files created since then are not found. Run tgrep index . again, or start tgrep serve ..
  • tgrep --files reads from the index too. Add --no-index to list what is on disk right now.

Keep index, serve and search flags aligned

Some flags describe the index, so index, serve and search have to agree on them. If they differ, the client either cannot find the server or silently searches a different set of files.

  • --exclude <DIR>: index and serve only. Use the same value on both.
  • --no-ignore: index and serve must agree. A server started without it on an index built with it treats the ignored files as deleted and drops them. Passing it to a search is different: that forces a full scan.
  • --index-path, --max-filesize, --no-max-filesize, --no-require-git: index, serve and every search. An index built with --no-max-filesize but searched with the default cap hides every file above 64 MiB.
tgrep index . --index-path /tmp/idx --exclude vendor
tgrep serve . --index-path /tmp/idx --exclude vendor
tgrep "pattern" . --index-path /tmp/idx

Repositories without .git

tgrep indexes plain directories normally, but like ripgrep it ignores .gitignore files outside a Git repository. The index is then larger than expected, and tgrep prints a warning saying so. Pass --no-require-git to index, serve and search to apply the ignore rules anyway.

Troubleshooting

SymptomCauseFix
warning: no index at ... - scanning every fileNo index at the path the search looked inIf a server or index uses --index-path, pass the same value to the search; otherwise run tgrep index . or tgrep serve .
Server unreachable, falling back to local indexServer died or serve.json is staleRestart tgrep serve .
A new file is not found, no serverOn-disk index predates the fileRun tgrep index .
A new file is not found, server runningFirst build still in progress, or the watcher event is still queuedWait, or pass --no-index for this search; re-running tgrep index . does not update a running server
Search is slow despite a serverFlag bypasses the index (see above)Drop the flag or scope with -g/-t

Tool definition sketch

If you expose tgrep to a model as a tool, a minimal schema is:

{
  "name": "tgrep",
  "description": "Fast regex search over the repository. ripgrep-compatible flags. Use -F for literal strings, -t/-g to scope, -l for file names only, -C N for context.",
  "parameters": {
    "type": "object",
    "properties": {
      "pattern": {"type": "string", "description": "Regex, or literal string with -F"},
      "path": {"type": "string", "default": "."},
      "flags": {"type": "array", "items": {"type": "string"}}
    },
    "required": ["pattern"]
  }
}

Before invoking tgrep, canonicalize path beneath the configured repository root and reject paths that resolve outside it. Allowlist search-only flags rather than forwarding arbitrary tokens. Then run tgrep <flags...> -- <pattern> <path> and return stdout, stderr and the exit code together. Treat 1 as "no results", not as a failure. Treat 2 as an error; stderr carries the cause, such as a bad regex. Always return stderr: the "no index" warning can arrive with code 0 or 1.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.