ast-grep

Match code patterns by AST structure instead of raw text.

1|Updated Mar 19, 2026
One-click install
npx skills add https://github.com/ian-pascoe/dotfiles-chezmoi --skill ast-grep-ian-pascoe
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/ian-pascoe/dotfiles-chezmoi/tree/main/dot_agents/skills/ast-grep
Command: npx skills add https://github.com/ian-pascoe/dotfiles-chezmoi --skill ast-grep-ian-pascoe

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you express code searches as structural AST patterns instead of brittle text matches, so you can find precise code constructs across a repository.

Core Features & Use Cases

  • Structural Code Search: Translate natural language ideas into ast-grep rules that match syntax trees rather than raw strings.
  • Complex Query Building: Combine patterns, node kinds, relational checks, and logical operators to find code with specific shapes or context.
  • Rule Debugging and Testing: Use example snippets and AST inspection guidance to validate searches before running them on a real codebase.
  • Use Cases: Locate async functions that use await, find console logging inside class methods, or detect code that matches a forbidden structural pattern.

Quick Start

Ask for an ast-grep rule that finds a specific code structure in your target language and explain any constraints you want included or excluded.

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

To search code by structure, you match abstract syntax tree (AST) patterns rather than raw strings. This approach uses language-aware rules to find precise code constructs across a repository, ignoring formatting and variable names.

What is the best way to find async functions that use await in a repository?

The best way to find async functions using await is structural code search. You translate the natural language idea into ast-grep rules that match the syntax tree shape, allowing you to locate specific constructs across supported programming languages.

Can I combine multiple rules and relational checks for complex code matching?

Yes, you can combine multiple rules for complex code matching. Structural search supports combining patterns, node kinds, relational checks, and logical operators to find code with specific shapes or contextual constraints.

Does structural code search work across different programming languages?

Structural code search works across supported programming languages by matching AST structure. It applies language-aware rules to find precise code constructs, requiring specific node kinds and metavariables to ensure reliable matches in each language.

How do I debug and test AST rules before running them on a real codebase?

To debug AST rules before running them, you use example snippets and AST inspection guidance. This allows you to validate searches and ensure the structural patterns, constraints, and stopBy settings produce reliable matches safely.