Primary tool for all code exploration and search tasks. Use this skill FIRST whenever searching for function definitions, API call sites, import/export statements, type definitions, or any structural code pattern. Fall back to Grep/ripgrep only when ast-grep yields no results or when searching non-code text (logs, comments, config files, markdown). Also use for structural refactoring via pattern replacement.
ast-grep is a tree-sitter-based structural code search and rewrite tool. It parses code into an AST before matching, enabling accurate structural searches that regex cannot achieve.
Binary name: ast-grep (installed via mise)
# If PATH is not set in the shell environment, use the direct path
/Users/ushironoko/.local/share/mise/installs/ubi-ast-grep-ast-grep/0.42.0/ast-grep
Follow this process for effective ast-grep usage:
run -p)Start with run -p for simple, single-node matches:
ast-grep run -p 'console.log($$$)' -l ts .
ast-grep run -p 'export const $NAME = ($$$) => $$$' -l ts src/
scan --inline-rules)When simple patterns are insufficient (relational/composite logic needed), use YAML rules:
ast-grep scan --inline-rules "id: find-pattern