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
Who's talking about microsoft/tgrep
- @sungkim.bsky.social“Microsoft releases yet another variation of grep. tgrep Tools like grep and ripgrep scan every file on …”Bluesky · Sep 8, 2026 · 34 likes
- @midu.dev“¡Microsoft saca tgrep para que los agentes de IA busquen código 50× más rápido! ✓ Desarrollado en Rust y …”Bluesky · Sep 8, 2026 · 15 likes
- A Hacker News story“Microsoft/tgrep: grep with trigram indexing in Rust”Hacker News · Sep 9, 2026 · 4 points
- A Hacker News story“Microsoft Tgrep: Trigram-indexed grep”Hacker News · Sep 7, 2026 · 4 points
- @yug1224.com“巨大なコードベースでも高速に正規表現検索できるトライグラムインデックス対応ツールらしい 大規模なリポジトリを扱うときにすごく便利そう yug1224 starred microsoft/tgrep …”Bluesky · Sep 8, 2026 · 3 likes
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
- Sep 22, 2026tgrep: 1.0.9 -> 1.0.10 — NixOS/nixpkgs1 reaction · 1 comment
- Aug 11, 2026[ca] CLI version updates: Claude Code 2.1.227, Copilot CLI 1.0.79 — github/gh-aw1 reaction · 1 comment
- Sep 28, 2026tgrep: 1.0.10 -> 1.0.11 — NixOS/nixpkgs0 reactions · 2 comments
- Sep 26, 2026tgrep 1.0.11 — Homebrew/homebrew-core0 reactions · 1 comment
- Sep 26, 2026docs(agents): document tgrep provenance and install path for agent environments — xmeta/aivtuber0 reactions · 2 comments
20 more on GitHub
- Sep 24, 2026docs(cc-community): screenshot-lead research batch 02 (plan 0008 row 20) — qte77/ai-agents-research0 reactions
- Sep 23, 2026fix(add): sin comando de instalación para la plataforma, add cierra en "Listo" sin haber instalado nada — UlisesCm/navori-harness0 reactions
- Sep 21, 2026tgrep 1.0.10 — Homebrew/homebrew-core0 reactions · 1 comment
- Sep 18, 2026tgrep: 1.0.8 -> 1.0.9 — NixOS/nixpkgs0 reactions · 2 comments
- Sep 18, 2026tgrep 1.0.9 — Homebrew/homebrew-core0 reactions · 1 comment
- Sep 11, 2026tgrep 1.0.8 — Homebrew/homebrew-core0 reactions · 1 comment
- Sep 11, 2026tgrep: 1.0.7 -> 1.0.8 — NixOS/nixpkgs0 reactions · 1 comment
- Sep 11, 2026tgrep: 1.0.5 -> 1.0.7 — NixOS/nixpkgs0 reactions · 1 comment
- Sep 11, 2026tgrep 1.0.7 — Homebrew/homebrew-core0 reactions · 1 comment
- Sep 11, 2026tgrep 1.0.6 — Homebrew/homebrew-core0 reactions · 1 comment
- Sep 10, 2026tgrep: 1.0.4 -> 1.0.5 — NixOS/nixpkgs0 reactions · 1 comment
- Sep 8, 2026Suggest binaries: tgrep — prefix-dev/octoconda0 reactions
- Sep 7, 2026tgrep 1.0.4 — Homebrew/homebrew-core0 reactions · 1 comment
- Sep 5, 2026Look at tgrep — petdance/altbox0 reactions
- Sep 4, 2026tgrep 1.0.3 — Homebrew/homebrew-core0 reactions · 1 comment
- Aug 30, 2026[Feature]: Native grep over whole-file TEXT with match offsets and S3-aware NGRAM — milvus-io/milvus0 reactions · 1 comment
- Aug 17, 2026build(deps): bump the npm-compatible-updates group with 3 updates — patchhive/tendwright0 reactions
- Aug 17, 2026npm(deps): bump the minor-and-patch-updates group across 2 directories with 9 updates — rajbos/ai-engineering-fluency0 reactions
- Aug 16, 2026chore(deps): bump @github/copilot from 1.0.70 to 1.0.79 — splrad/steward0 reactions · 1 comment
- Aug 11, 2026[bot] Update Learning Hub with model picker groups, tgrep, plugin extensions dir, and app Side chat — github/awesome-copilot0 reactions
On Bluesky · 7
- Sep 8, 2026Microsoft releases yet another variation of grep. tgrep Tools like grep and ripgrep scan every file on every search - O(total bytes) per… — @sungkim.bsky.social34 likes and reposts · 2 replies
- Sep 8, 2026¡Microsoft saca tgrep para que los agentes de IA busquen código 50× más rápido! ✓ Desarrollado en Rust y Open Source ✓ Indexas una vez,… — @midu.dev15 likes and reposts · 5 replies
- Sep 8, 2026巨大なコードベースでも高速に正規表現検索できるトライグラムインデックス対応ツールらしい 大規模なリポジトリを扱うときにすごく便利そう yug1224 starred microsoft/tgrep https://github.com/microsoft/tgrep — @yug1224.com3 likes and reposts
- Sep 6, 2026trigramなインデックスを作成しておくことでripgrepよりも大幅に高速と謳う正規表現検索用CLIツール。Microsoft製。Rust実装。homebrewに追加されたのでmacOSであればbrew install tgrepでインストール可能。 — @matsuu.bsky.social2 likes and reposts
- Sep 9, 2026🔗 microsoft/tgrep https://github.com/microsoft/tgrep — @kinduff.com1 likes and repost
2 more on Bluesky
- Sep 6, 2026GitHub - microsoft/tgrep: Trigram-indexed grep with a client/server architecture for fast regex search in large codebases locally… — @tech-trending.bsky.social1 likes and repost
- Sep 8, 2026💎 Hidden Gem! 💎 (1000+ new stars) 📦 microsoft / tgrep ⭐ 1,707 (+1,353) 🗒 Rust Trigram-indexed grep with a client/server architecture… — @github-trending-rs.bsky.social0 likes and reposts · 1 reply
On Hacker News · 4
- Sep 9, 2026Microsoft/tgrep: grep with trigram indexing in Rust4 points
- Sep 7, 2026Microsoft Tgrep: Trigram-indexed grep4 points
- Sep 4, 2026Tgrep: Trigram-Indexed Grep3 points · 2 comments
- Sep 8, 2026Microsoft Tgrep2 points
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
- Distinctive: line 61
Check that a server is up:
- Very specific: line 67
If your agent framework cannot keep a background process alive, skip serve and run tgrep index .
- Very specific: line 98
Prefer
-F: when the query is a symbol or a string the user typed. - Very specific: line 100
Narrow with
-tor-g: before adding -m. Both keep compatible indexes in use. - Very specific: line 105
Use
-C 2or-C 3: when you need to read the surrounding code. - Very specific: line 106
Use
-q: when you only need a yes/no answer. - Distinctive: line 154
Avoid these on large repositories unless you need them.
- Very specific: line 188
Use --no-index when the very latest edit must be visible.
- Very specific: line 235
If you expose tgrep to a model as a tool, a minimal schema is:
- Very specific: line 253
Before invoking tgrep, canonicalize path beneath the configured repository root and reject paths that resolve outside it.
- Very specific: line 258
Always return stderr: the "no index" warning can arrive with code 0 or 1.
≈ “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.
Files
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 millisecondsA search resolves in this order:
- 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-watchdisables it. - 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 withtgrep index .or resumetgrep serve .to enable indexed queries. - 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 checkoutThen, 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 filesRules of thumb for agents:
- Put
--before the pattern and pass the search root explicitly. Shell quotes do not stop the parser from reading a bareindex,serve,search,status,count-filesorhelpas 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
-Fwhen the query is a symbol or a string the user typed. It avoids regex-escaping mistakes. - Narrow with
-tor-gbefore adding-m. Both keep compatible indexes in use; globs filter the indexed corpus rather than reinclude ignored files.-monly trims output. - Use
-lfirst on a broad query, then search the specific files. This keeps output small. - Use
-C 2or-C 3when you need to read the surrounding code. - Use
-qwhen 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
| Code | Meaning |
0 | At least one match |
1 | No match |
2 | Error (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-ignoreand 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-indexwhen 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. Runtgrep index .again, or starttgrep serve .. tgrep --filesreads from the index too. Add--no-indexto 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>:indexandserveonly. Use the same value on both.--no-ignore:indexandservemust 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,serveand every search. An index built with--no-max-filesizebut 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/idxRepositories 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
| Symptom | Cause | Fix |
warning: no index at ... - scanning every file | No index at the path the search looked in | If 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 index | Server died or serve.json is stale | Restart tgrep serve . |
| A new file is not found, no server | On-disk index predates the file | Run tgrep index . |
| A new file is not found, server running | First build still in progress, or the watcher event is still queued | Wait, or pass --no-index for this search; re-running tgrep index . does not update a running server |
| Search is slow despite a server | Flag 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.
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
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.

