<!-- generated by build_articles.py — edit content/answers/local-code-search-mcp-fewer-tokens-than-grep.md instead -->
---
title: "Local code search MCP that uses fewer tokens than grep"
canonical: "https://xerj.org/answers/local-code-search-mcp-fewer-tokens-than-grep"
updated: "2026-11-13"
source: "content/answers/local-code-search-mcp-fewer-tokens-than-grep.md"
---

# Local code search MCP that uses fewer tokens than grep

**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.

## Agent prompt

```text
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.
```

## Commands

### Command 1

Note: Install the release binary into ~/.local/bin.

```sh
curl -fsSL https://xerj.org/get | sh
```

### Command 2

Note: Index the current tree. On psf/requests: 2.9 s, 95 files, one junk warning, exit 3.

```sh
xerj autoindex .
```

### Command 3

Note: 3 passages, 1,303 bytes, first hit sessions.py:309.

```sh
xerj search "how are HTTP redirects followed" -k 3 --full 400
```

### Command 4

Note: Declaration plus symbol list, 949 bytes, sessions.py:154.

```sh
xerj def should_strip_auth
```

The token-budget idea is [What is context engineering?](/science/context-engineering). MCP is [What is the Model Context Protocol?](/science/model-context-protocol).

*Figure: 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:

```sh
curl -fsSL https://xerj.org/get | sh
git clone https://github.com/psf/requests.git && cd requests && git checkout 611c6162
xerj autoindex .
```

```text
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:

```sh
xerj search "how are HTTP redirects followed" -k 3 --full 400
```

```text
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:

```sh
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:

```sh
xerj def should_strip_auth
```

```text
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](/answers/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](/case-studies/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](/compare/xerj-vs-ripgrep-for-code-agents). For syntax-aware lookups (declarations by kind, name and line), see [syntax-aware code search versus ast-grep](/answers/syntax-aware-code-search-refactoring). To ask about a catalogue repo without cloning it, see [ask questions about a GitHub repo without cloning](/answers/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](/compare/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

- autoindex: 2.9s, 95 files / 36 code, exit 3 (1 junk file) Source: `benchmarks/agent-intents-2026-10-19/01-autoindex-requests.txt`
- xerj search: 1,303 bytes, sessions.py:309 first Source: `benchmarks/agent-intents-2026-10-19/01-xerj-search.txt`
- rg -n -i redirect: 282 lines, 25,150 bytes Source: `benchmarks/agent-intents-2026-10-19/01-rg-redirect.txt`
- Wall times 8 to 23 ms for xerj search, 5 to 7 ms for rg; opening 17 files would have been 447,383 bytes Source: `benchmarks/agent-intents-2026-10-19/README.md`
- xerj def should_strip_auth: 949 bytes, sessions.py:154 Source: `benchmarks/agent-intents-2026-10-19/01-xerj-def.txt`
- On main xerj mcp serves 24 tools, or 21 in a build with no hub key Source: `landing/docs/agents/schemas/mcp-tools.json`
- Published agent benchmark: 9,982 vs 26,477 output tokens, 2.7 times fewer, 8 tasks; idle 8% CPU and 8.3 GB vs Zoekt 0.03% and 119 MB, on a 2 vCPU / 32 GB host Source: `landing/benchmarks/index.html`

## Related

- [What is context engineering?](/science/context-engineering)
- [I need my agent to find a passage and cite the file, not dump the whole tree. How?](/answers/code-search-mcp-for-claude-code)
- [Chat with a GitHub repo without cloning it](/answers/ask-questions-about-a-github-repo-without-cloning)
- [Syntax-aware code search: XERJ vs ast-grep](/answers/syntax-aware-code-search-refactoring)
- [How to run hybrid search in XERJ](/answers/what-is-hybrid-search)
- [Is ripgrep enough for a coding agent, or do I need a code index?](/compare/xerj-vs-ripgrep-for-code-agents)
- [Reference-coding for Claude Code](/case-studies/reference-coding)
