
ast-grep
github.com/ast-grep/ast-grep- Category
- Developer Tools
- Rank
- No. 39Tools index
- Pricing
- Open Source
- Platform
- cli
- Type
- TOOL
- Builder
- ast-grep
- GitHub
- 15.6k stars
- Latest release
- 0.45.1
- Added
- Jul 4, 2026
About
ast-grep is a fast, polyglot CLI tool for structural code search, linting, and rewriting based on abstract syntax trees (AST). Unlike text-based grep, it understands code syntax, letting you find and transform patterns across thousands of files using intuitive code-like patterns. It supports 20+ languages and can be used as a CLI, a Node.js library, or integrated into linting workflows.
What it does
You describe a code shape using ordinary-looking source, with uppercase dollar variables standing for syntax nodes. ast-grep parses that shape and target files with tree-sitter, then finds matching structures, reports them, or substitutes captured nodes into a replacement. YAML rules extend the same model to repeatable checks and fixes.
Why it's ranked here
ast-grep combines an approachable query model with unusually broad workflow coverage. The same engine supports one-off migrations, project rules, rule tests, editor diagnostics, fixes, and programmatic Node use. Its compiled Rust core, parallel file walking, structured output, and explicit match strictness make it credible for repository-scale automation.
What's good
Patterns resemble the code engineers already read, while named wildcards capture reusable syntax pieces. Searches can infer language from files, inspect injected sublanguages, filter with globs, emit JSON, or preview changes interactively. Configured rules have scaffolding, tests, generated schemas, diagnostics, hover notes, quick fixes, and fix-all editor actions.
Tradeoffs
The friendly pattern syntax still requires AST concepts such as node kinds, selectors, strictness, and language-specific parsing. Distribution relies on native binaries, so npm installation recognizes only listed operating-system and architecture combinations, with no musl CLI package selected there. The Python package also wraps the compiled command rather than exposing a Python library API.
How to use it well
Use it for codemods, custom repository conventions, security-oriented structural checks, and migrations that plain text matching would make fragile. Start in the playground or with a single pattern, inspect results, then promote stable checks into YAML rules with tests. Treat it as lightweight structural analysis, not evidence of full type-aware semantic analysis.
Technical notes+
Cargo.toml defines a Rust workspace spanning crates/* plus xtask, enables release LTO, and centralizes tree-sitter, configuration, language, LSP, and outline crates. crates/cli/src/lib.rs exposes run, scan, test, new, lsp, outline, and completions subcommands; crates/cli/src/run.rs uses parallel ignore-based walking, language inference, injected-language matchers, several strictness modes, interactive rewriting, and JSON output. crates/lsp/src/lib.rs keeps parsed documents in a DashMap, publishes diagnostics, reloads watched YAML rules, and supplies hover and code actions over full-document synchronization. crates/napi/index.d.ts exports parsing, pattern, file-search, dynamic-language, node, and root APIs, while crates/napi/index.js loads platform-specific native bindings. npm/postinstall.js selects and installs CLI binaries for supported targets. pyproject.toml packages the CLI through maturin. xtask/src/schema.rs generates general and language-specific JSON schemas from rule configuration types and tree-sitter node metadata.
Observed
- License
- MIT
- Primary implementation language
- Rust
- Install surfaces
- npm, pip, Cargo, cargo-binstall, Homebrew, Scoop, Nix, mise, and MacPorts are documented.
- Interfaces
- Command-line tool, Node.js native library, and language server.
- CLI commands
- Run, scan, test, new, language server, outline, and shell completions.
- Native CLI targets selected by npm
- macOS arm64 and x64; Linux GNU arm64 and x64; Windows arm64, ia32, and x64.
- Configuration format
- YAML rules and project configuration, with generated JSON schemas.
Read from README.md, Cargo.toml, pyproject.toml, npm/postinstall.js, xtask/src/main.rs, xtask/src/schema.rs, crates/napi/index.js, crates/napi/build.rs, crates/napi/index.d.ts, crates/cli/src/lib.rs, crates/lsp/src/lib.rs, crates/cli/src/lsp.rs, crates/cli/src/new.rs, crates/cli/src/run.rs, crates/cli/src/main.rs.
What it can do
Search for structural code patterns across a codebase
Code pattern with wildcards and a target codebase → List of matching code locations across files
Rewrite or refactor code patterns at scale
Source code pattern and replacement pattern → Transformed source files with pattern replaced
Lint code using custom structural rules
YAML-based lint rules and source code files → Lint warnings and errors for matched anti-patterns
Parse and traverse abstract syntax trees programmatically
Source code file or snippet via Node.js API → Traversable AST nodes with jQuery-like navigation
Search for code patterns across 20+ programming languages
A code pattern and polyglot codebase → Language-aware matches respecting each language's syntax
Identify and fix structural code issues via CLI
CLI command with pattern or rule file and target directory → Console report of matches or auto-fixed source files
Integrate structural lint rules into CI/CD workflows
YAML rule definitions and source code repository → Pass/fail lint results suitable for automated pipelines
Intel on ast-grep
Tags
Tech Stack
Comments (0)
No comments yet
Indexed by a proprietary survey. Corrections welcome.