- Home
- Code Search Tools
- ast-grep
ast-grep
What it is
ast-grep is an open-source tool for searching, linting, and rewriting code through its structure rather than plain text. Its patterns match syntax-tree nodes, helping developers locate and change code across a codebase. The CLI can preview and apply rewrites interactively, and scan configurable YAML lint rules with error, warning, info, and hint severity levels. Rules can combine pattern, kind, regex, relational, and composite conditions; CLI commands also support creating and snapshot-testing rules. The project says it supports 20+ languages and can load custom languages. Developers can use a JavaScript API to inspect and change syntax trees, or a WebAssembly API in browsers and other WASM environments. An online playground allows pattern and rewrite-rule experiments without a local installation. Editor options include a VS Code extension and language-server support, with guides for Vim, Neovim, and Emacs. The FAQ notes limits on advanced static-analysis information and says a rule cannot target multiple languages at once.
For and against
For
- Searches and rewrites code through syntax-tree patterns
- Supports 20+ languages and custom languages
- Includes configurable YAML lint rules
- Offers JavaScript and WebAssembly APIs
- Online playground requires no local installation
Against
- Some advanced static-analysis information is unsupported
- A rule cannot target multiple languages at once
The verdict
ast-grep combines structural search and rewriting with configurable linting and several ways to integrate it into development workflows. Consider its documented limits if your rules depend on advanced static-analysis information or must cover multiple languages at once.
Who it suits
It suits developers who need structural search, linting, or bulk code changes across supported languages. It may also fit users who want editor integration or a browser playground for trying patterns.
Plans and prices
ast-grep
Pricing not stated on the opened official pages
Read 4 Oct 2026 · ast-grep.github.io
On the record
- APIs
- ast-grep provides a JavaScript API for programmatically inspecting and changing syntax trees, plus a WebAssembly API for browsers and other WASM environments.ast-grep.github.io · read 4 Oct 2026
- Code rewriting
- The CLI can interactively preview and apply rewrites to matching code.ast-grep.github.io · read 4 Oct 2026
- Custom rules
- Rules are written in YAML and can combine pattern, kind, regex, relational, and composite matching conditions.ast-grep.github.io · read 4 Oct 2026
- Distribution
- The CLI is distributed through npm, Cargo, Homebrew, MacPorts, Nix, and pip, and can also be built from source.ast-grep.github.io · read 4 Oct 2026
- Install methods
- The CLI is distributed through npm, Cargo, Homebrew, and MacPorts, with source builds also available.ast-grep.github.io · read 4 Oct 2026
- Integrations
- The documentation describes editor integrations, including a VS Code extension and language server support for editors such as Vim and Neovim.ast-grep.github.io · read 4 Oct 2026
- Languages
- The project says it supports 20+ languages and allows custom languages to be loaded.ast-grep.github.io · read 4 Oct 2026
- Language support
- The site says ast-grep supports 20+ programming languages and can load custom languages.ast-grep.github.io · read 4 Oct 2026
- Limits
- The FAQ says ast-grep does not currently support some advanced static analysis information.ast-grep.github.io · read 4 Oct 2026
- Linting
- The scan command runs configurable AST pattern rules and supports severity levels including error, warning, info, and hint.ast-grep.github.io · read 4 Oct 2026
- Lint rules
- Users can define custom lint rules with AST patterns and receive error reporting.ast-grep.github.io · read 4 Oct 2026
- LSP capabilities
- The language server publishes diagnostics and supports diagnostic code actions; linting diagnostics require an sgconfig.yml project file.ast-grep.github.io · read 4 Oct 2026
- Notable limitation
- A rule cannot target multiple languages at once; the FAQ recommends a superset language with languageGlobs or separate rules for each language.ast-grep.github.io · read 4 Oct 2026
- Other editor integrations
- The editor guide documents setups for Neovim and Emacs, plus community integrations for coc.nvim, Telescope, and grug-far.nvim.ast-grep.github.io · read 4 Oct 2026
- Pattern search
- It matches code patterns against syntax tree nodes rather than searching source text.ast-grep.github.io · read 4 Oct 2026
- Performance
- The site describes search and replace across thousands of source files as powered by parallel Rust.ast-grep.github.io · read 4 Oct 2026
- Programmatic API
- The JavaScript API lets programs inspect and change syntax trees using JavaScript.ast-grep.github.io · read 4 Oct 2026
- Publisher
- The site credits Herrington Darkholme in its copyright notice.ast-grep.github.io · read 4 Oct 2026
The review
ast-grep is a free, open-source tool for developers who need to find, lint, or change code by its structure across a codebase. It is best for repeatable syntax-aware workflows; teams that depend on deeper static analysis or one rule spanning multiple languages should look elsewhere.
Overview
Instead of matching raw source text, ast-grep compares patterns with nodes in a program’s abstract syntax tree. That makes searches less dependent on formatting and gives refactors a way to target code shape rather than a particular string. Its CLI can preview and apply changes interactively, and the project describes parallel Rust processing for searches and replacements across thousands of files.
The scope is deliberately practical: structural search, linting, and rewriting, not every kind of program analysis. The FAQ says some advanced static-analysis information is not supported, so ast-grep is a poor sole choice for rules that need that context.
Key features
Search, rewrite, and lint
Pattern search works against syntax-tree nodes, while the CLI’s interactive rewrite mode lets developers review matching changes before applying them. This is useful for broad, repeatable refactors where a text replacement could be too blunt. The scan command runs configurable AST-pattern rules with error, warning, info, and hint severities, making it suitable for code-shape checks that teams want surfaced as lint findings.
Rules and testing
YAML rules can combine pattern, node-kind, regex, relational, and composite conditions. That gives a rule author several ways to narrow a match without building a separate tool for each check. CLI commands support creating and testing rules, including snapshot-based tests, which makes a growing rule set easier to validate before it becomes part of a workflow.
Language and editor coverage
The project supports more than 20 languages and can load custom languages, but a single rule cannot target multiple languages at once. The FAQ points to a superset language with languageGlobs or separate per-language rules as workarounds; either adds setup when a policy needs to cover several syntaxes.
The official VS Code extension provides a CLI interface and language-server client. The server publishes diagnostics and code actions, though lint diagnostics require an sgconfig.yml project file. Documentation also covers Vim, Neovim, and Emacs setups, with community integrations for coc.nvim, Telescope, and grug-far.nvim.
APIs and access
A JavaScript API lets programs inspect and change syntax trees, and a WebAssembly API supports browsers and other WASM environments. The browser playground offers a way to try patterns and rewrite rules without installing the CLI. Distribution through npm, Cargo, Homebrew, MacPorts, Nix, and pip, as well as source builds, gives developers multiple routes to add the CLI to existing environments.
The example catalog includes security rules such as checks for a Go JSON tag vulnerability and C/C++ format-string risks. These examples show a use for structural matching in security checks, but they do not remove the stated limits on advanced analysis.
Pricing
ast-grep is free and open source, with the ast-grep plan at no cost. There is no free trial because there is no paid tier to trial. The project’s open-source model makes it a straightforward option for individual developers and teams that can use its codebase-focused, self-hosted workflow without a subscription.
Platforms
ast-grep is listed for API, extension, Linux, macOS, web, and Windows. The CLI distribution channels and editor support make it usable in development workflows across those environments; the web playground and WebAssembly API cover browser-oriented use.
Who it's for
Choose ast-grep when a team needs structural search and repeatable rewrites, wants custom lint rules with explicit severity levels, or plans to integrate syntax-tree operations into JavaScript or WASM software. It also suits developers who prefer to run code search locally and build rules around their own repositories.
Look elsewhere or pair it with a deeper analysis tool when checks require advanced static-analysis information. For policies that must apply across languages, be prepared to maintain separate rules or configure a superset-language approach.
Pros and cons
- Structural matching: Targets syntax-tree nodes, so searches and rewrites can focus on code shape instead of exact source text.
- Flexible rule authoring: YAML rules support multiple matching conditions, and CLI rule tests include snapshot options.
- Broad integration choices: Editor support, JavaScript and WebAssembly APIs, a playground, and several CLI package channels offer different ways into a workflow.
- Analysis boundary: Some advanced static-analysis information is unsupported, limiting rules that need more than syntax-level context.
- Per-language rule work: A rule cannot target multiple languages at once, which can increase maintenance for polyglot codebases.
Alternatives
For other options, browse Code Search Tools and Code Refactoring Tools.
- Chromium is a free, open-source option for readers looking for software across Windows, macOS, Linux, and Android.
- Sourcebot is worth considering for readers who want a freemium, web-based or self-hosted code-search option with a free plan and trial.
- sqry is another free, locally run, open-source option for Linux, macOS, and Windows.
- Chatterbox TTS is a free, open-source-model option for Linux or self-hosted use.
- Code Fundi may suit readers seeking a freemium option with a paid Dev plan at $21 a month.
- Code Search offers a free Community plan with unlimited users, full-text search, repository find-and-replace, a CLI, and MCP server.
- LXR Cross Referencer is a free, open-source project for self-installed Linux, web, or self-hosted use.
- OpenGrok is a free, open-source project for readers who want an option spanning API, desktop, web, and self-hosted platforms.
Verdict
ast-grep is an easy recommendation for developers who need free, scriptable structural search, linting, and refactoring across a codebase. Its strongest reason to choose it is the combination of configurable AST rules and interactive rewrites; its clearest reason to look elsewhere is a need for advanced analysis or a single rule set that directly spans multiple languages.