ast-grep

Search codebases by matching AST patterns with YAML rules.

1|Updated Jan 19, 2026
One-click install
npx skills add https://github.com/cercova-studios/terminal-agent-plugins --skill ast-grep-cercova-studios
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/cercova-studios/terminal-agent-plugins/tree/main/plugins/10x-swe/skills/ast-grep
Command: npx skills add https://github.com/cercova-studios/terminal-agent-plugins --skill ast-grep-cercova-studios

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Ast-grep helps engineers locate code patterns and language constructs by using Abstract Syntax Tree (AST) patterns rather than plain text, enabling precise, scalable searches across codebases.

Core Features & Use Cases

  • AST-based search: Write rules that match code structure (patterns, kinds) to find constructs like async functions with awaits or specific call expressions.
  • Relational and composite rules: Use inside/has/precedes/follows and all/any/not to express complex queries.
  • Test and apply rules: Validate rules against sample code and run scans against real projects to identify matches and drive refactoring or auditing.

Quick Start

  • Create a simple rule to match an async function with await by writing: language: javascript rule: kind: function_declaration has: pattern: await $EXPR stopBy: end Then run ast-grep to test the rule on 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 specific code constructs using AST patterns instead of plain text?

AST-based code search locates specific language constructs by matching structural patterns rather than exact text. You write YAML rules defining kinds, patterns, and relational constraints, then run the ast-grep CLI to find matching code across your codebase.

Can I write complex structural code queries that check relationships between code blocks?

Yes, complex structural code queries use relational rules like inside, has, precedes, and follows, combined with logical operators all, any, and not. This allows you to express deeply nested constraints and find patterns requiring structural context.

How do I write a rule to find an async function containing an await expression?

To find an async function with an await expression, write a YAML rule specifying kind: function_declaration and a has relation with pattern: await $EXPR. This matches the function declaration structurally and checks for the nested await pattern.

What is the best way to test and apply structural code search rules before scanning a large project?

The best way to test structural code search rules is to validate them against sample code snippets first. After confirming the YAML rule logic matches expected constructs, run the ast-grep CLI to scan the real project and identify matches for refactoring or auditing.

Do I need to install any dependencies to perform AST-based code searches?

No external dependencies are required to perform AST-based code searches. You only need to write YAML rules defining your structural patterns and use the ast-grep CLI tool to test and apply those rules against your codebase.

Why use structural AST search instead of regular expression text matching for code auditing?

Structural AST search outperforms regex text matching for code auditing because it understands code syntax and language constructs. It accurately locates complex patterns regardless of formatting, whitespace, or variable names, preventing false positives common in plain text searches.