ast-grep

Search codebases using AST patterns to identify language constructs.

2|1|Updated Oct 21, 2025
One-click install
npx skills add https://github.com/aldoborrero/agent-kit --skill ast-grep-aldoborrero
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/aldoborrero/agent-kit/tree/main/skills/ast-grep
Command: npx skills add https://github.com/aldoborrero/agent-kit --skill ast-grep-aldoborrero

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

AST-driven code search helps you locate code by structural patterns rather than raw text, enabling precise queries over large codebases.

Core Features & Use Cases

  • Pattern mode for simple, exact structural searches
  • Rule mode for relational and negation queries
  • Inspect mode to debug and understand AST results
  • Use cases include finding language constructs, refactoring targets, and architecture conformance

Quick Start

Ask ast_grep to search for a simple function declaration pattern in your codebase.

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 structural patterns instead of raw text?

You can search for code by structural patterns using pattern mode for exact structural searches and rule mode for relational or negation queries. This enables finding language constructs beyond simple text matching.

What is the difference between pattern mode and rule mode for AST code search?

Pattern mode handles simple, exact structural searches for language constructs, while rule mode enables relational and negation queries. Inspect mode is also available to debug and understand AST results.

Can I refine code search results using metavariables and stopBy end?

Yes, you can refine structural code search results using metavariables and the stopBy: end guidance. These features help target specific language constructs and structures within your codebase more precisely.

When do I need AST patterns for static analysis over regular text search?

AST patterns for static analysis are needed when locating refactoring targets, finding specific language constructs, or checking architecture conformance. This approach enables precise structural queries that raw text matching cannot achieve.

How do I debug AST search results to understand matched code structures?

You can debug and understand AST search results using inspect mode. This mode provides visibility into how structural patterns match your code, helping refine queries for language constructs and refactoring targets.