COMPARE · COMPARISON: CODE RETRIEVAL

ast-grep vs ripgrep vs ugrep: which code search should your AI agent run?

AUTHOR · XERJ documentation team · REVIEWED BY · XERJ engineering team · PUBLISHED · 2026-11-22 · UPDATED · 2026-11-22
SHORT ANSWER · UPDATED 2026-11-22

ast-grep vs ripgrep vs ugrep: which one for an AI agent? ripgrep finds text and regex fast and respects .gitignore. ast-grep finds and rewrites code by syntax, using tree-sitter. ugrep adds Boolean and fuzzy queries and searches inside archives and PDFs. Most agents use ripgrep by default and add ast-grep for refactors.

Key number: ripgrep 16.0.0 shipped on 2026-11-22, and ripgrep has 70,142 GitHub stars. (as of 2026-11-22 · source: github.com/BurntSushi/ripgrep)

Last checked: 2026-11-22. Features come from each project's README; stars and releases from the GitHub REST API on that date.

TL;DR Use ripgrep to find text, ast-grep to find or rewrite a code shape, and ugrep when you want Boolean, fuzzy or archive search. They answer different questions, so many agents keep two of them.

Try it: answer three questions

Which search tool fits this job?

1. What is the agent looking for?
2. What does it do with the matches?
3. Which files?

Pick an answer above.

MIT or Unlicense · Rust

ripgrep

Recursive regex search that respects .gitignore and skips hidden and binary files.

MIT · Rust

ast-grep

Structural search, lint and rewrite on tree-sitter syntax trees.

BSD-3-Clause · C++

ugrep

Boolean AND, OR and NOT, fuzzy search, a query TUI, and search in archives and PDFs.

Apache-2.0 · Rust

XERJ

A local index that returns a few ranked passages with file:line, over MCP.

Runs in your browser and sends nothing. Each answer adds a point to the tools it matches. The examples come from each project's README: the ast-grep rewrite is the one in its README, and ug -Q opens ugrep's query TUI.
PASTE THIS TO YOUR AI AGENT. IT DOES THE REST Act as a coding agent. Read https://xerj.org/compare/ast-grep-vs-ripgrep-vs-ugrep. For each search you run in this repository, use ripgrep for names and regex, ast-grep for code shapes and rewrites, and ugrep for Boolean or fuzzy queries over mixed files. Tell me which tool you used for each search and why.

Side by side

Questionripgrepast-grepugrep
What it matchestext and regextree-sitter syntax patternstext, regex, Boolean and fuzzy queries
Rewrites matchesnoyes, with --rewriteno
Lint rulesnoyes, in YAMLno
Archives, compressed files, PDFsnonoyes
Respects .gitignore by defaultyesyeswith --ignore-files
Interactive modenoyes, --interactiveyes, query TUI with -Q
MCP servernoseparate ast-grep-mcp projectno
LicenceMIT or UnlicenseMITBSD-3-Clause
Latest release (2026-11-22)16.0.0 (2026-11-22)0.51.3 (2026-11-16)v7.8.5 (2026-09-15)
GitHub stars (2026-11-22)70,14216,6613,339
Installbrew install ripgrepbrew install ast-grepbrew install ugrep

When to choose ripgrep instead

Choose ripgrep for names, strings and regular expressions in a git repository. It needs no setup, respects .gitignore and skips hidden and binary files by default, so it is the right first call for most agent searches.

When to choose ast-grep instead

Choose ast-grep when the match depends on code structure, or when the agent must rewrite every match. Its patterns follow the syntax tree, so formatting and line breaks do not change the result, and YAML rules turn a pattern into a lint check.

When to choose ugrep instead

Choose ugrep for Boolean AND, OR and NOT queries, fuzzy matches, or search inside archives, compressed files, PDFs and documents. Its query TUI (ug -Q) is handy when a person searches alongside the agent.

ast-grep vs ripgrep

ripgrep answers "where does this text appear?". ast-grep answers "where does this code shape appear?" and can rewrite each match. Ask ripgrep for a function name. Ask ast-grep for every call of that function with a given argument pattern, then rewrite them in one step.

ugrep vs ripgrep

Both search text recursively. ugrep adds Google-like Boolean queries, fuzzy matches, a query TUI, and search inside zip, 7z and tar archives, compressed files, PDFs and documents. An optional ugrep-indexer speeds up search on slow or cold file systems. ripgrep keeps to fast regex search and respects your ignore files by default.

ast-grep vs ugrep

They rarely compete. ast-grep reads code as syntax trees for refactors and lint rules. ugrep reads any file as text, including archives and PDFs. A refactor goes to ast-grep; a search across a downloaded bundle of docs goes to ugrep.

When an agent needs ranked passages

All three print every match in file order. When an agent asks one tree many questions, a ranked index returns less to read: on psf/requests one XERJ answer was 1,303 bytes where ripgrep printed 25,150 (capture). XERJ is a new way for AI to search for data, and it sits next to ripgrep rather than replacing it. XERJ is single-node, and search is lexical by default.

How this page was checked

On 2026-11-22 we read the README of each project and the GitHub REST API for stars and the latest release. No head-to-head benchmark was run for this page; ripgrep publishes its own benchmarks in its README.

Read next

FAQ

ast-grep vs ripgrep: what is the difference?

ripgrep searches text with regular expressions and respects .gitignore by default. ast-grep matches code by its syntax tree, using tree-sitter patterns, and can rewrite every match. Many agents keep both.

ugrep vs ripgrep: what is the difference?

ugrep adds Boolean AND, OR and NOT queries, fuzzy search, a query TUI and search inside archives, compressed files, PDFs and documents. ripgrep focuses on fast recursive regex search that respects .gitignore.

Which one should a coding agent call first?

ripgrep for a literal name or regex, ast-grep for a code shape such as every call of a function with given arguments, and ugrep for Boolean or fuzzy queries over mixed files. For many questions over one tree, a ranked index such as XERJ returns fewer bytes.

Do any of them have an MCP server?

ast-grep has a separate ast-grep-mcp project (MIT). ripgrep and ugrep are command-line tools that agents call through the shell. XERJ ships xerj mcp.

Which licences do they use?

ripgrep is dual licensed MIT or Unlicense, ugrep is BSD-3-Clause and ast-grep is MIT.

Evidence

Related