---
title: "Tree-sitter vs ast-grep (2026): which code search fits?"
canonical: "https://xerj.org/compare/tree-sitter-vs-ast-grep-2026"
updated: "2026-12-04"
---

# Tree-sitter vs ast-grep in 2026

SHORT ANSWER · UPDATED 2026-12-04
Pick Tree-sitter for building syntax-aware tools on top of a parser; pick ast-grep for syntax-aware search and codemods. Tree-sitter is a library in your process written in Rust under MIT, while ast-grep is a command-line tool written in Rust under MIT.
**Key number:** Tree-sitter: 27,693 GitHub stars, ast-grep: 16,859 GitHub stars (3 Dec 2026).
Stars, licences, languages and releases for 3 tools were fetched live from the GitHub API, GitHub release pages and the Hugging Face API on 3 Dec 2026. Hosted services link to their official sites and carry no invented numbers.

**TL;DR** Pick Tree-sitter for building syntax-aware tools on top of a parser.

## Agent prompt

```text
Read https://xerj.org/llms.txt. I am choosing between Tree-sitter and ast-grep. Index this project with xerj autoindex, connect xerj mcp, and use xerj_search to find where my code would call either one. Cite file and line.
```

## Pick one in ten seconds

- Pick [Tree-sitter](https://github.com/tree-sitter/tree-sitter) for building syntax-aware tools on top of a parser.
- Pick [ast-grep](https://github.com/ast-grep/ast-grep) for syntax-aware search and codemods.
- Pick [XERJ](https://github.com/xerj-org/xerj) when an AI agent should search local code, docs and logs over MCP, with citations.

## Where Tree-sitter shines

Incremental parser generator that builds concrete syntax trees for source files. It fits building syntax-aware tools on top of a parser. Plan for this: a parsing library, you build the search on top.

## Where ast-grep shines

Structural search, lint and rewrite tool that matches code by syntax tree. It fits syntax-aware search and codemods. Plan for this: patterns follow tree-sitter grammars.

## Key differences

- **How it runs:** Tree-sitter is a library in your process; ast-grep is a command-line tool.
- **Language:** Tree-sitter is mainly Rust and ast-grep too.
- **Licence:** Tree-sitter uses MIT; ast-grep uses MIT.
- **Release cadence:** ast-grep shipped 0.51.3 on 15 Nov 2026; Tree-sitter's latest GitHub release is v0.27.2 from 7 Nov 2026.

## Where XERJ fits

XERJ is a new way for AI to search for data: one local Rust binary that indexes code, docs, logs and data with `xerj autoindex` and returns passages with file and line citations. `xerj mcp` is a stdio MCP server, and `xerj mcp --http` serves Streamable HTTP at `http://127.0.0.1:9330/mcp`, read-only unless you pass `--allow-writes`. A non-loopback bind needs `XERJ_MCP_TOKEN`. Use it next to Tree-sitter or ast-grep when an agent has to answer from files on your machine.

## How we checked

Stars, licences, languages and releases for 3 tools were fetched live from the GitHub API, GitHub release pages and the Hugging Face API on 3 Dec 2026. Hosted services link to their official sites and carry no invented numbers. We describe what each project says it does and avoid ranking one above the other in general.

## Read next

- [Tree-sitter alternatives 2026: code search tools compared](https://xerj.org/compare/tree-sitter-alternatives-2026)
- [Semgrep vs ast-grep (2026)](https://xerj.org/compare/semgrep-vs-ast-grep-2026)
- [ast-grep alternatives 2026: code search tools compared](https://xerj.org/compare/ast-grep-alternatives-2026)
- [ast-grep vs ripgrep vs ugrep (2026): code search for AI agents](https://xerj.org/compare/ast-grep-vs-ripgrep-vs-ugrep)
- [XERJ vs ast-grep: syntax search and an index](https://xerj.org/compare/xerj-vs-ast-grep)
- [What is syntax-aware search?](https://xerj.org/science/syntax-aware-search)
- [Reference coding for AI coding agents](https://xerj.org/science/reference-coding)
- [What is agentic search? AI agents that search in a loop (2026)](https://xerj.org/science/agentic-search)

## FAQ

### Is Tree-sitter better than ast-grep?

Neither is better in general. Tree-sitter fits building syntax-aware tools on top of a parser, and ast-grep fits syntax-aware search and codemods. The 4-question picker on this page scores both for your workload.

### Are Tree-sitter and ast-grep open source?

Tree-sitter: MIT. ast-grep: MIT. Licences come from each repository on 3 Dec 2026.

### Which is easier to run, Tree-sitter or ast-grep?

Tree-sitter runs as a library in your process (a parsing library, you build the search on top). ast-grep runs as a command-line tool (patterns follow tree-sitter grammars).

### Which has more GitHub stars, Tree-sitter or ast-grep?

Tree-sitter had 27,693 stars and ast-grep had 16,859 on 3 Dec 2026. Stars measure attention, so weigh them with the fit questions above.

## Evidence

- [tree-sitter/tree-sitter](https://github.com/tree-sitter/tree-sitter): 27,693 stars, MIT, Rust, latest release v0.27.2, 7 Nov 2026 (GitHub API and release page, checked 3 Dec 2026).
- [ast-grep/ast-grep](https://github.com/ast-grep/ast-grep): 16,859 stars, MIT, Rust, latest release 0.51.3, 15 Nov 2026 (GitHub API and release page, checked 3 Dec 2026).
- [xerj-org/xerj](https://github.com/xerj-org/xerj): 23,588 stars, Apache-2.0, Rust, latest release v1.0.0-rc.105, 23 Nov 2026 (GitHub API and release page, checked 3 Dec 2026).

## Comparison table

| Tool | What it is | Runs as | Language | Latest release | Licence | Stars |
|---|---|---|---|---|---|---|
| [Tree-sitter](https://github.com/tree-sitter/tree-sitter) | Incremental parser generator that builds concrete syntax trees for source files | Library in your process | Rust | v0.27.2, 7 Nov 2026 | MIT | 27,693 |
| [ast-grep](https://github.com/ast-grep/ast-grep) | Structural search, lint and rewrite tool that matches code by syntax tree | Command-line tool | Rust | 0.51.3, 15 Nov 2026 | MIT | 16,859 |
| [XERJ](https://github.com/xerj-org/xerj) | One local Rust binary that indexes code, docs, logs and data, and serves cited search to agents over MCP | Command-line tool | Rust | v1.0.0-rc.105, 23 Nov 2026 | Apache-2.0 | 23,588 |
