hai-ast-grep
hai-ast-grep
ast-grep uses tree-sitter to parse code into AST, enabling precise pattern matching. Reach for it whenever a search or refactor depends on syntax structure: one-off searches and rewrites run straight from the CLI, reusable lint/codemod rules are written in YAML. Either way the job is not "write a pattern" — it is to ship a pattern or rule validated against a positive AND a negative case, so it catches what it should and nothing it shouldn't.
Project Configuration
One-off ast-grep run commands need no project config. Reusable project scans use sgconfig.yml
and rule directories; read references/project-setup.md only when creating or changing that setup.
Everyday CLI Usage (no rule file)
Most day-to-day search and refactor work never needs YAML or sgconfig — ast-grep run (the default subcommand) does it directly:
# Search: every fetch call site, regardless of formatting
ast-grep run -p 'fetch($URL)' -l ts src/