ast-grep

Perform AST-based code search and codemods with offline pattern validation.

3.2k|198|Updated May 25, 2026
One-click install
npx skills add https://github.com/code-yeongyu/lazycodex --skill ast-grep-code-yeongyu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/code-yeongyu/lazycodex/tree/main/plugins/omo/skills/ast-grep
Command: npx skills add https://github.com/code-yeongyu/lazycodex --skill ast-grep-code-yeongyu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

AST-aware code search and deterministic codemods across languages, enabling robust pattern-based code modifications without regex pitfalls.

Core Features & Use Cases

  • Offline pattern validation ensures patterns are parseable before execution.
  • Two-pass apply supports safe previews and actual rewrites for codemods.
  • Binary auto-resolution works across environments, including cache, PATH, and OS-specific installers.
  • Use cases: find structural patterns, migrate code, and enforce YAML-rule scans.

Quick Start

Install the helper and run pattern searches or codemods across your repository.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I run AST-based code search and codemods across multiple programming languages?

AST-based code search and codemods run across 25 languages via a wrapper around sg, using offline pattern validation to ensure patterns parse correctly before execution. This avoids regex pitfalls and enables deterministic structural modifications.

What is the best way to perform deterministic code modifications without regex issues?

Deterministic code modifications use two-pass rewriting for safe previews and actual rewrites, applying structural AST patterns instead of regex. This approach ensures robust pattern-based code modifications across supported languages.

Can I use YAML rules to scan and enforce code patterns in my repository?

YAML rule scans are supported for finding structural patterns and enforcing code standards. The system validates patterns offline before execution, ensuring your YAML rules parse correctly and apply deterministically across the codebase.

Does ast-grep work offline and resolve its binary across different operating systems?

Binary auto-resolution works offline across environments, checking cache, PATH, and OS-specific installers. The install workflow falls back to GitHub releases when needed, ensuring the sg binary resolves correctly on your platform.

How do I safely preview codemod rewrites before applying them to my codebase?

Two-pass apply supports safe previews and actual rewrites for codemods, allowing you to review structural modifications before committing them. Offline pattern validation ensures patterns are parseable before execution begins.