ast-grep

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

2|Updated Nov 30, 2025
One-click install
npx skills add https://github.com/ryantking/agentctl --skill ast-grep-ryantking
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/ryantking/agentctl/tree/main/internal/templates/templates/skills/ast-grep
Command: npx skills add https://github.com/ryantking/agentctl --skill ast-grep-ryantking

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers translate natural language requests into AST-based rules for structural code search and analysis, enabling precise queries that go beyond simple text search.

Core Features & Use Cases

  • AST-based rule writing: Create rules that match code by syntax tree structure rather than textual patterns.
  • Guided workflow: Step-by-step approach from query understanding to testing rules.
  • Language-agnostic patterns: Works across languages supported by Tree-sitter and ast-grep, including JavaScript, Python, and more.
  • Use Case: Identify all async functions using await, locate code inside class methods, or extract complex structural patterns across a codebase.

Quick Start

Example: write a simple rule to find function declarations containing an await expression, test with sample code, and iterate.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I write AST-based rules for structural code search?

You can write AST-based search rules using YAML syntax to define atomic, relational, and composite constructs that match code by syntax tree structure rather than textual patterns. This enables precise structural queries across supported languages.

What is the difference between AST-based code search and regular text search?

AST-based code search matches code by syntax tree structure rather than textual patterns, allowing you to locate specific language constructs or complex structural patterns that text search cannot precisely identify across large codebases.

Does ast-grep work with Python and JavaScript for tree-sitter static analysis?

Yes, tree-sitter static analysis works across languages supported by Tree-sitter, including JavaScript and Python. You can apply YAML-based rules to locate specific language constructs or complex structural patterns across these codebases.

How do I find all async functions containing an await expression using static analysis?

You can translate this natural language query into an AST-based rule to match function declarations containing an await expression. The guided workflow helps you write the YAML rule, test it with sample code, and iterate for precise results.

Can I use natural language to generate tree-sitter rules for large codebases?

Yes, this skill translates natural language requests into AST-based rules for structural code analysis. It provides a step-by-step workflow from query understanding to testing rules, enabling precise queries across large codebases.

What are the limitations of using YAML rules for AST-based static analysis?

YAML rules for AST-based static analysis require understanding atomic, relational, and composite constructs to match syntax tree structures. You must test rules with sample code and iterate, as complex structural patterns need precise YAML definitions to avoid mismatches.