tgrep is a trigram-indexed grep tool with a client/server architecture for fast regex search in large codebases.
The problem tgrep solves is the performance penalty of scanning every file on every search, which becomes prohibitively slow in monorepos with hundreds of thousands of files. Tools like grep and ripgrep must examine all bytes in the repository for each query. tgrep pre-builds a trigram index that identifies which files could possibly match a given pattern, so searches only need to examine a small subset of files. The architecture uses a persistent server that maintains both an on-disk memory-mapped index and an in-memory overlay for recently modified files, with a background indexer that builds the index in parallel batches while clients can search against incomplete indexes.
Developers working with large codebases should consider tgrep if search latency is a bottleneck. The tool is particularly suited for monorepos with tens of thousands of files or more, where the speedup over ripgrep can exceed fifty times on some platforms. The project is integrated into GitHub Copilot CLI and provides agent integration for AI coding assistants through an MCP interface. The benchmark results show that tgrep's advantage is most pronounced on macOS and Windows with very large repositories, though the margin depends on repository size and match volume—queries returning tens of thousands of matches spend more time delivering results than the index saves on finding them.
The project shows active development with regular updates to the indexing pipeline and server architecture. The codebase includes comprehensive benchmarking documentation and platform-specific optimizations. The tool provides detailed configuration options for background indexing batch sizes and periodic flushing intervals to balance memory usage and index freshness. Integration guides for agent-based workflows are maintained alongside the core functionality.