ast-grep
Installation
SKILL.md
ast-grep (ast-grep or sg) searches code by AST structure, not text. Patterns must be valid parseable code with $VAR meta-variables for wildcards.
Core Commands
# Search with pattern
ast-grep run -l ts --pattern 'console.log($X)' src/
# Search in directory (auto-detects language)
ast-grep run --pattern '$FUNC()' agent/extensions/
Pattern Syntax
$VAR— matches single AST node (uppercase only:$MOD,$_,$_123)$$$VAR— matches zero or more nodes (function args, statements)$_VAR— non-capturing (same name can match different content)- Patterns must be valid code:
import { $X } from "$Y"works,from $Xfails