ripgrep vs ast-grep vs Zoekt vs Semgrep: the search tool you hand an agent

Now that the frontier coding agents have dropped the embedding index and search the tree directly, the search binary behind the agent's Grep tool is a product decision rather than a detail. These four answer four different questions exactly — a string, a shape of code, a ranked hit across thousands of repositories, and whether untrusted input reaches a sink — and the capability ordering runs opposite to the licensing one: Semgrep is the most powerful and the only one whose rules are restricted to internal business use, while ripgrep, ast-grep and Zoekt are permissive. Choose on what the agent can verify and what you are allowed to ship.

By Agentic AI Wiki 10 min read

The most capable code-search tool on this list is the one you are least free to ship. That inversion is the whole decision: now that frontier coding agents have dropped the embedding index and search the working tree directly, the binary behind the agent's search tool is a product choice, and the four leading candidates answer four different questions exactly — a string, a shape of code, a ranked hit across thousands of repositories, and whether untrusted input reaches a sink. Pick on what the agent can verify and what your licence permits, in that order.

At a glance

All four are things you can hand an agent as a tool today. They are not competitors in the usual sense: three of them answer questions the others cannot express at all.

ToolQuery modelIndexLicence
ripgrep Literal and regex, line-oriented None Permissive (Unlicense / MIT)
ast-grep Syntax-tree patterns via tree-sitter None MIT
Zoekt Ranked search across many repositories Persistent trigram index Apache-2.0
Semgrep CE Semantic rules, taint within a file None Split: LGPL-2.1 engine, restricted rules
Code search backends compared on three axes A four by three matrix. ripgrep: literal and regex queries, no index, permissive licence. ast-grep: syntax-tree patterns, no index, permissive licence. Zoekt: ranked trigram queries, a persistent index, permissive licence. Semgrep CE: semantic rules, no index, and a split licence whose rules are restricted to internal business use. Legend: permissive, conditional, restricted. What each backend answers, and what you may ship What it can match Needs an index Licence to ship on ripgrep Literal and regex No Permissive ast-grep Syntax-tree patterns No Permissive (MIT) Zoekt Ranked, many repos Yes, trigram Permissive (Apache-2.0) Semgrep CE Semantic rules No Split: rules restricted Strongest on this axis Partial Weakest or absent
Capability rises down the first column; licensing freedom falls in the last one.
The question each search tier can answer exactly Four bands. ripgrep answers where a given string appears. ast-grep answers where a shape of code appears, independent of names and whitespace. Zoekt answers which of many repositories mentions a symbol, ranked. Semgrep answers whether a dangerous pattern reaches a sink. The two middle and last tiers shade toward higher cost; only Zoekt keeps a persistent index. One question per tier, answered exactly ripgrep Where does this string appear? ast-grep Where does this shape of code appear, whatever it is named? Zoekt Which of these 4,000 repositories mentions it, best first? Semgrep CE Does untrusted input reach this sink? No index, instant More setup Most expensive to run
The useful way to choose: which of these four questions does your agent keep asking badly?

Why this became a decision in 2026

For two years the interesting question about code retrieval was which embedding model to use. It stopped being interesting when the frontier harnesses abandoned the index: Cursor removed its semantic codebase indexing during 2026 — the resync and delete-index controls came out of the UI, and retrieval moved to a locally built exact-match index it calls instant grep — and Claude Code never had one at all, navigating with glob, regex search and file reads against the tree as it is on disk.

Cursor's stated reason, posted on its own community forum, is worth quoting in substance: models got good enough at using grep and indexed search that the dedicated semantic path stopped helping in a meaningful way. Cursor's own earlier research had measured roughly a 12.5% average accuracy gain from semantic search over grep alone, so the gain was real; it got eaten by better tool use rather than disproven.

And a May 2026 study found that the thing deciding the outcome was not the retriever at all. Is Grep All You Need? How Agent Harnesses Reshape Agentic Search (arXiv:2605.15184) held retrievers fixed and varied delivery: with results returned inline in the tool response, grep beat vector retrieval on all ten harness-and-model pairs tested; with results written to files the agent had to open, vector won five of ten. Exact search wins because its failures are legible — zero hits means the name is wrong, four hundred means the term is too generic — which is exactly what an iterating model needs.

So the embedding question collapsed into a plainer one: which exact-search tool, with what query language, returning what shape of result. That is what the rest of this post is about, and the operational version of it is in repo navigation and code context.

ripgrep — the default, and usually right

ripgrep is a line-oriented regex search in Rust with no index and no state, distributed as one binary, under a permissive licence (sources list the Unlicense, some MIT). It is what most agent harnesses shell out to, and the reason is not speed: it is that path:line:match is the ideal result shape for a model. Each hit is independently checkable, cheap to return, and carries the coordinates the agent needs to open a 40-line window rather than a whole file.

Its limit is that a regex cannot express structure. except:\s*pass finds bare excepts written that way and misses the ones with a comment in between; a pattern for "this function called with a literal as the second argument" is not writable at all. In a well-named codebase that limit rarely binds, which is why ripgrep remains the right default and the others are additions rather than replacements.

ast-grep — the cheapest real upgrade

ast-grep matches patterns against a tree-sitter syntax tree, so the pattern is written in the language being searched rather than in regex. foo($$$ARGS) matches that call however it is formatted, across line breaks, ignoring comments and whitespace. It is MIT, a single Rust binary, and needs no index — so it has the same operational profile as ripgrep and strictly more expressive power on anything with a tree-sitter grammar.

For an agent that distinction matters in one specific way: ast-grep answers "where is this construct" rather than "where does this text occur", so it is the tool for the class of query where the answer exists but the name does not. It is also a rewriter, which makes it the natural instrument for the mechanical half of a large-scale migration — the agent proposes a pattern and a replacement, and the tool applies it deterministically to 400 sites instead of the model editing each one and drifting.

Zoekt — the one that is about scale, not about matching

Zoekt is a trigram-indexed, ranked code search engine under Apache-2.0, built for searching many repositories at once. Its axis is different from the other three: it does not match anything the others cannot, it answers across a corpus the others cannot walk in a reasonable time.

Which makes its trade-off the one from index freshness and invalidation, not from retrieval quality. An index means a sync job, and a stale code index is worse than no index because it returns a line number that no longer exists with full confidence — the failure that confident wrong localization is named after. Run it when your agent's question genuinely spans an organisation's repositories rather than one checkout, and keep a non-indexed tool mounted alongside for the current working tree.

Semgrep — most powerful, most constrained

Semgrep's community edition is an open-source engine under LGPL-2.1 that evaluates semantic rules, including taint tracking within a single file: it can answer whether a value from an untrusted source reaches a dangerous sink, which none of the other three can express. Cross-file taint analysis is not in CE; it requires the paid platform.

The constraint is the rules, and it is the part teams discover late. The rules in Semgrep's own rules repository — community and pro alike — are published under the Semgrep Rules License v1.0, which makes them available for internal business use. That is a perfectly ordinary arrangement and a serious problem for exactly one use case: shipping or reselling a product whose value comes from running those rules for someone else. If your agent is an internal security reviewer, this is a non-issue. If your agent is a product, read the licence before you build the feature, not after.

That is the general lesson rather than a Semgrep complaint: a search backend is a dependency with a licence, and for agent products the licence is load-bearing in a way it is not for a developer's own terminal. Open-weight licences makes the same argument about models.

What the agent gets back matters more than which tool produced it

Across all four, the result shape is the variable with the largest effect on agent behaviour, and it is the one under your control rather than the vendor's. The May 2026 harness result says delivery flipped the winner between retrievers; the same mechanism applies between these four.

Three rules follow, and they apply whichever backend you mount. Return hits inline, with path, line and a few lines of surrounding context, so the model can decide what to open without opening anything. Cap the result set and say so explicitly — a tool that silently truncates at 50 hits teaches the model that 50 is the answer, where "412 matches, showing 50, narrow your pattern" teaches it to refine. And return the count even when you cannot return the hits, because a count is the signal that distinguishes "wrong name" from "too generic". The general form of all three is in shaping tool results and tool error messages.

When to pick which

SituationMount thisWhy
One repository, ordinary agent coding workripgrep aloneRight default; the result shape is what matters, and an index buys nothing at one checkout.
Agent keeps missing constructs because names varyripgrep plus ast-grepSame zero-setup profile, expresses structure, and rewrites deterministically.
Questions span hundreds or thousands of repositoriesZoekt, plus a non-indexed tool for the working treeOnly one of the four answers a ranked corpus query; accept the sync job.
Internal agent reviewing for vulnerability classesSemgrep CETaint-to-sink is inexpressible in the others; internal use is what the rules licence covers.
Agent is a product you sellripgrep, ast-grep or ZoektAll three are permissive; the Semgrep rules licence is scoped to internal business use.

FAQ

Is semantic code search dead?

No — the measured gain was real and the frontier harnesses dropped it anyway, because better tool use reached the same answers more cheaply. It still earns its place for the query whose target has a name nobody wrote, and for latency against a very large tree, which is why index-based products kept their index.

Should I give an agent more than one search tool?

Usually two at most, and only when they answer different questions. Mounting four overlapping search tools spends description tokens on every turn and makes selection the model's problem rather than yours; ripgrep plus one structural tool covers nearly everything.

Does Semgrep's licence stop me using it with an agent at all?

Not for internal work — that is exactly what the rules licence permits. The constraint bites when running those rules is the service you charge for. The LGPL-2.1 engine and the rules are licensed separately, so read both.

Why does returning the match count matter so much?

It is the cheapest piece of information in the loop and it decides the next move. Zero hits means the identifier is wrong; four hundred means the pattern is too generic. Without the count, both look like "this did not work" and the model guesses.

Is ast-grep a replacement for ripgrep?

No, an addition. Regex is still the right instrument for a literal string, a log line or a config key, and it works on files no grammar covers. Structural search earns its keep on code, in the cases where formatting or naming defeats a pattern.

Further reading

On this wiki:

Sources: