ast-grep

Search and refactor source code using AST-aware structural pattern matching.

26|2|Updated Apr 23, 2026
One-click install
npx skills add https://github.com/aryaniyaps/ultimate-pi --skill ast-grep-aryaniyaps
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/aryaniyaps/ultimate-pi/tree/main/.pi/skills/ast-grep
Command: npx skills add https://github.com/aryaniyaps/ultimate-pi --skill ast-grep-aryaniyaps

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @ast-grep/cli, and includes scripts (resource) components.

What problem does it solve?

It enables precise code exploration by searching for patterns based on code structure rather than plain text, enhancing accuracy in identifying code components.

Core Features & Use Cases

  • Pattern-based code search: Find function calls, definitions, imports, and classes accurately using AST-aware syntax.
  • Code refactoring and codemods: Perform safe, structural rewrites across projects with pattern matching and replacements.
  • Use Case: Locate all instances of deprecated API usage in a codebase and replace them automatically.

Quick Start

Use the sg command to find all function calls to fetch in your JavaScript project.

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

Structural code search using AST patterns matches source code based on its syntactic structure rather than exact text, enabling precise identification of function calls, definitions, imports, and classes across your project files.

How do I refactor deprecated API usage and replace function calls automatically?

You can perform safe structural rewrites across projects by applying pattern matching and replacements, enabling you to locate all instances of deprecated API usage in a codebase and replace them automatically.

Does structural code search require Node.js to run the AST pattern matching?

Yes, structural code search requires Node.js and the @ast-grep/cli package for CLI execution to facilitate precise code exploration and automated transformations in your software engineering workflows.

What is the best way to find all function calls in a JavaScript project?

Using the sg command with AST-aware syntax is an effective way to find all function calls to specific APIs like fetch in a JavaScript project, ensuring accurate pattern detection without false positives from text matching.

Why use AST pattern matching instead of regex for code refactoring and codemods?

AST pattern matching distinguishes itself by understanding code structure, preventing false positives that regex encounters, and allowing safe automated transformations across large codebases without risking unrelated text replacements.

What are the limitations of structural code search for pattern detection?

Structural code search is limited to source code files that can be parsed into an AST, meaning it may not apply to non-code text formats and requires the specific syntax of the target language to be supported by the CLI.