ast-grep

Perform structural code searches with ast-grep using atomic, relational, and composite rules.

218|11|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/poteto/noodle --skill ast-grep-poteto
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/poteto/noodle/tree/main/.agents/skills/ast-grep
Command: npx skills add https://github.com/poteto/noodle --skill ast-grep-poteto

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Structural code search based on AST patterns to find relationships between code elements, not just textual matches.

Core Features & Use Cases

  • Atomic, relational, and composite rules to specify precise code queries.
  • Metavariables to capture nodes for deep analysis and refactoring.
  • Debug-friendly workflow with --stdin testing and --debug-query.

Quick Start

Create a simple rule (e.g., kind: function_declaration with a has: pattern) and run ast-grep against your codebase to observe matches.

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 structural code patterns across a large codebase?

Structural code pattern searches use ast-grep to perform Abstract Syntax Tree (AST) based matching over source code, detecting specific patterns and refactoring opportunities rather than relying on textual matches.

How do I capture specific code nodes during AST-based refactoring?

You can capture specific code nodes during AST-based refactoring by using ast-grep's metavariables. Metavariables allow you to capture specific elements within matched patterns for deep analysis and targeted refactoring across your codebase.

Can I combine multiple rules for code search to find complex relationships?

Yes, ast-grep supports atomic, relational, and composite rules for code search to specify precise queries. These rule types allow you to identify complex relationships between code elements and find specific structural patterns across large codebases.

What is the best way to debug structural search queries when matches are not working?

When structural search queries are not working, the best way to debug is by using ast-grep's built-in debugging tools. You can use the --stdin option for quick testing and the --debug-query command to fine-tune your AST pattern matches.

How does AST pattern matching differ from regular text search for static analysis?

AST pattern matching differs from regular text search by analyzing the structural relationships between code elements rather than matching exact strings. This structural approach to static analysis finds code patterns that text searches would miss due to formatting variations.

Do I need to configure composite rules to find function declarations with specific patterns?

No, you do not need composite rules to find function declarations with specific patterns. You can start with a simple atomic rule, such as specifying kind: function_declaration with a has: pattern, and run it against your codebase to observe matches.