ast-grep

Writes ast-grep rules to search codebases using Abstract Syntax Tree patterns.

Updated Dec 4, 2025
One-click install
npx skills add https://github.com/dallascrilley/dowser --skill ast-grep-dallascrilley
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/dallascrilley/dowser/tree/main/skills/ast-grep
Command: npx skills add https://github.com/dallascrilley/dowser --skill ast-grep-dallascrilley

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Text-based search tools like grep cannot understand code structure, making it hard to find patterns such as async functions missing error handling or calls inside specific contexts. This Skill translates natural language queries into ast-grep rules that match code by its AST structure. ## Core Features & Use Cases - Structural Code Search: Write YAML rules using pattern, kind, relational (inside/has), and composite (all/any/not) rules to match code by structure rather than text. - Test-Driven Rule Development: Create example code, test rules with ast-grep scan --stdin or rule files, then run verified rules across the entire codebase. - AST Debugging: Use --debug-query=cst to inspect the concrete syntax tree and find correct node kind values when rules fail to match. - Use Case: Ask to find all async functions that use await but lack try-catch blocks, and the Skill builds, tests, and runs a composite ast-grep rule across your project. ## Quick Start Ask Claude to use ast-grep to find all async functions in this project that use await but do not have try-catch error handling.

Frequently Asked Questions about ast-grep

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I search code by structure instead of text?▼

Use ast-grep, which matches code against Abstract Syntax Tree patterns rather than raw text. Write a YAML rule with pattern or kind fields, test it against example code with ast-grep scan, then run it across your codebase.

How do I write an ast-grep rule to find functions containing await?▼

Create a rule with kind set to function_declaration and a has relational rule matching the pattern await $EXPR with stopBy set to end. Test it with ast-grep scan --rule your_rule.yml against a sample file before searching the full project.

What languages does ast-grep support?▼

ast-grep supports many languages including JavaScript, TypeScript, Python, Rust, Go, Java, C, C++, Ruby, and PHP. Rules are written per language by specifying the language field in the YAML rule file.

Why is my ast-grep rule not matching any code?▼

Common causes include missing stopBy: end on relational rules, incorrect node kind values, or metavariables not being the only content in their AST node. Use --debug-query=cst to inspect the actual tree structure and simplify the rule into smaller sub-rules.

When should I use ast-grep instead of grep or ripgrep?▼

Use ast-grep when matches depend on code structure, such as calls inside class methods or functions missing try-catch blocks. Plain text search is sufficient for literal strings but cannot express relational or composite structural conditions.