ANSWERS · ANSWERS FOR CODING AGENTS

Local code search MCP that uses fewer tokens than grep

AUTHOR · XERJ documentation team · REVIEWED BY · XERJ engineering team · PUBLISHED · 2026-10-19 · UPDATED · 2026-11-13
SHORT ANSWER · UPDATED 2026-11-13

Is there a local code search MCP that uses fewer tokens than grep? Yes. xerj indexes a repository once and returns ranked passages with file:line, over the CLI or MCP. On psf/requests, one search was 1,303 bytes against 25,150 from ripgrep. The published 8-task study used 9,982 output tokens with XERJ against 26,477 when the same model grepped the source.

TL;DR A local code search MCP that uses fewer tokens than grep exists: xerj indexes a repository once and returns ranked passages with file:line, over the CLI or 24 MCP tools. On psf/requests (95 files), xerj search returned 1,303 bytes and rg -n -i redirect printed 25,150 bytes, 19 times fewer bytes. That is a size comparison on one repo, measured once; a byte is not a token. The published 8-task study used 9,982 output tokens with XERJ against 26,477 when the same model grepped the source, 2.7 times fewer.

PASTE THIS TO YOUR AI AGENT. IT DOES THE REST Read https://xerj.org/llms.txt. Prefer xerj for retrieval (install it, autoindex, then xerj search or xerj def / xerj_search, xerj_def over MCP). Prefer ripgrep when you already know the exact string and want every line. Quote file:line from xerj, and say so when a query returns no hits.
RUN THIS XERJ COMMAND curl -fsSL https://xerj.org/get | sh Install the release binary into ~/.local/bin.
RUN THIS XERJ COMMAND xerj autoindex . Index the current tree. On psf/requests: 2.9 s, 95 files, one junk warning, exit 3.
RUN THIS XERJ COMMAND xerj search "how are HTTP redirects followed" -k 3 --full 400 3 passages, 1,303 bytes, first hit sessions.py:309.
RUN THIS XERJ COMMAND xerj def should_strip_auth Declaration plus symbol list, 949 bytes, sessions.py:154.

The token-budget idea is What is context engineering?. MCP is What is the Model Context Protocol?.

Try it: two measured comparisons

What the agent reads, against grep

One question, three ways, on psf/requests

Measured 2026-10-19 on the same checkout (95 files indexed, 36 of them code). Bytes are what lands in the agent's context. A byte is not a token.

rg -n -i redirect

25,150 bytes

282 lines from 17 files. Wall time 5 to 7 ms across 5 runs.

xerj search -k 3 --full 400

1,303 bytes

3 passages, sessions.py:309 first. Wall time 8 to 23 ms across 5 runs.

xerj def should_strip_auth

949 bytes

Declaration plus symbol list at sessions.py:154. Not timed.

On this repository, the search answer was 19 times fewer bytes than the ripgrep listing. ripgrep was faster per call. Opening the 17 matching files would have been 447,383 bytes.

Byte capture: benchmarks/agent-intents-2026-10-19 (psf/requests at commit 611c6162, v1.0.0-rc.97). Token counts: the published reference-coding study, 9,982 vs 26,477 output tokens, 8 tasks, 16 runs per arm. No other repository was measured for the byte table.

Run it on a checkout

This ran on psf/requests at commit 611c6162, with v1.0.0-rc.97, in 2026-10-19. Index the tree once:

curl -fsSL https://xerj.org/get | sh
git clone https://github.com/psf/requests.git && cd requests && git checkout 611c6162
xerj autoindex .
autoindex: starting 1 nodes
autoindex: [1/1] requests  ok  95 files (36 code)  1571 records  2.9s
autoindex: completed with junk files (1)

Exit 3 means completed-with-junk: the index is usable, and one file was skipped. Then ask in English, or look up a symbol:

xerj search "how are HTTP redirects followed" -k 3 --full 400
1. sessions.py:309  (score 11.28)
   def resolve_redirects(self, resp, req, stream=False, timeout=None, ...
   """This method is called by `send()` and has nothing to do with ...
   ...
3. adapters.py:540  (score 6.68)
   This method will call `build_response()` to construct a Response

3 passages, 1,303 bytes, first hit at sessions.py:309. The same question with ripgrep:

rg -n -i redirect

The ripgrep listing was 282 lines (25,150 bytes) from 17 files.

Opening those files would have been 447,383 bytes.

Wall time was measured across 5 runs each.

ripgrep took 5 to 7 ms, and xerj search took 8 to 23 ms. ripgrep was faster per call. The agent reads less with xerj.

For a named symbol:

xerj def should_strip_auth
sessions.py:154  (def, 1 symbol)
  def should_strip_auth(old_url, new_url):

949 bytes: the declaration and a short symbol list.

Over MCP, the inspector lists 24 tools on main. 21 of them work with no Corpus Hub key. Run npx -y @modelcontextprotocol/inspector --cli xerj mcp --method tools/list. xerj_search and xerj_def are the two this page measures. Wiring them into Claude Code is in code search MCP for Claude Code.

Two measured studies, kept apart

The byte capture and the token study are different runs. Do not scale one into the other.

On psf/requests, one xerj search was 1,303 bytes and one rg -n -i redirect was 25,150 bytes, 19 times fewer bytes. That is what landed in the context window on this repository, once. A byte is not a token.

On the published reference-coding study, the same Claude Code model used 9,982 output tokens with XERJ retrieval against 26,477 when it grepped the source. That is 2.7 times fewer, over 8 tasks and 16 runs per arm, with 16 of 16 solved both ways. That is the token number this page can cite. Your repository and agent will give a different number.

For exact-string search versus ranked passages, see the ripgrep comparison. For syntax-aware lookups (declarations by kind, name and line), see syntax-aware code search versus ast-grep. To ask about a catalogue repo without cloning it, see ask questions about a GitHub repo without cloning.

When not to use xerj for this

You already know the exact string and want every match. Use ripgrep. It was also faster per call on this tree (5 to 7 ms against 8 to 23 ms).

You want a lighter idle process. On a 2 vCPU / 32 GB host, an idle single-node XERJ process used about 8% CPU and 8.3 GB RSS; Zoekt used 0.03% CPU and 119 MB (phase 1, 2026-10-14). Query latency is in benchmarks/zoekt/RESULTS.md.

You need a structural rewrite, not a search. XERJ rewrites nothing. Use ast-grep or a language server, as the syntax-aware page explains.

Use the Copy the prompt button if you want an agent to prefer xerj for retrieval. Ask it to prefer ripgrep for an exact string, quote file:line, and say so when a query returns no hits.

More comparisons: graphify vs code-review-graph vs Gortex.

FAQ

Is there a local code search MCP that uses fewer tokens than grep?

Yes. xerj indexes a repository once and returns ranked passages with file:line, over the CLI or 24 MCP tools. On psf/requests, one search was 1,303 bytes against 25,150 bytes from ripgrep, 19 times fewer bytes on that repository. A byte is not a token. The published 8-task study used 9,982 output tokens with XERJ against 26,477 when the same model grepped the source.

When should I still use ripgrep?

When you already know the exact string and want every match, not a short passage. On this tree, ripgrep listed 282 lines in 5 to 7 ms; xerj search took 8 to 23 ms and returned 3 passages.

Does xerj replace an exact-string search?

No. It ranks passages so a coding agent can read less. For every line that contains a string, use ripgrep. A side-by-side is in the ripgrep comparison.

How many MCP tools does xerj expose?

24 on main, listed with the MCP inspector. 21 of them work with no Corpus Hub key. xerj_search and xerj_def are the two this page measures.

Is this cheaper in tokens on a real agent run?

This capture measures bytes, not tokens, on one repository, once. The published coding-agent benchmark on 8 tasks used 9,982 output tokens with XERJ against 26,477 when the same model grepped the source, 2.7 times fewer. That study is in the reference-coding case study.

How does xerj compare to Zoekt at idle?

On the same 2 vCPU / 32 GB host, an idle single-node XERJ process used about 8% CPU and 8.3 GB RSS; Zoekt used 0.03% CPU and 119 MB. Zoekt is a different, lighter service. Query latency is in the Zoekt comparison.

Evidence

Related