ast-grep

Translate natural language queries into ast-grep rules for structural code search.

Updated Oct 27, 2025
One-click install
npx skills add https://github.com/SomtoUgeh/dotfiles --skill ast-grep-somtougeh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/SomtoUgeh/dotfiles/tree/main/claude/skills/ast-grep
Command: npx skills add https://github.com/SomtoUgeh/dotfiles --skill ast-grep-somtougeh

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill enables developers to translate natural language queries into ast-grep rules for structural code search, allowing precise matching based on code structure rather than textual content.

Core Features & Use Cases

  • Rule creation: Define atomic, relational, and composite rules to match language constructs by AST.
  • Codebase search: Locate functions, calls, and patterns across large codebases using AST patterns.
  • Testing & debugging: Use inline tests and debugging options to validate rules against sample code and inspect ASTs.
  • Use Case: Find all async functions that contain await expressions within a given project to audit async patterns.

Quick Start

Install the ast-grep CLI and ensure it is on your PATH. Write a simple rule file (e.g., test_rule.yml) using a basic pattern. Run a search against a repository with ast-grep scan --rule test_rule.yml /path/to/project.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I search for code by AST structure instead of plain text?

Structure-aware code search uses AST patterns to locate code based on its structural syntax rather than exact textual matches. This allows precise matching of language constructs like functions and calls across large codebases.

What is the best way to find all async functions containing await expressions in a project?

You can find specific patterns like async functions containing await expressions by defining structural rules using metavariables. This translates natural language queries into AST rules for auditing codebase patterns.

How do I write and test rules for tree-sitter based structural code search?

To write and test rules, define atomic, relational, or composite rules in a YAML file and run it against your project. Use inline tests and debugging options to validate rules against sample code and inspect ASTs.

Does structure-based search work for codebases in any programming language?

Structure-based search applies to codebases in any language where you need to locate code by AST structure. It leverages tree-sitter to support specific language constructs across various programming environments.

When should I use AST patterns over standard static analysis tools?

Use AST patterns when you need to locate code by specific language constructs or structural relationships rather than predefined linting rules. It excels at translating natural language queries into custom structural search rules.