15.7k stars · MIT · 0.45.3 (2026-08-31) · Track this in Scout
Searches and rewrites code by matching the syntax tree rather than the raw text, so a pattern written in the language itself finds every real match.
▶Repo detailsthe review · specs · pros & cons · install
What it is
ast-grep is a single command-line program written in Rust. It parses your code into a tree, the same way a compiler does, and matches patterns against that tree rather than against the raw characters. It supports many languages and can also run a set of your own rules as a checker.
What it is good for. Anybody making the same change in many places. The pattern is written in the language itself: console.log($ARG) finds every one of those calls whatever the spacing or line breaks. Rewrites use the same notation, so a rename across four hundred files is reliable instead of hopeful. This is the best pairing on the page with a coding assistant. Instead of asking it to read the whole project and find every place something happens, you hand it one exact command that already found them.
- Fast on large projects, and there is nothing left running afterwards.
- Rewrites are expressed the same way as searches, so what you found is what you change.
- You can write your own rules as text files and run them as a project checker.
- Simple patterns are easy but the rule format has a real learning curve once you need conditions and relationships between pieces of code.
- Language support depends on community grammars, so an unusual language may parse badly or not at all.
- It is still before version 1.0 after several years, and the rule format has changed between releases, so saved rules can need revisiting after an upgrade.
- comby-tools/comby
The same structural search and replace across many languages, using lighter parsing, so it is more forgiving and less precise.
Track this in Scout - biomejs/gritql
The same declarative searching and changing of code, now maintained inside the Biome project rather than as a standalone tool; it moved from getgrit/gritql.
Track this in Scout - semgrep/semgrep
The same idea of matching on code shape, aimed at security checks with a large public rule library, but heavier, licensed LGPL-2.1, and built to report problems rather than fix them.
Track this in Scout
npm install --global @ast-grep/cli # or: pip install ast-grep-cli # or: brew install ast-grep ast-grep run --pattern 'console.log($ARG)' --lang ts src/

