ast-grep-api

Parse, search, and rewrite source code via AST across multiple languages.

1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/hafley66/claude-research --skill ast-grep-api
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep-api
Source: https://github.com/hafley66/claude-research/tree/main/skills/ast-grep-api
Command: npx skills add https://github.com/hafley66/claude-research --skill ast-grep-api

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides programmatic access to AST-based tooling across Rust crates, Node.js NAPI, and Python bindings for parsing, searching, and rewriting code.

Core Features & Use Cases

  • Parse source into AST using Rust crates, Node.js NAPI, or Python bindings
  • Search for structural patterns with metavariable capture
  • Extract matched node text and byte offsets
  • Apply code rewrites
  • Load and run YAML rule configs programmatically

Quick Start

Invoke the AST API to parse code, search for patterns with metavariables, and apply a rewrite using YAML rule configs.

Frequently Asked Questions about ast-grep-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I search for structural code patterns across multiple languages?

To search code structurally across multiple languages, you parse source code into an AST and use metavariable captures to match specific nodes. This enables precise structural querying and code analysis across different programming languages.

How do I apply automated code refactoring using YAML rule configs?

Automated code refactoring is applied by loading and running YAML rule configs programmatically. The system parses the AST, matches patterns defined in the YAML, and executes rewrites to transform the source code automatically.

Does ast-grep work with Rust, Node.js, and Python for code analysis?

Yes, ast-grep supports code analysis by providing programmatic AST tooling via Rust crates, Node.js NAPI, and Python bindings, allowing you to parse, search, and rewrite source code natively across these three environments.

Can I extract matched node text and byte offsets during AST parsing?

Yes, during AST parsing you can extract matched node text and byte offsets. This functionality is useful for pinpointing exact code locations and extracting specific code segments matched by your structural search patterns.

What is the best way to programmatically rewrite source code using AST?

The best way to programmatically rewrite source code using AST is by leveraging language bindings to parse code, match structural patterns with metavariables, and apply transformation rules. This ensures syntax-safe refactoring across supported languages.