
grepika
Token-efficient MCP server for code search.
LLMs burn context tokens on every search call. grepika indexes your codebase and returns ranked, compact results — so the model spends tokens reasoning instead of reading raw grep output. It combines FTS5, ripgrep-backed regex search, and a sparse n-gram prefilter for ranked lexical search, then adds MCP tools for AST structural search and code-graph navigation.
Why grepika?
grep is a great tool, but it wasn't designed for LLM workflows. It returns unranked file lists, and the model has to make multiple calls to piece together context. grepika gives the model structured tools for the things it actually needs to do:
| Task | grep approach | grepika |
|---|
| Find a pattern | Unranked file list | Ranked results with relevance scores |
| Understand a symbol | Multiple grep calls, manual assembly | refs classifies definitions, imports, usages |
| Explore structure | Read entire files | outline extracts functions/classes/structs |
| Find related code | Guess-and-grep loop | refs finds files sharing symbols |
| Natural language query | Requires regex | search routes to BM25 full-text search |
| Find syntax patterns | Fragile regex | structural_search matches AST patterns and node kinds |
| Trace relationships | Manual file hopping | graph navigates indexed call/import edges |
Benchmarks
Criterion benchmarks against ripgrep content output on the grepika codebase, 9 queries across all intent categories:
| Metric | grepika | ripgrep (content mode) |
|---|
| Response size | 2,352 B avg | 17,336 B avg |
| Mean per-query savings | 61.4% | N/A |
| Relevance ranking | BM25 + grep + sparse n-gram signals | None |
| Structural search | AST pattern/kind matching, no index required | Regex only |
Savings are largest on high-match queries (for example, fn saves 93.8%); low-match patterns can be larger with grepika because structured JSON has a fixed cost. See full analysis.
Token Efficiency
Compared to ripgrep content output (matching lines), indexed search returns fewer tokens per query. The bigger win is search quality — ranking, NLP queries, and reference classification reduce follow-up reads.
Criterion benchmarks on the grepika codebase, 9 queries across all intent categories:
Query │ grepika │ ripgrep (content) │ Savings
──────────────────┼──────────┼────────────────────┼────────
SearchService │ 3,227 B │ 10,053 B │ 67.9%
Score │ 2,433 B │ 6,497 B │ 62.6%
Database │ 2,680 B │ 12,379 B │ 78.4%
fn │ 2,880 B │ 46,125 B │ 93.8%
use │ 2,676 B │ 31,868 B │ 91.6%
search service │ 787 B │ 1,556 B │ 49.4%
error handling │ 782 B │ 985 B │ 20.6%
fn\s+\w+ │ 2,896 B │ 43,898 B │ 93.4%
impl.*for │ 2,806 B │ 2,664 B │ -5.3%
Savings are largest on high-match queries where ripgrep returns many unranked lines. Natural language queries route to FTS5 concept search in grepika and now stay close to ripgrep's output size while preserving ranking and snippets.
Claude Code lazy-loads MCP tools on demand, so grepika's 12 tool schemas are not loaded all at once. Loaded schemas are prompt-cached after the first call (~90% discount on subsequent turns). In the current benchmark, the full schema is 11,475 bytes (~2,869 tokens), and the one-time schema cost breaks even after one average search compared with ripgrep content output.
See docs/token-efficiency-analysis.md for the full comparison including Grep file-list mode and workflow analysis.
How it works
- Three lexical search backends (FTS5 + grep + sparse n-gram prefilter) with weighted score merging
- AST structural search via ast-grep and indexed code-graph navigation via tree-sitter symbols/edges
- BM25 ranking with tuned column weights
- Query intent detection — classifies regex vs natural language vs exact symbol
- Unit/integration tests,
cargo clippy --all-targets, and Criterion benchmarks cover library, CLI, MCP, graph, and structural-search paths
MCP Server Setup
By default, grepika runs in global mode — the server starts without --root, and the LLM calls add_workspace with its working directory automatically.
Claude Code
Plugin (recommended)
The grepika plugin bundles the MCP server with an exploration agent, skills, and commands.