talira

ast-grep

A CLI tool for code structural search, lint and rewriting

open sourceMITself-hostablefree

ast-grep (sg) searches code by syntax tree pattern rather than text: you write a pattern as ordinary code with $METAVARIABLE wildcards and it matches every node with the same structure. It can rewrite matches, run YAML lint rules, and installs from npm, pip, cargo, Homebrew and others. It is written in Rust on tree-sitter.

Ways to install

Problems it solves

  • find every call to a function with a specific argument shape, regex keeps matching the wrong things
  • rewrite an API usage across thousands of files safely
  • grep cannot tell code from comments and strings
  • write custom lint rules for our codebase without writing an ESLint plugin
  • codemod that works for many languages, not just JavaScript
  • search for code patterns that span multiple lines
  • let my AI agent do structural search and replace reliably
  • enforce banned patterns in CI with simple rule files

Features

  • pattern code with metavariables
  • rewrite
  • YAML lint rules
  • many languages
  • playground
  • npm/pip/cargo installs

Capabilities

Has a command line toolplan not known

Alternatives

The same job

These do what ast-grep does.

  1. Semgrep Code security: SAST, supply chain and secrets scanning with rules that look like code
  2. ripgrep Searches directories recursively for a regex pattern, skipping gitignored files
  3. The Silver Searcher A code-searching tool similar to ack, but faster
  4. Renamify Smart search & replace for code and files with case-aware transformations and built-in undo/redo

Compare ast-grep with the top 3