ast-grep

Web · Windows · Mac · Linux · API · Extension

Freedom report

Three barsScore 6.7

  • Free tierA free tier is on its own pricing page
  • Open codeNo open-source code on record
  • Runs widely4 of 6 device platforms
  • DocumentedPlans, terms and facts published

ast-grep is a free, open-source tool for searching, linting, and rewriting code by its structure. It matches patterns against syntax-tree nodes rather than plain text, which lets developers target code across a codebase. Its CLI can preview and apply changes interactively, and scan configurable YAML rules with error, warning, info, or hint severity. Rules can combine pattern, kind, regex, relational, and composite conditions; commands are available for creating and testing rules, including snapshot-based tests. The project says it supports more than 20 languages and can load custom languages. Programs can inspect or change syntax trees through its JavaScript API, while a WebAssembly API supports browsers and other WASM environments. An online playground lets users try patterns without installing the tool. Editor options include a VS Code extension and language-server setups for editors including Vim, Neovim, and Emacs. The CLI is available through several package managers or as a source build. The FAQ notes gaps in advanced static analysis and that a rule cannot target multiple languages at once.

Who it is for

It suits developers who need structural search, custom lint rules, or large-scale code rewrites across supported languages. It also offers API and editor integration options for developers who want to use it from programs or their editor.

What is good

  • Searches and rewrites code by syntax-tree pattern.
  • Interactive CLI previews rewrites before applying them.
  • Supports 20+ languages and custom language loading.
  • Rule tests can use snapshots.
  • Online playground works without local installation.

What to know first

  • Some advanced static-analysis information is unsupported.
  • A rule cannot target multiple languages at once.

Freedom251 review

ast-grep: the full review

ast-grep combines structural code search, configurable linting, and rewriting in a free, open-source tool. Its language coverage and integrations are broad, though it does not provide some advanced static-analysis information and rules are limited to one language at a time.

ast-grep is a free, open-source tool for developers who need to search, lint, and rewrite code by its structure rather than by raw text. It is a strong fit for repeatable, codebase-wide changes; teams that rely on deeper static analysis should look elsewhere or pair it with another tool.

Overview

ast-grep matches patterns against syntax-tree nodes, which helps distinguish code by its shape instead of matching every textual occurrence. That makes it useful for locating and changing recurring constructs across many files. Its CLI can preview and apply rewrites interactively, and the project describes parallel Rust processing for work across thousands of source files.

The breadth comes with a boundary: the FAQ says some advanced static-analysis information is not supported. Structural rules can identify code patterns, but ast-grep is not the right choice when a task depends on that deeper analysis.

Key features

Search, rewriting, and linting

The scan command runs configurable AST-pattern rules and reports severities including error, warning, info, and hint. This gives teams a way to turn code-shape conventions into checks, while interactive previews help review broad changes before applying them. It is particularly suited to repeatable refactors and targeted linting, not checks that require unsupported analysis.

Custom rules and testing

Rules are written in YAML and can combine pattern, kind, regex, relational, and composite conditions. The CLI includes commands to create and test rules, with snapshot-based test options. That combination is useful for teams maintaining reusable checks: rules can express more than a single text match and can be tested as part of their workflow.

A rule cannot target multiple languages at once. For mixed-language repositories, that means maintaining separate rules or using a superset language with languageGlobs, as the FAQ recommends. That extra organization is a real cost for teams hoping to write one rule for every language.

Languages, editors, and APIs

The project says it supports more than 20 languages and allows custom languages to be loaded. The online playground lets users try patterns and rewrite rules without installing the tool. Editor support includes an official VS Code extension and language-server integrations; the editor guide also documents Neovim and Emacs setups, alongside community integrations. The language server publishes diagnostics and supports diagnostic code actions, though linting diagnostics require an sgconfig.yml project file.

For programmatic use, the JavaScript API can inspect and change syntax trees, while the WebAssembly API supports browsers and other WASM environments. These interfaces make ast-grep relevant beyond command-line use, but they do not remove its analysis limits.

Pricing

ast-grep is open source and free, with no free trial because no paid trial is offered. The ast-grep plan is 0.00 USD per free. There are no paid tiers or seat-based plan distinctions in this offering, so teams can use the same tool without choosing a higher subscription to access its core capabilities.

Platforms

ast-grep is available across Linux, macOS, and Windows, as well as through API, extension, and web experiences. The CLI is distributed through npm, Cargo, Homebrew, MacPorts, Nix, and pip, with source builds also possible. Its self-hosted deployment model suits teams that want to run code search and linting within their own environment; the browser playground offers a way to explore rules without a local installation.

Who it's for

Choose ast-grep if you need structural search, configurable lint rules, or large-scale code rewrites across a codebase, especially when you want to define and test your own rules. Its language coverage and editor options also make it relevant to developers working across different languages and environments. It is a weaker fit when one rule must cover multiple languages or when the task requires advanced static-analysis information.

For questions and issues, the project directs users to GitHub and Discord, and also points to Stack Overflow and Reddit. That community-oriented support suits users comfortable resolving questions through public channels.

Pros and cons

  • Pros: Structural matching targets syntax-tree nodes, making it more precise for code-shaped searches and rewrites than raw text matching.
  • Pros: YAML rules, rule-testing commands, and multiple severity levels support reusable lint checks.
  • Pros: More than 20 supported languages, custom language loading, editor integrations, and JavaScript and WebAssembly APIs give it several routes into a workflow.
  • Cons: Some advanced static-analysis information is unsupported, limiting its use for checks that depend on it.
  • Cons: Rules target one language at a time, so mixed-language projects may need separate rules or a superset-language setup.
  • Cons: Linting diagnostics through the language server require an sgconfig.yml project file.

Alternatives

For a broader starting point, browse Code Refactoring Tools or Code Search Tools.

  • CodeRush is an alternative to consider for its editor-extension offering; it provides all versions free for commercial use, with the same features and updates across free and paid subscriptions.
  • ReSharper is worth considering for non-commercial C# work in VS Code and compatible editors through its free non-commercial plan, or for readers seeking its separate paid plan.
  • Roslynator is another free option, with tools and extensions available at no charge.
  • Sourcery may suit readers looking for a free open-source plan centered on public repositories, AI reviews, PR summaries and diagrams, one-click fixes, and custom review rules.
  • Moderne is an option for readers seeking a managed service, including managed backpatch service and dedicated FTEs in its Fully Managed Service plan.
  • Refrax is another free alternative.
  • Scalafix is another free alternative, from the Scala Center, which focuses on open source and education.
  • Coccinelle is another free alternative.

Verdict

Choose ast-grep if your priority is reusable, syntax-aware search, linting, and rewriting across a codebase without a subscription. Its broad language and integration support strengthens the case, but the one-language-per-rule constraint and gaps in advanced static analysis are reasons to look elsewhere when those capabilities are central.

ast-grep plans and pricing

All plans
ast-grep Free Pricing not stated on the opened official pages ast-grep.github.io · 4 Oct 2026

Compared on code search tools

Indexing scope
codebase
Deployment
self_hosted
Regex search
Yes
Code navigation
Yes
IDE extensions
Yes

Best ast-grep alternatives

See all 12