ast-grep

Search and validate code patterns using Tree-sitter structural queries.

16|1|Updated Jan 2, 2026
One-click install
npx skills add https://github.com/bahayonghang/my-ai-cli-toolkit --skill ast-grep-bahayonghang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/bahayonghang/my-ai-cli-toolkit/tree/main/skills/developer-tools-integrations/ast-grep
Command: npx skills add https://github.com/bahayonghang/my-ai-cli-toolkit --skill ast-grep-bahayonghang

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill solves the limitation of traditional text-based search tools by enabling syntax-aware code analysis, allowing you to find and validate code patterns based on their structural shape rather than just character matches.

Core Features & Use Cases

  • Structural Pattern Matching: Search for code based on AST nodes like function declarations, decorators, or specific call contexts.
  • Rule Validation: Create and test YAML-based search rules against local fixtures to ensure accuracy before running them on large codebases.
  • Use Case: Use this to identify all instances of a specific function call that occur inside a try-catch block, or to find all arrow functions that lack a specific error handling pattern.

Quick Start

Use the ast-grep skill to find all arrow functions containing an await expression in the current directory.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
What is structural code search and how does it differ from text-based search?

Structural code search matches syntax-aware AST nodes like function declarations or call contexts rather than character strings. It enables you to find code patterns based on their structural shape, overcoming limitations of traditional text-based search tools.

How do I find arrow functions containing an await expression in my repository?

To find arrow functions with await expressions, use the ast-grep skill to execute structural queries. It leverages Tree-sitter grammars to perform syntax-aware pattern matching, allowing you to target specific code structures across multi-language repositories.

Can I test structural search rules locally before running them on a large codebase?

Yes, you can create and validate YAML-based search rules against local fixtures. This rule validation ensures your syntax-aware patterns are accurate and safe before executing structural queries across large multi-language repositories.

Does ast-grep work with Tree-sitter grammars for multi-language static analysis?

ast-grep uses Tree-sitter grammars to perform syntax-aware structural code search across multi-language repositories. It targets complex refactoring discovery and static analysis tasks by validating code patterns against defined YAML rules.

What's the best way to identify specific function calls inside a try-catch block?

The best way to identify specific function calls inside try-catch blocks is using structural pattern matching. By defining YAML rules, you can search for code based on AST nodes and specific call contexts to pinpoint exact structural shapes.

Do I need the ast-grep CLI tool to perform structural code auditing?

Yes, the ast-grep CLI tool is required to execute structural queries and validate code patterns. The skill relies on this CLI to perform syntax-aware static analysis and rule validation against your local codebase.