mrkeyoor.com_
Sun 25 Oct 23:13 UTC
Dev Toolsevaluationupdated 25 Oct 2026

ast-grep review

ast-grep is a CLI for structural code search, linting, and rewriting. It matches syntax-tree nodes using patterns that look like ordinary code. Its README describes YAML rules for repeatable checks and code modifications.

+53stars / 7d
Verdict

Consider ast-grep for syntax-based searches, YAML checks, and rewrites whose selection criteria fit tree structure. Establish any required semantic facts separately before changing code. Our October 16, 2026 run at commit 14934d6 recorded successful install and build steps, but did not verify an installed CLI, execute tests, or measure a rewrite workload. Start with a small representative example, inspect the proposed diff, and run the relevant project checks before expanding a migration.

We ran it

Lab card: what happened when we ran ast-grepScreenshot of ast-grep (ast-grep.github.io)
Install✓ · 237s36 packages · 88 MB
Build✓ · 1s
Testsn/ano test script
Known vulns0(pip-audit)
Repo325 files~49,032 lines of source · 3 MB · 6 CI workflows

Answers from our run

Does ast-grep build from source?

Dependencies installed in 237 seconds (36 packages), and the build succeeded in 1 seconds. We cloned commit 14934d6 into a clean Debian container with 3 CPUs and no project-specific setup.

Does ast-grep have tests you can run?

Not through a standard command: the project exposes no test script or target that our harness could run.

Does ast-grep have known vulnerabilities in its dependencies?

pip-audit found none in the dependency tree at the time of our run.

Who should not use ast-grep?

Migrations whose correctness depends on types, resolved symbols, or cross-file references unless you supply and validate the necessary external analysis. Issue 2413 proposes a shared integration API for this information; it is not documentation of an implemented semantic engine.

What are the alternatives to ast-grep?

Semgrep, Comby. Consider ast-grep for syntax-based searches, YAML checks, and rewrites whose selection criteria fit tree structure.

Setup3/5The README documents multiple installation routes. Our October 16, 2026 run at 14934d6 recorded successful 237-second install and 1-second build steps, but did not verify installed-binary availability.
Docs3/5The supplied README contains installation instructions, pattern and rewrite examples, and a YAML-rule overview. The limited documentation extract does not support a comprehensive documentation rating.
Community2/5The supplied issues contain concrete user reports and proposals. They do not establish adoption, support response times, or community breadth; this score reflects limited evidence.
Maturity3/5The README documents search, rewriting, and YAML rules, while the 0.45.3 issue report identifies a specific composition limitation. Our run supplies no test-suite or production-reliability evidence.

Discussed on

  1. hnAST-grep(sg) is a CLI tool for code structural search, lint, and rewriting292 points
  2. hnHow AST-grep Rewrote Tree-sitter in Rust and Made It 30% Faster93 points
  3. hnCode Quality at Scale with AST Grep and LLMs13 points
  4. hnShow HN: AST-grep, a grep/eslint/codemod hybrid tool, powered by tree-sitter.11 points
  5. hnast-grep: A CLI tool for code structural search, lint and rewriting6 points

Who it’s for

Developers evaluating source-shaped patterns for API migrations.
Teams that want to express custom lint checks and fixes in YAML.
Library maintainers whose breaking changes can be described through syntax patterns.

Who it’s NOT for

Migrations whose correctness depends on types, resolved symbols, or cross-file references unless you supply and validate the necessary external analysis. Issue 2413 proposes a shared integration API for this information; it is not documentation of an implemented semantic engine.
Integrations that require inline rules to resolve project utilities without checking their chosen version. Issue 2927 reports this failing in 0.45.3 on macOS arm64.
Evaluators who need this review to establish installed CLI behavior, rewrite correctness, test-suite results, or dependency safety. Our recorded run establishes none of those.

Setup reality

In our recorded run on October 16, 2026, at commit 14934d690a547abce8576baff9a1856a10ae7da8, the harness reported a successful install step taking 237 seconds and a successful build step taking 1 second. It recorded 36 dependency packages and 88 MB. These are rounded step timings, not a CLI performance benchmark.

The raw install tail only identifies a Python 3.12.12 environment, and the build tail is empty. The record does not establish which project artifact was built, whether an ast-grep binary was installed, or whether that binary ran. Tests were skipped with the reason "no script". That describes harness discovery, not the absence of upstream tests.

The pip-audit summary records zero advisories, but its package field is zero and usable coverage is unknown. It does not establish that the 36 dependency packages were audited or that the product is safe.

Separately, the README lists npm, pip, Cargo, cargo-binstall, Homebrew, Scoop, mise, and MacPorts installation routes. It says source installation requires rustup and notes that pnpm may require pnpm approve-builds. Those are upstream instructions, not routes verified by our run.

Choose it when syntax describes the change

ast-grep lets you express a code search in the language you are searching. The README says it matches AST nodes rather than text and uses tree-sitter for parsing. Uppercase placeholders such as $MATCH stand for individual nodes.

The README includes the pattern $A && $A() and this rewrite command:

ast-grep -p '$A && $A()' -l ts -r '$A?.()'

This is an upstream example, not a command executed in our recorded run. It illustrates how a pattern and replacement share a placeholder. Before applying a similar rewrite, check both which code it selects and whether the replacement preserves the behavior your project needs. A syntactic match alone does not establish behavioral equivalence.

The README also describes YAML configuration for lint rules and code modifications. That makes ast-grep worth evaluating when a team wants to reuse a syntax-based check instead of repeating a one-off search. Claims about parallel execution come from the README; we did not measure search throughput or rewriting speed.

Check semantic requirements and rule composition

A source-shaped pattern does not establish an identifier's resolved symbol, inferred type, or cross-file relationships. Issue 2413 is a proposal for a pluggable semantic-analysis API. Its author reports that ast-grep has no structured way to attach semantic information to AST nodes and describes using external analyzers. Treat the proposed APIs in that issue as design examples, not available features. The issue does not establish version-specific behavior for 0.45.3.

For a migration, write down what determines whether a call should change. If the answer includes its resolved import or inferred type, obtain that information through suitable analysis and validate the integration before applying the rewrite.

Rule composition has a separate reported limitation. Issue 2927 describes ast-grep 0.45.3 on macOS arm64: a file-based rule referencing a global utility passes the reporter's ast-grep test, while the same rule supplied through scan --inline-rules fails to resolve that utility from utilDirs, including with an explicit configuration. This is the reporter's reproduction, not our test result or proof that every later version behaves the same way. An editor integration that generates inline rules should check this exact workflow in its chosen version.

What our recorded run establishes

In our run on October 16, 2026, the checkout was commit 14934d690a547abce8576baff9a1856a10ae7da8. The recorded environment had 3 CPUs, 8 GB of memory, and image ghcr.io/astral-sh/uv:python3.12-bookworm. The install tail identifies Python 3.12.12. Detection found Python and Rust and selected Python as the primary ecosystem.

Recorded item Result Limit
Install step Exit 0; 236,863 ms, rounded to 237 seconds The tail only identifies the Python environment; installed CLI availability was not checked
Build step Exit 0; 908 ms, rounded to 1 second Empty output tail; the resulting artifact is not established
Dependencies 36 packages; 88 MB Not an audited-package count
Tests Skipped; reason: no script No test-suite result; does not show that upstream has no tests
pip-audit Recorded advisory total: 0; package field: 0 Usable audit coverage is unknown
Checkout 325 files; approximately 49,032 lines; 3 MB Repository inventory, not workload performance

The detector recorded six CI workflows and did not detect a Dockerfile, Compose configuration, or top-level tests directory. These are discovery results, not a complete inventory of checks or deployment options. Recorded parser summaries were not reconciled against complete logs to establish exhaustive coverage.

No installed-binary check, search workload, rewrite workload, or upstream test execution appears in the supplied record. The successful step statuses therefore support a narrower conclusion than a verified source build or working CLI installation. The zero-advisory summary also cannot support a dependency-safety verdict because audit coverage is unknown.

Installation instructions and the next useful check

The README lists npm, pip, Cargo, cargo-binstall, Homebrew, Scoop, mise, and MacPorts. For a source installation it specifies rustup and cargo install --path ./crates/cli --locked. It also notes that pnpm may require pnpm approve-builds. We did not verify those individual routes.

Choose the route that fits your environment, confirm that the installed ast-grep command runs, and try a representative pattern before committing to a repository-wide migration. Review the matches and diff, then run the application's relevant checks. Those steps resolve the practical questions left open by our harness record.

When to consider Semgrep or Comby

Semgrep's README describes code scanning, bug finding, and coding-standard enforcement. It separately describes an AppSec Platform with result triaging and exploration workflows. Consider that product family when security findings and their handling drive the evaluation. Keep the editions distinct: the README warns that Community Edition can only analyze within a single function or file. We did not compare detection rates, speed, or cost.

Comby's README demonstrates matching nested C-like conditions with if (:[condition]), replacing them with if (1), and using interactive review. Consider it when that template approach fits your change. The supplied evidence does not establish a language-coverage or performance advantage over ast-grep.

How to read the scores

These are editorial assessments of the supplied evidence, not benchmark results. The rubric is: 1 means substantial documented obstacles; 2 means evidence is too limited for a confident recommendation; 3 means a documented route with material checks left open; 4 means detailed supporting evidence with bounded gaps; 5 requires broad, directly verified evidence. Missing evidence is uncertainty, not proof of a product defect. Community and maturity scores do not measure adoption or production reliability.

Alternatives

ProjectWhat it isPick it when
SemgrepA static-analysis tool for code searches, bug finding, and coding standards, with a separate AppSec Platform.Consider it when security scanning and findings workflows are central. Its README describes platform triage workflows and warns that Community Edition analysis is limited to a single function or file. This review does not benchmark its detection quality.
CombyA matching and rewriting tool with templates and interactive review.Consider it when a language-aware template expresses the edit you need. Its README demonstrates matching nested C-like conditions with `if (:[condition])` and replacing them with `if (1)`.

What people are saying

  1. [github-trending] ast-grep/ast-grep

Sources

  1. ast-grep repository and README
  2. ast-grep documentation
  3. ast-grep 0.45.3 release
  4. Issue 2927: inline rules do not bind global utilities
  5. Issue 2413: proposed semantic analysis API
  6. Issue 56: sg command deprecation

More dev tools reviews

thinkrail · firebase-tools · brotli · agentskills · hallmark · ds-harness-remote · the whole board →