Microsoft Tgrep: Trigram-indexed grep

2026-09-07

Link: https://github.com/microsoft/tgrep

HN Discussion: 1 points, 0 comments

Every developer who has ever waited on grep -r through a monorepo knows the pain: linear scans over millions of files, repeated for every query, with no memory of what came before. Ripgrep famously made scanning faster with clever parallelism and better regex engines, but it's still fundamentally a scan-every-time tool. Microsoft's Tgrep takes a different bet: build a trigram index once, then answer queries in near-constant time.

The idea itself is not new — Russ Cox's classic 2012 essay "Regular Expression Matching with a Trigram Index" laid out how Google Code Search worked, and Zoekt has been carrying that torch for years. What makes Tgrep interesting is that it's coming from Microsoft, likely aimed at the kind of massive internal codebases where Windows, Office, and Azure engineers live. A trigram index breaks every file into overlapping three-character substrings and stores a posting list of which files contain which trigrams. A regex query gets decomposed into a boolean expression over trigrams (e.g., foo.*bar requires files containing both foo and bar), which prunes the candidate set to something small enough to scan with a real regex engine.

Why a technical audience should care:

The fact that this has one upvote and zero comments is a small tragedy. Developer-tooling infrastructure rarely goes viral on HN unless it comes with a slick landing page, but this is exactly the kind of foundational utility that quietly ends up in a lot of pipelines.

Why it deserves more upvotes: A Microsoft-scale, open-source trigram-indexed grep is a serious piece of developer infrastructure that could reshape how coding agents and monorepo search work — worth attention beyond a single upvote.

All newsletters