Favicon of ast-grep

ast-grep

CLI tool for structural code search, linting and rewriting using abstract syntax tree patterns. Search across languages, define custom rules in YAML, and automate bulk refactors.

ast-grep is a powerful CLI tool that lets you search and modify code based on its structure rather than text patterns. Using abstract syntax tree matching, it works like grep but understands code syntax, allowing you to write patterns that look like ordinary code and match all structurally identical code regardless of formatting.

Key capabilities include:

  • Structural pattern matching - Write patterns as normal code with $VARIABLE wildcards to match any AST node
  • Multi-language support - Reuse the same patterns across JavaScript, TypeScript, Python, Java, Go, Rust and more
  • Bulk refactoring - Use the --rewrite flag to automatically transform matching code at scale
  • Interactive mode - Review and approve changes before applying them
  • YAML-based linting - Define custom lint rules in configuration files without coding
  • Project organization - Centralize rules in project configs and share across teams
  • CI integration - Plug into GitHub Actions to enforce patterns automatically
  • JSON export - Pipe matches to jq or other tools for custom processing
  • Performance - Built in Rust with tree-sitter parsing and multi-core support

Perfect for library authors migrating APIs, tech leads enforcing code standards, security researchers writing detection rules, or anyone automating repetitive code changes across large repositories.

Install

Pip
$ pip install ast-grep-cli

Features

JSON outputScriptable

Media

Pros

4
  • Structural code search and linting using AST patterns.
  • Supports multiple programming languages.
  • Automates bulk refactoring tasks.
  • Customizable rules defined in YAML.

Related tools

Share:

Auto-fetched .

Recent releases

Similar to ast-grep

Favicon

 

  
 
Favicon

 

  
 
Favicon