Fast, agent-friendly, symlink-safe code search and hydration tool with centered KWIC snippets, stateless point hydration, edit-ready block boundaries, and native Model Context Protocol (MCP) support.
trg is a high-performance, symlink-safe, agent-friendly code search and context hydration CLI tool with native Model Context Protocol (MCP) server support.
Designed for modern AI coding agents and developers, trg recursively searches across any codebase (C/C++, Python, TypeScript, Rust, Go, Java, Markdown, and more) with intelligent syntactic block expansion, enclosing symbol scope breadcrumbs, and LLM-safe token budget protection.
Key Highlights
Universal Code Search: Recursively searches repositories in any programming language with literal fast-paths, smart case sensitivity, and non-backtracking regular expressions.
Instant Symbol Outline (trg symbols, trg_symbols): Streaming single-pass $O(1)$ memory symbol extractor providing edit-ready ranges [start, end], Go receiver methods, TypeScript arrow functions, and decorator upward snapping.
Stateless Point Hydration (trg view, trg_view): Sub-3ms target line inspection with surrounding context (-C N) or full syntactic block expansion (--block).
Native Stdio MCP Server (--mcp): Built-in JSON-RPC 2.0 server over stdio for Claude Desktop, Cursor, Antigravity, and AI agent frameworks—zero Node.js or Python runtime required.
LLM Context Protection: Hard result payload budgets (--max-result-bytes, --max-total-matches), token-efficient compact JSON mode (--json=compact), and atomic context window framing prevent context runaway.
Syntactic Block Hydration (--block, --scope, --def-first): Expands matches into full enclosing functions/classes and prioritizes symbol definitions over usages for instant code comprehension.
Zero-Dependency Native Binary: Ships as a single standalone executable across macOS (Apple Silicon), Linux (x86_64), and Windows (x64 / ARM64).
Features & Guarantees
Instant Symbol Outline (trg symbols [options], trg_symbols MCP Tool):
Streaming single-pass symbol tree extractor with zero heavy AST or tree-sitter overhead, operating strictly in $O(1)$ memory.
Automatically identifies symbol kind (function, method, class, struct, interface, type, shape, impl), symbol name, parent scope (scope), and exact edit-ready line range (range: [start, end]).
Go Receiver Method Extraction: Accurately recognizes Go methods with value/pointer receivers and generics (func (s *Server[T]) Method()), while ignoring anonymous function closures.
TypeScript / JavaScript Arrow Functions: Distinguishes block-body arrow functions (const f = () => { ... }) from concise expression bodies (const add = (a, b) => a + b;).
Decorator & Attribute Upward Snapping: Automatically snaps upward across preceding decorators (@decorator) and attributes (#[derive(...)]), including multiline expressions, with empty-line hard stops.
Kind Filtering (-k / --kind ): Filter symbols by kind (e.g. -k function,method or -k class).
Fail-Closed Truncation Contracts: Supports --max-symbols and --max-bytes budgets with truthful completeness flags (complete, truncated, termination_reason).
Available via CLI (trg symbols [--json] [-k kinds] [--max-symbols N] [--max-bytes SIZE]) and MCP stdio (trg_symbols).
Sub-3ms stateless code hydration for inspecting lines and code blocks around target coordinates.
Line context mode: trg view : [-C N] (default 10 lines; recommended for local facts, conditions, and error branches).
Explicit line range: trg view --lines -.
Syntactic block mode: trg view : --block (expands to the enclosing function/class block with decorator snapping).
Symbol mode: trg view --symbol [--scope ] [--max-lines N] (extracts symbol range; pair with --max-lines on large functions. Note: view --scope is a scope name filter, not a boolean flag).
Two-pass streaming search prioritizing symbol declarations/definitions before usages when running under output budgets (--max-total-matches, --max-result-bytes).
Identifier-Aware Extraction: Correctly identifies the declared symbol name while skipping modifiers (pub, async, export), declaration keywords (fn, struct, class, shape, type), generics (<...>), and impl Trait for Target. Ensures references in parameter or return types are not falsely treated as definitions.
Maintains strict $O(1)$ memory streaming per file.