sg

Installation
SKILL.md

ast-grep (sg)

Searches code by AST structure, not text. Patterns must be valid parseable code with $VAR meta-variables for wildcards.

Basic Search

ast-grep run -l ts --pattern 'console.log($X)' src/
ast-grep run --pattern '$FUNC()' agent/extensions/   # Auto-detect language

Pattern Syntax

  • $VAR — matches a single AST node (uppercase only: $MOD, $_)
  • $$$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, bare from $X fails

Common Patterns

Installs
5
Repository
knoopx/pi
GitHub Stars
59
First Seen
May 24, 2026
sg — knoopx/pi