
ast-grep
A command-line tool that searches, lints, and rewrites code by its syntax structure, not plain text.
- Stars
- 16.4k
- Forks
- 488
- Licence
- MIT
- Language
- Rust
- Last update
- 4 days ago
- Type
- CLI
What it is
ast-grep is a command-line tool that searches code by matching its syntax tree rather than raw text, so a pattern written like ordinary code can find every place that shares the same structure. It can also rewrite matches and run YAML-defined lint rules. People use it to find usages, migrate code across breaking changes, or enforce team coding standards.
- Find all calls matching a code pattern across a project
- Rewrite a deprecated API call to its replacement across many files
- Write a YAML lint rule that flags a specific code pattern
- Try patterns interactively in the online playground before running them
Great for
- Developers who want grep-like searching that understands code structure
- Library authors migrating users across breaking API changes
- Tech leads who want to enforce custom code practices with lint rules
- Engineers doing large-scale, consistent code rewrites
Not ideal for
- People who only need simple text search, since plain grep or ripgrep is simpler for that
- Non-programmers, because patterns assume familiarity with code syntax
- Languages not supported by its tree-sitter parsers, which the README does not fully list
How to get it
- 1
Install with a package manager
Install via npm
npm install --global @ast-grep/cliInstall via pip
pip install ast-grep-cliInstall via Homebrew
brew install ast-grepInstall via cargo
cargo install ast-grep --locked - 2
Run it
- Install ast-grep using one of the package manager commands above.
- Run a search with: ast-grep --pattern 'var code = $PATTERN' --lang ts
- Add --rewrite to replace matches with a new pattern.
- Try example patterns in the online playground at ast-grep.github.io/playground.html.
- 3
Get the most out of it
- Use $ wildcards such as $MATCH to match any single syntax node.
- Write YAML configuration files to define custom lint rules.
- Use the jQuery-like API for traversing and manipulating the syntax tree.
- Run it across multiple cores, as the README notes it uses multiple cores for parsing.
- Check the official website for more screenshots and documentation.
Downloads
Strengths
- Patterns look like the code you already write
- Matches by syntax tree, so it ignores formatting differences
- Installable through many package managers including npm, pip, Homebrew, and cargo
Trade-offs
- Its matching depends on the language grammars it supports, so coverage varies by language
- The README is truncated and does not describe every feature or limitation in detail
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| ast-grep (this) | 16.4k | CLI | beginner | 4 days ago | Developers who want grep-like searching that understands code structure |
| jscodeshift | 10k | Dev tool | intermediate | 9 days ago | Engineers migrating a large JavaScript or TypeScript codebase to a new API or syntax |
| ruff | 50.4k | CLI | beginner | 4 days ago | Python developers who want one tool for linting and formatting |
| broot | 13.1k | CLI | intermediate | 5 days ago | Developers who work in a terminal and often jump between project folders |
| babel | 44.1k | Dev tool | intermediate | 4 days ago | Web developers who want to use recent JavaScript syntax while still supporting older browsers |
| code-review-graph | 32.6k | Dev tool | beginner | 8 days ago | Developers who use an MCP-compatible AI coding assistant on a large repository |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.