tgrep

tgrep

Trigram indexed code search

Description

Searching a regex across a repo with hundreds of thousands of files means grep and ripgrep re-read every single byte, every single time. Waiting ten seconds once is fine. The problem shows up when an AI agent runs dozens of searches inside one task — every one of them starts from scratch, and the whole session turns into waiting.

Microsoft open-sourced tgrep with a different approach: build a trigram index once, then every later search narrows to a handful of candidate files from the index and only runs the real regex on those. The published figure is up to 52x faster than ripgrep on large repositories.

Two commands to use it. tgrep index . builds the index, then tgrep "pattern" . searches. To keep the index fresh, run tgrep serve . — a resident server watches the tree and incrementally updates whatever changed, and the client auto-connects to it on the next search. No manual rebuilds.

The syntax is the one you already know: regex, case switches, file-type filters, path scoping. Results come back with line numbers and highlighting, and tgrep status tells you how many files and trigrams are currently indexed.

GitHub Copilot CLI already uses it internally for code search. Written in Rust, MIT licensed, with prebuilt binaries for Windows, macOS and Linux — unzip and run, no runtime to install.

If you run agents locally, shaving seconds off every code lookup adds up faster than you would expect.