ast-grep

Translates structural search requests into ast-grep rules for AST pattern matching in JavaScript and Python.

1|Updated Jun 27, 2026
One-click install
npx skills add https://github.com/babually/bongo-template --skill ast-grep-babually
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/babually/bongo-template/tree/main/.agents/skills/ast-grep
Command: npx skills add https://github.com/babually/bongo-template --skill ast-grep-babually

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you locate and analyze code based on its AST structure, which is far more precise than plain text search when you need to find specific language constructs or patterns across a codebase.

Core Features & Use Cases

  • Structural Code Search: Search for functions, calls, classes, and other syntax patterns by tree shape instead of exact strings.
  • Rule Authoring Workflow: Translate a natural-language query into an ast-grep rule, test it on examples, and then run it against real repositories.
  • Advanced Querying: Use relational and composite rules to find nested code patterns, missing constructs, or context-specific matches such as async functions with await or logs inside methods.

Quick Start

Ask for an ast-grep rule that finds the code pattern you want, and include the target language and any must-have or must-not-have structural constraints.

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 patterns by structure instead of plain text?

Structural code search matches syntax tree shapes rather than exact strings, letting you locate functions, calls, or classes across a repository. This approach requires translating structural constraints into rules to find precise matches.

Can I find nested code constructs like async functions containing await statements?

Yes, you can locate nested code constructs by using relational and composite rules. Applying semantics like has, inside, and all enables detection of context-specific matches such as logs inside methods or await inside async functions.

Does structural code search work with Python and JavaScript source code?

Structural code search works with JavaScript, Python, and other supported languages for repository-wide analysis. It applies language-specific querying to detect nested constructs or missing syntax by matching AST patterns.

What is the best way to translate natural language queries into AST rules?

Translating natural-language queries into AST rules involves defining the target language and structural constraints. The rule authoring workflow generates the rule, tests it on examples, and runs it against repositories to verify precise matches.

How do I match missing syntax constructs in a codebase?

To match missing syntax constructs, you use the not and stopBy semantics within composite rules. This allows structural code search to identify context-specific absences, such as methods lacking specific calls, across the repository.

Why use AST structural matching instead of regular expressions for source code analysis?

AST structural matching is far more precise than regular expressions for source code analysis because it understands tree shapes. It avoids false positives from text matching by targeting actual language constructs across the codebase.