ast-grep

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

16|Updated Jun 6, 2026
One-click install
npx skills add https://github.com/Insik-Han/han-monorepo-template --skill ast-grep-insik-han
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/Insik-Han/han-monorepo-template/tree/main/.agents/skills/ast-grep
Command: npx skills add https://github.com/Insik-Han/han-monorepo-template --skill ast-grep-insik-han

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Structural code search is hard when relying on text patterns that ignore syntax. ast-grep translates natural language queries into AST-based rules to enable precise, structure-aware searches across codebases.

Core Features & Use Cases

  • Structural search with AST patterns that survive code reformatting.
  • Rule composition using atomic, relational, and composite rules to express complex queries.
  • Built-in guidance for testing and debugging rules against sample code and real repositories.
  • Use Case: identify all async functions that use await or locate specific language constructs across a project.

Quick Start

Write an ast-grep rule to find all async functions that use await in a JavaScript file and run the scan on the target 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 specific code structures like async functions across a codebase?

You can translate natural language queries into ast-grep rules to perform structural code search. This generates AST-based patterns that match syntax trees, enabling precise identification of constructs like async functions across a repository.

What is AST-based code search and how does it differ from text pattern matching?

AST-based code search parses syntax trees using Tree-sitter to match code structures instead of raw text. It ignores formatting variations and matches semantic constructs, allowing precise structural pattern identification across supported languages.

Does Tree-sitter support structural search for my programming language?

Tree-sitter supports structural code search across numerous programming languages. You can apply AST-based rules to any Tree-sitter-supported language to perform structure-aware searches, enabling broad codebase coverage without language-specific restrictions.

How do I write AST rules to find async functions that use await in JavaScript?

You write ast-grep rules combining atomic, relational, and composite patterns to find async functions using await in JavaScript. Relational rules must include stopBy: end to bound the search scope correctly within the target syntax tree.

Can I compose complex code search rules using relational and atomic patterns?

You can compose complex AST code search rules using atomic, relational, and composite pattern types. Relational rules define dependencies between syntax nodes and require stopBy: end, while composite rules combine multiple patterns for intricate structural queries.

Why does my ast-grep relational rule not match the expected code structure?

Relational ast-grep rules require stopBy: end to match correctly. If your rule fails, verify the relational bounds are set properly, then use the built-in testing and debugging guidance to validate the rule against sample code and real repositories.