convez.ai
MCP ServerBusca & PesquisaIntermediário
momokun7

xgrep — Motor de Busca de Código Ultra-Rápido

momokun7/xgrep

Busca indexada ultra-rápida de código com MCP server integrado

Ver no GitHub
BomPluginScore · de 0 a 100

Motor de busca indexado para código que usa índice trigram invertido, oferecendo buscas 2-46x mais rápidas que ripgrep em pesquisas repetidas. Inclui servidor MCP nativo para integração com agentes de IA (Claude Code, Cursor) e modo de descoberta de arquivos 2-15x mais veloz que fd. Zero configuração: instala via cargo/npm/pip e constrói índice automaticamente.

Instalação

$npx convez-ai momokun7/xgrep

1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.

Métricas

Estrelas
22
Forks
1
Acompanhando
1
Saúde
85%
Último commit
há 2 dias
Versão
v0.9.0
Issues abertas
26
Contribuidores
2

Casos de uso

  • Busca repetida em bases de código grandes para humanos e agentes IA
  • Integração com IDEs e ferramentas de coding assistido (Claude Code, Cursor)
  • Descoberta rápida de arquivos e padrões em repositórios git-aware

Veredito

Ferramenta sólida e bem-engineered para quem faz buscas repetidas em codebases grandes. O MCP server nativo é vantagem real vs ripgrep/zoekt; a troca é menos flexibilidade em buscas únicas. Recomendado para fluxos com agentes IA ou desenvolvimento contínuo em projetos grandes.

README

A tradução para o português deste README ainda está na fila.

xgrep

CI Crates.io npm PyPI License: MIT

Ultra-fast indexed code search engine with MCP server for AI coding tools.

Pre-builds a trigram inverted index, then searches in milliseconds. Designed for repeated searches on large codebases — by humans and AI agents alike.

Features

  • Indexed search — trigram inverted index makes repeated searches 2-46x faster than ripgrep
  • File discovery — --find mode locates files 2-15x faster than fd
  • MCP server — built-in Model Context Protocol server for AI coding tools (Claude Code, Cursor, etc.)
  • LLM-optimized output — --format llm produces Markdown with language tags, context lines, and token-aware truncation
  • Git-aware — search only changed files (--changed), recent commits (--since 1h), respects .gitignore
  • Zero config — install via cargo/npm/pip, then xg "pattern". Index builds automatically on first search
  • Hybrid search — serves results from index instantly while rebuilding in the background

Why xgrep?

ripgrepzoektxgrep
SetupNoneServer requiredNone (cargo/npm/pip)
First searchInstantAfter server startAuto-builds index
Repeated search (Linux kernel)1,687ms170ms (server)37ms
File discovery (next.js, 26K files)N/AN/A9ms (fd: 191ms)
Index sizeN/A155% of source8% of source
AI agent integrationNoneNoneMCP server built-in
Memory (search)11MB288MB208MB

xgrep is not a ripgrep replacement. Use ripgrep for one-off searches. Use xgrep when you search the same codebase repeatedly — the index pays for itself after ~2 searches.

Installation

Choose your package manager:

# Rust (recommended — native binary, no runtime)
cargo install xgrep-search    # Requires Rust 1.85+

# npm (Node.js 18+)
npm install -g xgrep

# pip (Python 3.8+)
pip install xgrep-search

Prebuilt binaries are also available on the Releases page.

Quick Start

xg "pattern"                  # Search (auto-builds index on first run)
git clone https://github.com/momokun7/xgrep.git
cd xgrep/rust
cargo build --release
cp target/release/xg ~/.local/bin/

Usage

xg "pattern"                  # Smart-case search (all-lowercase = case-insensitive)
xg "Pattern"                  # Mixed/upper case in pattern = case-sensitive
xg "pattern" -i               # Force case-insensitive
xg "pattern" -s               # Force case-sensitive (disable smart-case)
xg "pattern" /path/to/repo    # Search a specific directory
xg -e "handle_\w+"            # Regex search
xg "pattern" -w               # Match whole words only
xg "pattern" -t rs            # Filter by file type
xg "pattern" -C 3             # Context lines (symmetric)
xg "pattern" -A 2 -B 1        # 2 lines after, 1 line before
xg "pattern" -g "*.rs"        # Include only paths matching glob (repeatable)
xg "pattern" -g "!*_test.rs"  # Exclude paths matching glob (! prefix)
xg "pattern" --format llm     # Markdown output for LLMs
xg "pattern" --changed        # Only git changed files
xg "pattern" --exclude vendor  # Exclude paths containing "vendor"
xg "pattern" --absolute-paths # Show absolute paths
xg "pattern" --no-hints       # Suppress regex pattern hints
xg --find "*.rs"              # Find files by glob pattern
xg --list-types               # Show supported file types
xg status                     # Show index status
xg init                       # Explicitly rebuild index

Search is smart-case by default: an all-lowercase pattern matches case-insensitively, while any uppercase letter makes the search case-sensitive. Use -i or -s to override (priority: -i > -s > smart-case).

Environment Variables

VariableDescriptionDefault
XGREP_LLM_CONTEXTDefault context lines for --format llm3
XGREP_ABSOLUTE_PATHSSet to 1 to always use absolute pathsunset
XGREP_NO_HINTSSet to 1 to suppress regex pattern hintsunset

Run xg --help for all options.

MCP Server

xgrep runs as an MCP server, giving AI coding tools fast indexed search.

xg serve                        # Start MCP server
xg serve --root /path/to/repo   # Specific directory

Claude Code

{
  "mcpServers": {
    "xgrep": {
      "command": "xg",
      "args": ["serve"]
    }
  }
}

Available tools: search, find_definitions, read_file, index_status, build_index

See docs/agents.md for agent-oriented usage patterns.

Performance

Benchmarked with hyperfine on Apple M4, 32GB RAM, macOS. All numbers are warm cache, after index build.

Search: Linux kernel (92,947 files, 2.0GB)

Queryxgripgrepvs ripgrep
struct file_operations37ms1,687ms46x faster
printk52ms1,756ms34x faster
EXPORT_SYMBOL66ms1,773ms27x faster

File discovery: next.js (27,332 files)

Queryxg --findfdvs fd
*.ts (4,838 files)20.8ms187.3ms9x faster
config (substring)12.7ms188.1ms15x faster

Index cost

Metricxgrepzoekt
Build time (Linux kernel)6s46s
Index size175MB (8% of source)3.0GB (155%)
Breakeven~2 searches—

First run includes a one-time index build. See docs/benchmarks.md for full results including medium/small repos.

Limitations

  • Short queries (< 3 chars) bypass the index — no speed advantage over ripgrep
  • Tiny files (< 3 bytes) hold no trigrams and are invisible to indexed content search — a deliberate trade-off of the trigram index
  • Index staleness — background rebuild runs every ~30s. Use --fresh for up-to-date results
  • find_definitions uses regex heuristics, not AST analysis — false positives expected

When to use ripgrep instead: one-off searches, very small codebases (< 100 files), or queries shorter than 3 characters.

How It Works

  1. Index Build: Walks the codebase, extracts 3-byte trigrams from each file, builds an inverted index with delta+varint compression
  2. Search: Extracts trigrams from query, intersects posting lists to find candidate files, verifies matches
  3. Hybrid Mode: Combines index results with direct scanning of changed files when index is stale
  4. MCP Server: Exposes search via JSON-RPC over stdio, with token-aware truncation

Contributing

See CONTRIBUTING.md for development setup and guidelines.

License

MIT

Ver o original no GitHub

Bom para

Relacionados