← ClaudeAtlas

code-ast-greplisted

Use ast-grep (sg) for semantic, syntax-aware code searching. Prefer over Grep for code pattern searches that depend on structure rather than text matching. Use when searching for function calls, class definitions, import statements, or any pattern where syntax context matters.
tstapler/dotfiles · ★ 8 · Data & Documents · score 59
Install: claude install-skill tstapler/dotfiles
# ast-grep: Semantic Code Search Use `ast-grep` (command: `sg`) for structure-aware code searching. Unlike `Grep` (text search), ast-grep understands syntax and finds patterns by their role in the code, not their textual form. ## When to Use ast-grep vs Grep | Use `ast-grep` | Use `Grep` | |----------------|------------| | Find all calls to a function | Find a string in any file | | Find class definitions | Search logs or text files | | Find import statements for a module | Find TODO comments | | Find all uses of a decorator | Search non-code files (YAML, MD) | | Find arrow functions vs regular functions | Quick text pattern in known file | | Search within specific code constructs | Simple identifier search | ## Installation ```bash brew install ast-grep ``` Verify: `ast-grep --version` or `sg --version` ## Core Usage ### Basic Pattern Search ```bash # Find pattern in current directory sg --pattern '<pattern>' --lang <language> # Search specific directory sg --pattern '<pattern>' --lang <language> <path> # Show context lines sg --pattern '<pattern>' --lang <language> -A 2 -B 2 ``` ### Language Flag Reference | Language | Flag | |----------|------| | Python | `--lang python` | | JavaScript | `--lang javascript` | | TypeScript | `--lang typescript` | | Java | `--lang java` | | Kotlin | `--lang kotlin` | | Rust | `--lang rust` | | Go | `--lang go` | ## Pattern Syntax ### Metavariables - `$NAME` — matches any single node (expression, identifier, etc.) - `$$$NAME`