plugins-claude/ast-grep/skills/ast-grep/SKILL.md
Structural code search and bulk refactor via AST patterns. Use for nested expressions, calls with specific argument shapes, or syntax-shape matching where regex breaks (e.g. "replace all calls to deprecated API X"). Not for plain text search (use grep) or symbol rename (use Serena rename_symbol).
npx skillsauth add st0nefish/claude-toolkit ast-grepInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
ast-grep matches code by its AST structure, not by text. It understands syntax, so wildcards match real syntax nodes (expressions, identifiers, argument lists) rather than arbitrary text spans.
Binary: ast-grep (not sg — sg is shadowed by a system utility on Linux)
ast-grep run --pattern '<PATTERN>' --lang <LANG> [PATH...]
All three parts are required for most searches: --pattern, --lang, and a path (defaults to .).
| Flag | Short | Purpose |
|------|-------|---------|
| --pattern | -p | AST pattern to match |
| --rewrite | -r | Replacement string (uses $VAR from pattern) |
| --lang | -l | Language (required) |
| --json | | Output matches as JSON |
| --json=stream | | Output one JSON object per line (pipe-friendly) |
| --context | -C | Show N lines of context around each match |
| Wildcard | Matches |
|----------|---------|
| $VAR | Any single AST node (expression, identifier, call, etc.) |
| $$$VAR | Zero or more nodes (argument lists, statement sequences) |
| $_ | Any single node, unnamed (throwaway) |
| $$$ | Any sequence of nodes, unnamed |
Common values for --lang: python, javascript, typescript, java, kotlin, rust, go, ruby, c, cpp, bash, json, yaml.
Full list: https://ast-grep.github.io/reference/languages.html
# Find all calls to console.log with any arguments
ast-grep run --pattern 'console.log($$$ARGS)' --lang javascript src/
# Find all usages of a deprecated method
ast-grep run --pattern '$OBJ.oldMethod($$$ARGS)' --lang kotlin .
ast-grep run --pattern 'foo($X, $Y)' --lang python --json=stream src/
ast-grep run --pattern 'throw new $ERR($$$)' --lang java -C 3 src/
# Rename a function call, preserving arguments
ast-grep run --pattern 'oldFunction($$$ARGS)' --rewrite 'newFunction($$$ARGS)' --lang python .
# Add a missing argument
ast-grep run --pattern 'createUser($NAME)' --rewrite 'createUser($NAME, defaultRole)' --lang typescript src/
grep or rg (ripgrep). Faster and simpler for non-structural patterns.rename_symbol (LSP-aware, handles imports and cross-file references).find_referencing_symbols.grep/rg.Always run the search without --rewrite first to review matches, then add --rewrite once the pattern looks correct.
# Step 1: preview matches
ast-grep run --pattern 'OldApi.$METHOD($$$ARGS)' --lang java src/
# Step 2: apply rewrite
ast-grep run --pattern 'OldApi.$METHOD($$$ARGS)' --rewrite 'NewApi.$METHOD($$$ARGS)' --lang java src/
Run /ast-grep:setup to check if ast-grep is installed and print its version. Install via cargo install ast-grep --locked if missing.
development
Start work from your description — explore the codebase and plan
data-ai
Multi-phase, multi-agent feature workflow: spec → plan → refine → divide → execute → review. Invoke when the user escalates a session-start/session-issue flow to orchestration, or asks to run a non-trivial feature (multiple files, design ambiguity, cross-cutting concerns, correctness-critical paths) through the full multi-agent workflow. For small fixes, prefer session-start.
tools
Browse open issues, pick one, and start work on it
tools
Review, clean up, and open a PR to finalize the work