tensor-grep: Fast local code search, symbol navigation, and token-budgeted AI context (Rust + tree-sitter + MCP; zero API key required, GPU experimental) · Pythie
tensor-grep (tg) is a local-first code search, symbol-navigation, and AI context CLI. It combines regex and structural AST search with repository orientation, caller/blast-radius analysis, diff-impact slicing, rollback checkpoints, and an MCP server—with zero telemetry and no API key required for core workflows.
With Python 3.11+ on Windows, macOS, and Linux (or the managed native installer in docs/installation.md):
python -m pip install tensor-grep
tg --version
From any repository:
# 1. Find literal text or regex matches with line numbers
tg search -F -n "TODO" src
# 2. Orient yourself in an unfamiliar codebase
tg orient src
# 3. Trace callers and prepare an edit-readiness capsule (add --json or --json --compact)
tg callers src create_invoice --json
tg prepare src "add invoice tax validation" --json --compact
# 4. Inspect git diff blast radius before committing
tg diff-impact . --json
Commands default to concise human-readable text when --json is omitted; pass --json for machine output or --json --compact for a bounded <= 4,000-byte JSON payload.
12-command core workflow (tg --help vs tg --help-all)
tg --help highlights the 12 core workflow commands so humans and agents can start without noise. Run tg --help-all for the complete command catalog.
Stage
Core commands
What it gives you
Search & structure
search, find, run, scan
Regex/literal search (--index, --rank), local hybrid BM25+RRF (find --hybrid), structural AST patterns (run), and bounded AST rulesets (scan)
Understand & trace
orient, defs, callers, blast-radius
Central files and entry points (orient), symbol definitions (defs), call sites (callers), and transitive file/test impact (blast-radius)
15-tool compact default MCP server (< 12 KBtools/list, tg_batch step pipelines; TG_MCP_LEGACY_TOOLS=1 for all 61 legacy tools)
For AST structural search and rulesets via PyPI, install python -m pip install "tensor-grep[ast,scan]" (the managed native binary supports tg run directly). In PowerShell, wrap patterns containing $VALUE in single quotes:
tg run -p 'print($VALUE)' --lang python src
Why tg vs rg + ast-grep + IDE
rg (ripgrep) is the cold exact-text search baseline. tg does not replace rg; it routes compatible cold text searches through rg or its native CPU engine, and adds warm trigram indexing (tg search --index), symbol graphs, and bounded AI context on top.
ast-grep (sg) has the broader structural-rule surface. tg run and tg scan expose a validated AST search/rewrite slice alongside symbol navigation, diff impact, and checkpoints in one CLI.
IDEs hold rich semantic state interactively, but scripts, CI gates, and coding assistants need headless, deterministic, token-budgeted CLI/MCP outputs (--json, --json --compact, tg_batch, and tg review-bundle verify --require-change-slice) without GUI startup or cloud telemetry.
Zero-telemetry, local-first: Core search, indexing (.tg_cache/), symbol graphs, sessions, and checkpoints run 100% locally with no API key and no outbound telemetry.
Benchmark & verification surfaces
Performance and accuracy claims in tensor-grep are benchmark-governed and workload-specific. Rather than quoting cherry-picked numbers, each surface has a reproducible harness in benchmarks/ documented in docs/benchmarks.md and docs/tool_comparison.md:
tg prepare, tg agent (context capsule), and tg orient --compact bound JSON output to <= 4,000 bytes and reuse warm .tg_cache/ views (manifest_v1.json, symbols_v1/, graph_v1/tdad_tests.sqlite3)
MCP schema & pipeline budget
tests/unit/test_mcp_compact_parity.py
Default tg mcp exposes 15 compact tools (< 12 KBtools/list, vs 61 with TG_MCP_LEGACY_TOOLS=1) and tg_batch ($prev / $steps[i])
Security & AST rulesets (tg scan)
benchmarks/run_ast_benchmarks.py
Built-in rulesets (e.g., secrets) via tensor-grep[scan]; fails closed when ast-grep is absent and discloses partial / partial_reason
Native GPU (experimental)
benchmarks/run_gpu_native_benchmarks.py
Explicit --gpu-device-ids only; never inferred from fallback/sidecar rows (docs/gpu_crossover.md)
Bounded scans can return partial results. Confidence scores and caller graphs are evidence to review, not proof that a change is safe or that a symbol is unused.
Installation & platform channels
Windows (x64), macOS (x64 / Apple Silicon), and Linux (x64 / ARM64) installation options are documented in docs/installation.md and the support matrix. npm, Homebrew, and Winget manifests exist in the repository but are not published to their registries yet.
See CONTRIBUTING.md for development and review conventions, and
SECURITY.md for private vulnerability reporting.
Future Work
Ongoing work focuses on retrieval quality, cross-file navigation, larger repositories,
and integrations. Experimental features graduate through measured results and compatibility
checks. See the experimental-feature guide for current boundaries
and GitHub issues for discussion.