Agent Skill
2/7/2026ast-grep-structural-code-search-refactoring
Find and replace code patterns structurally using ast-grep. Use when you need to match code by its AST structure (not just text), such as finding all functions with specific signatures, replacing API patterns across files, or detecting code anti-patterns that regex cannot reliably match.
V
ven0m0
0GitHub Stars
1Views
npx skills add Ven0m0/claude-config
SKILL.md
| Name | ast-grep-structural-code-search-refactoring |
| Description | Find and replace code patterns structurally using ast-grep. Use when you need to match code by its AST structure (not just text), such as finding all functions with specific signatures, replacing API patterns across files, or detecting code anti-patterns that regex cannot reliably match. |
name: ast-grep-search description: Performs structural code search and safe rewrite planning with ast-grep. Use when pattern matching must follow AST structure instead of plain text. compatibility: Designed for Claude Code allowed-tools: Read, Grep, Glob, Bash user-invocable: false
ast-grep Search and Refactor
Use this skill when
- regex/
rgmatching is too fragile - refactors need placeholder captures (
$VAR,$$$ARGS) - you need language-aware code pattern detection
Decision rule
- Literal text search ->
rg - Syntax tree structure search ->
ast-grep
Core workflow
- Define a minimal structural pattern.
- Run search scoped to target paths/language.
- Review match set before rewrite.
- Apply rewrite interactively or with update-all if safe.
- Re-run tests/lints after rewrite.
Minimal command set
# Search
ast-grep -p 'pattern' --lang ts src/
# Preview rewrite
ast-grep -p 'old($$$ARGS)' -r 'new($$$ARGS)' --lang ts src/
# Interactive rewrite
ast-grep -p 'old($$$ARGS)' -r 'new($$$ARGS)' --lang ts -i src/
# Apply all rewrites
ast-grep -p 'old($$$ARGS)' -r 'new($$$ARGS)' --lang ts -U src/
Constraints
- Always limit path scope.
- Prefer interactive mode for large rewrites.
- Never run destructive rewrites without a preview.
References
reference.mdexamples.mdrules/(ready-to-use scan rules)
Skills Info
Original Name:ast-grep-structural-code-search-refactoringAuthor:ven0m0
Download