sgrep cuts agent search cost 21% on SWE-bench, and the accuracy gain is within noise

Week 429 min read

TL;DR

Context.dev's open-source sgrep, a local semantic layer on top of ripgrep, cut LLM API spend by 21.3% in a 100-attempt SWE-bench Verified test while solving 70 attempts to ripgrep's 68. The authors' own confidence interval on that accuracy gap runs from minus 3 to plus 8 points.

On this page

What happened

Context.dev, a Y Combinator Summer 2026 company that sells a web-scraping and brand-data API, published sgrep, an MIT-licensed command-line tool that searches code and documents by meaning. It runs on the developer's machine, builds on ripgrep and needs no account, hosted index or model server. The launch announcement says it makes agents cheaper and more accurate, with 21.3% less LLM API spend than ripgrep and 70 of 100 attempts solved against 68 on SWE-bench Verified.

context-dot-dev/sgrep (GitHub)The repository. README, install steps and the full benchmark notes.github.com →

The repository's own write-up is more careful than the pitch. The test used one agent, GPT-6 Luna at medium reasoning, on 50 tasks from 12 repositories, each run twice. The README says the two-point accuracy difference had a 95% interval of minus 3 to plus 8 points. In its words that supports a prespecified five-point loss margin and does not establish better accuracy.

The project is young. The repository showed 21 stars and 14 commits when read, and the native Rust version with document search arrived as v0.3.0 on 7 October.

How it works

sgrep has two modes, and the benchmark headline comes from only one of them.

  • Discovery mode searches a folder by meaning, as in sgrep "when does a failed scrape consume credits" ./src. It lists files with ripgrep, splits them into passages of about 2,048 characters, embeds them and keeps an index in a local cache.
  • Pipe mode ranks the output of a focused ripgrep command, as in rg --json -C 3 'creditCost|shouldBill' ./src | sgrep "when does a failed scrape consume credits" --stdin. It ranks only the matches ripgrep returned and does not use the index.

The model is the unusual part. sgrep uses static embeddings, which store one learned vector per token. It looks up the vectors for a passage, averages them into 256 numbers and compares them with the query. That means no transformer runs at search time and no API call is made per query. Code uses Minish Lab's Potion Code 16M v2, distilled from CodeRankEmbed, and prose uses Potion Base 8M.

Results blend two signals. sgrep takes the top 200 keyword matches and the top 200 semantic matches, then scores 75% semantic and 25% BM25, and ranks exact, case-sensitive identifier matches first. Averaging loses word order and can miss context, the README says, and scores rank candidates against each other and carry no confidence meaning.

The benchmark, read closely

The benchmark notes list eight configurations with 100 attempts each, scored by the official SWE-bench patch and test grading.

Configuration Solved of 100 Mean LLM API cost per attempt Note
sgrep, pipe mode 70 $0.00475 The headline result
ripgrep 68 $0.00604 The baseline
ColGrep 69 $0.00654 Local semantic search using late-interaction models
sgrep, discovery mode 67 $0.00637 The persistent-index mode
Jevgrep 67 At least $0.11347 Hosted calls to TypeSafe's Jev. Lower bound, because three retrieval failures left no usage receipt
CK semantic 25 $0.00366 Left off the chart: 57 index setup failures
CK hybrid 27 $0.00348 Left off the chart: 58 index setup failures
ColGrep agent 62 $0.00392 Left off the chart: 46 search timeouts

Three things stand out in the table.

  • The saving is real and small in dollars. Pipe mode cost $0.00129 less per attempt than ripgrep, about $1.29 per thousand attempts at GPT-6 Luna prices. That is my arithmetic from the table.
  • The headline belongs to pipe mode. sgrep's own discovery mode solved 67 and cost 5.5% more than ripgrep.
  • Accuracy is a statistical tie. The notes say small vertical differences in the chart do not establish superiority, and the paired interval for sgrep over ripgrep spans minus 3 to plus 8 points.

The authors disclose their limits plainly. Cost covers the coding and retrieval model calls, cache reads and writes, and output and reasoning tokens, and leaves out machine and grading costs. Agents chose their own queries, so pairing is by task and not by identical queries. Runs used four-core, 8 GiB CPU sandboxes and one agent policy. There is no matched output-length ablation, and overlap with public training data was not audited. The repository holds the derived ledgers of all 800 attempts but not the raw model transcripts.

How it helps developers and agents

Search is a large share of an agent's work. Morph's docs cite Cognition's finding that coding agents spend about 60% of their turns searching for code, and every result an agent reads costs tokens.

For agents, sgrep fits a gap ripgrep leaves. An agent often knows what code should do before it knows a name to search for. With ripgrep it must guess patterns, and broad ones flood the context while narrow ones miss. The pattern the benchmark used is cheap to copy:

  • Let the agent run a focused ripgrep command with a few candidate terms and the --json -C 3 flags.
  • Pipe the output into sgrep with the intent in plain English and a result limit such as -n 20.
  • The coding model then reads the best twenty passages and not every match.

That saves money without adding a model call, since the ranking uses a lookup table and runs on the CPU. Search subagents such as Morph's WarpGrep, which Morph says is 15.6% cheaper and 28% faster on SWE-Bench Pro, spend an extra language-model call per search.

For developers, the appeal is local and low-friction:

  • Describe behavior in plain English to explore an unfamiliar repository, for example when a failed job consumes credits.
  • Source and queries stay on the machine, and after the first model download searches can run offline.
  • Output is easy to script. --json returns structured results, --explain shows the keyword, semantic and combined scores, and exit codes follow grep: 0 for results, 1 for none and 2 for errors.
  • --model text searches documentation folders, though the benchmarks measure only code.

One gap for agent builders: the README documents a command-line tool and lists no MCP server or agent plugin. It says CK offers an MCP server, so an agent has to be told to call sgrep through the shell.

How it compares with other search tools for agents

sgrep is one of several attempts to give agents something better than plain grep. They differ in where they run and what they spend.

Tool Where it runs How it searches What to know
ripgrep Local Exact text and regex Right for known names. Intent queries need agent-chosen patterns, per sgrep's README
sgrep Local, CPU Keywords plus static embeddings, in pipe or index mode Needs Rust 1.90 and ripgrep. Downloads a 32 to 34 MB model once
CK Local Semantic and hybrid search with several embedding models, plus an MCP server Needs an index. Its semantic mode beats sgrep on the CoSQA test, per sgrep's README
mgrep Hosted Semantic search with reranking Syncs files to Mixedbread and needs authentication. Not measured by sgrep's authors
ColGrep Local ColBERT late-interaction models fused with keyword search LightOn says it needed 56% fewer search operations than grep with Claude Code
Jevgrep Hosted Verifies and re-ranks candidates with TypeSafe's Jev model Needs a TypeSafe API key. Cost at least $0.11 per attempt in sgrep's test
WarpGrep Hosted subagent A separate language model runs repeated grep and file reads Morph says it is 15.6% cheaper and 28% faster on SWE-Bench Pro. Each search spends a model call

Two other results frame the field. FastContext, an open exploration subagent, reports 9% to 25% fewer tokens across three benchmarks on its small models and up to 60.3% for one agent on SWE-QA, per its model card. In sgrep's own sandboxes, the setup failures and timeouts that sank CK and ColGrep's agent mode show that a search tool can cost more in reliability than it saves in tokens.

The numbers above come from different benchmarks, agents and years of code, so they cannot be ranked against one another. sgrep's distinct bet is that a lookup-table model can do the ranking for free on the CPU.

Fine print

  • Install. sgrep needs Rust 1.90 or later and ripgrep, and installs with cargo install --git https://github.com/context-dot-dev/sgrep --locked. A prebuilt binary exists for macOS on Apple Silicon, and the v0.3.0 release notes say only macOS on ARM was exercised.
  • First run. The first search downloads a 32 to 34 MB model and any code parsers. Later searches can run offline, and HF_HUB_OFFLINE=1 blocks further downloads.
  • A local copy of your source. The index stores copies of source passages in the cache until cleanup or manual deletion. The cache holds at most 256 MiB and 128 entries, drops entries unused for 30 days, and can be changed with SGREP_CACHE_MAX_BYTES or skipped with --no-cache.
  • Hidden files. Normal searches follow ripgrep's ignore rules and skip hidden and binary files, but piped ripgrep results can include hidden or ignored files if ripgrep was told to look there.
  • Language support. Syntax-aware chunking covers Python, C and C++, Go, Java, Rust, JavaScript and TypeScript. Other files use plain text splitting, and PDFs and images are not parsed.
  • Mixed folders. Auto mode uses the prose model only when every candidate has a prose extension such as .md or .txt, and uses the code model otherwise.
  • Scores. They rank candidates against each other. The README says a high score is only a ranking signal, with no proof that code performs a task.
  • Whole functions or snippets. Per the README, sgrep leads on retrieving complete functions on RepoQA while CK's semantic mode leads on snippet retrieval on CoSQA. Both datasets were used during development.
  • Speed. The v0.2.0 notes put a complete sgrep search at 71 ms against 23 ms for ripgrep, on an older build, and the repeated latency tests ran on an M5 Max laptop.
  • Documents. The benchmarks measure code retrieval only, so document search has no headline quality claim.

What to watch

  • Other agents and models. The test used one agent policy on GPT-6 Luna. Whether the saving holds with pricier models or with other coding agents is untested.
  • Replication. Fifty tasks across 12 repositories is a small sample, and the accuracy interval is wide. The authors publish the protocol and attempt ledgers so others can rerun it.
  • Agent integration. No MCP server or plugin is documented yet, which leaves adoption to developers wiring sgrep into their own agent setups.
  • Maintenance. sgrep sits alongside a company whose main product is a scraping API, and no roadmap was found in the repository.
  • Document search. The text model has no benchmark of its own.

Sources

  1. context-dot-dev/sgrep (GitHub): the README, install steps, how search works, cache and privacy details.
  2. sgrep benchmark notes: the SWE-bench table, method, limits and retrieval tests.
  3. sgrep releases and pull request 10: v0.2.0 and v0.3.0 notes, latency method.
  4. Launch HN: Context.dev and Runtime Wire: what Context.dev is.
  5. LightOn on ColGrep and lib.rs: ColGrep and its claims.
  6. jevr (docs.rs): how the Jev-based search tool works.
  7. WarpGrep docs and Morph on agentic search: search subagents and the 60% figure.
  8. FastContext 1.0 model card: token savings of an open exploration subagent.

Continue reading