
ast-grep
Summary
ast-grep is a free, open-source tool for structural code search, linting, and rewriting. It matches patterns against syntax tree nodes rather than plain source text, helping developers find and change code across a codebase. Its CLI can preview and apply rewrites interactively, and scan configurable YAML rules with error, warning, info, or hint severity. Rules can combine pattern, kind, regex, relational, and composite conditions; CLI commands support creating and snapshot-testing them. The project says it supports more than 20 languages and can load custom languages. Developers can use its JavaScript API to inspect or change syntax trees, or its WebAssembly API in browsers and other WASM environments. An online playground lets users try patterns without a local installation. Editor options include a VS Code extension and language-server setups for Vim and Neovim. The FAQ notes that some advanced static-analysis information is unavailable, and one rule cannot target multiple languages at once. ast-grep is distributed through several package managers and can also be built from source.
Who it is for
It suits developers who need syntax-aware search, linting, or bulk code changes across supported languages. Teams wanting advanced static-analysis information or one rule spanning multiple languages should note its stated limits.
What is good
- Searches and rewrites code using syntax-tree patterns.
- Interactive CLI previews and applies rewrites.
- Supports 20+ languages and custom language loading.
- Includes JavaScript and WebAssembly APIs.
- Offers a browser playground and editor integrations.
What to know first
- Some advanced static-analysis information is unsupported.
- A single rule cannot target multiple languages.
Everything Xiaomi review
ast-grep: the full review
ast-grep brings structural search, linting, and rewriting together in a free, open-source tool. Its language and editor support is broad, with limits around advanced analysis and cross-language rules.
ast-grep is a free, open-source tool for developers who need structural search, linting, or repeatable code changes across a codebase. It is most compelling when text search is too blunt but a full static-analysis suite would be more than the job requires.
Overview
Rather than searching source as plain text, ast-grep matches patterns against syntax-tree nodes. That helps target code by its structure, making it useful for finding and changing patterns across many files without relying on one exact formatting or spelling. The CLI can preview and apply rewrites interactively, and the project describes parallel Rust processing for searches and replacements across thousands of source files.
The boundary matters: ast-grep is not a substitute for deeper analysis of program behavior. Its FAQ acknowledges gaps in advanced static-analysis information, so teams that depend on that kind of analysis should pair it with another tool or look elsewhere.
Key features
Search, rewrite, and lint
The scan command runs configurable AST-pattern rules and assigns severities from error through hint. That gives teams a way to encode code-shape checks and surface them consistently, while the interactive rewrite flow makes broad changes easier to inspect before applying. It is a strong fit for repeatable structural refactors; it is less suited to checks that require analysis beyond syntax structure.
Custom rules and testing
Rules are written in YAML and can combine pattern, syntax-kind, regex, relational, and composite conditions. CLI commands help create and test rules, including snapshot-based tests, which makes the rule system more practical to maintain than a collection of one-off search commands. A rule cannot target multiple languages at once: use a superset language with languageGlobs or maintain separate rules for each language.
Languages and integrations
The project supports more than 20 languages and can load custom ones. Its official VS Code extension provides a CLI interface and language-server client; editor guidance also covers Vim, Neovim, and Emacs, with community integrations for other editors. The language server publishes diagnostics and code actions, though lint diagnostics require an sgconfig.yml project file.
APIs and access
A JavaScript API supports programmatic inspection and changes to syntax trees, while a WebAssembly API serves browsers and other WASM environments. The online playground lets users try patterns and rewrite rules without local installation. The CLI is distributed through npm, Cargo, Homebrew, MacPorts, Nix, and pip, and can also be built from source.
Pricing
ast-grep is free and open source, with no paid tier or trial to weigh against its core functionality. The ast-grep plan is 0.00 USD per free. That makes it an easy option to evaluate for an individual or team, though its value depends on whether structural rules meet the need without the advanced analysis it lacks.
Platforms
ast-grep is available across API, extension, Linux, macOS, web, and Windows. Its codebase indexing, regex search, code navigation, IDE extensions, and self-hosted deployment suit developers who want the tool close to their source and editor rather than as a hosted-only service.
Who it's for
Choose ast-grep when you need repeatable, language-aware searches and rewrites, custom lint rules, or a programmable way to inspect syntax trees. Security-focused teams can adapt its example rules, which include checks for a Go JSON tag vulnerability and C/C++ format-string risks. It is a less natural fit when one rule must span multiple languages or when advanced static-analysis data is essential.
Pros and cons
- Pros: Free and open source, with broad language coverage and custom-language support, so teams can apply structural rules across varied codebases without a subscription.
- Pros: Interactive rewrite previews, rule testing, editor integrations, and JavaScript and WebAssembly APIs support workflows from manual refactoring to automation.
- Cons: Rules cannot target multiple languages at once, creating extra maintenance for mixed-language codebases.
- Cons: Some advanced static-analysis information is unsupported, limiting its usefulness as a standalone analysis solution.
Alternatives
For other options, browse Code Refactoring Tools and Code Search Tools.
- CodeRush is an alternative for readers considering a paid product that also offers a free plan and lists the same features and updates across free and paid subscriptions.
- ReSharper is worth considering for readers seeking a freemium alternative with a free non-commercial plan and a free trial.
- Roslynator is another free option, with tools and extensions available free of charge.
- Sourcery may suit readers who want a freemium option with a free open-source plan for public repositories, including AI reviews and one-click fixes.
- Moderne offers a paid route with a fully managed service for readers who prefer a managed offering.
- Scalafix is a free alternative for readers considering another option from the Scala Center.
- Refrax is another free alternative.
- OpenRewrite is a free option for readers looking for a self-hosted alternative.
Verdict
Choose ast-grep if you want a free, flexible way to search, lint, and rewrite code by syntax structure across a broad range of languages. Its combination of custom rules, editor support, APIs, and interactive changes is persuasive for codebase-scale refactoring. Look elsewhere or supplement it when your work depends on advanced static analysis or a single rule spanning several languages.
ast-grep plans and pricing
All plansCompared on code search tools
- Indexing scope
- codebaseast-grep.github.io
- Deployment
- self_hostedast-grep.github.io
- Regex search
- Yesast-grep.github.io
- Code navigation
- Yesast-grep.github.io
- IDE extensions
- Yesast-grep.github.io
Facts
- Purpose
- ast-grep is a fast, polyglot tool for structural code search, linting, and rewriting at scale.ast-grep.github.io · 4 Oct 2026
- Search and rewrite
- It uses code patterns and abstract syntax trees to find and modify code across many files, with an interactive rewrite mode.ast-grep.github.io · 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 · 4 Oct 2026
- Languages
- The project says it supports 20+ languages and allows custom languages to be loaded.ast-grep.github.io · 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 · 4 Oct 2026
- Rule testing
- The CLI includes commands to create and test rules, with snapshot-based test options.ast-grep.github.io · 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 · 4 Oct 2026
- 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 · 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 · 4 Oct 2026
- Security use
- The example catalog includes rules for detecting security issues, such as a Go JSON tag vulnerability and C/C++ format string risks.ast-grep.github.io · 4 Oct 2026
- Support
- The project directs users with questions or issues to GitHub or Discord and also points to Stack Overflow and Reddit.ast-grep.github.io · 4 Oct 2026
- Limits
- The FAQ says ast-grep does not currently support some advanced static analysis information.ast-grep.github.io · 4 Oct 2026
- Publisher
- The site credits Herrington Darkholme in its copyright notice.ast-grep.github.io · 4 Oct 2026
- What it does
- ast-grep is a fast, polyglot tool for structural code search, linting, and large-scale rewriting.ast-grep.github.io · 4 Oct 2026
- Pattern search
- It matches code patterns against syntax tree nodes rather than searching source text.ast-grep.github.io · 4 Oct 2026
- Code rewriting
- The CLI can interactively preview and apply rewrites to matching code.ast-grep.github.io · 4 Oct 2026
- Lint rules
- Users can define custom lint rules with AST patterns and receive error reporting.ast-grep.github.io · 4 Oct 2026
- Language support
- The site says ast-grep supports 20+ programming languages and can load custom languages.ast-grep.github.io · 4 Oct 2026
- Performance
- The site describes search and replace across thousands of source files as powered by parallel Rust.ast-grep.github.io · 4 Oct 2026
- Programmatic API
- The JavaScript API lets programs inspect and change syntax trees using JavaScript.ast-grep.github.io · 4 Oct 2026
- Web playground
- The online playground lets users try patterns and rewrite rules without installing ast-grep locally.ast-grep.github.io · 4 Oct 2026
- VS Code
- The official VS Code extension provides a UI for the CLI and a client for the ast-grep language server.ast-grep.github.io · 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 · 4 Oct 2026
- Install methods
- The CLI is distributed through npm, Cargo, Homebrew, and MacPorts, with source builds also available.ast-grep.github.io · 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 · 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 · 4 Oct 2026
- Support channels
- The site links to Discord, Stack Overflow, and Reddit community channels.ast-grep.github.io · 4 Oct 2026
Best ast-grep alternatives
See all 12Where it ranks on Everything Xiaomi
Is ast-grep yours?
Claim it for free: prove the domain, then correct facts, plans and screenshots. An editor reviews every change.
Sources
- ast-grep.github.io· checked 4 Oct 2026
- ast-grep.github.io/reference/cli.html· checked 4 Oct 2026
- ast-grep.github.io/guide/rule-config.html· checked 4 Oct 2026
- ast-grep.github.io/guide/tools/editors· checked 4 Oct 2026
- ast-grep.github.io/guide/api-usage/js-api· checked 4 Oct 2026
- ast-grep.github.io/guide/quick-start· checked 4 Oct 2026
- ast-grep.github.io/catalog/go/unmarshal-tag-is-dash· checked 4 Oct 2026
- ast-grep.github.io/contributing/how-to.html· checked 4 Oct 2026
- ast-grep.github.io/advanced/faq· checked 4 Oct 2026
- ast-grep.github.io/reference/playground· checked 4 Oct 2026




