ast-grep

Search and rewrite code by syntax structure with ast-grep.

5|Updated May 17, 2026
One-click install
npx skills add https://github.com/islee23520/lfg --skill ast-grep-islee23520
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/islee23520/lfg/tree/main/skills/ast-grep
Command: npx skills add https://github.com/islee23520/lfg --skill ast-grep-islee23520

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill removes the guesswork from codebase refactors by searching and rewriting code by syntax structure instead of plain text, which makes it far safer for large-scale edits and language-aware linting.

Core Features & Use Cases

  • AST-aware search: Find functions, calls, imports, classes, control flow, and other syntax shapes across supported languages.
  • Deterministic rewrites: Preview changes first, then apply codemods with built-in safeguards for two-pass mutation workflows.
  • Cross-platform setup: Install and resolve the ast-grep binary on macOS, Linux, Windows, WSL, and Git Bash with fallback paths and diagnostics.
  • Rule-based scanning: Run reusable YAML rules for repository-wide checks, fixes, and snapshot testing.
  • Use Case: A developer can replace console logging, strip unsafe casts, migrate imports, or enforce project-specific code patterns across many files with one guided workflow.

Quick Start

Ask the skill to search for a syntax pattern or rewrite it across your repository, and tell it the target language, path, and whether you want a dry run or an applied change.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I perform syntax-aware code search instead of plain text matching?

Syntax-aware code search finds structural code patterns like functions, calls, and imports by matching syntax structure rather than plain text. This Skill uses ast-grep to locate exact language-specific syntax shapes across supported languages.

What is the best way to run codemods for large-scale codebase refactors?

Running codemods for large-scale refactors is safer with AST-aware rewrites that preview changes before applying them. This Skill performs deterministic rewrites with ast-grep using a two-pass mutation workflow to ensure precise code modifications.

Can I use YAML rules for repository-wide code scanning and linting?

YAML rules can be used for repository-wide code scanning and linting to enforce project-specific patterns. This Skill runs reusable YAML rules with ast-grep to perform checks, apply fixes, and execute snapshot testing across your codebase.

Does ast-grep support cross-platform installation on Windows, macOS, and Linux?

Cross-platform installation on Windows, macOS, Linux, WSL, and Git Bash is supported through binary resolution and installer fallback paths. This Skill resolves the ast-grep binary across these environments with built-in diagnostics for setup.

How do I migrate imports and strip unsafe casts across multiple files?

Migrating imports and stripping unsafe casts across multiple files requires structural code rewrites guided by language-specific patterns. This Skill applies ast-grep to replace logging, migrate imports, and enforce code patterns with a dry run or applied change.

What programming languages are supported for AST-based structural code search?

AST-based structural code search supports JavaScript, TypeScript, Python, Go, Rust, and other supported languages. This Skill requires valid language-specific patterns to execute ast-grep searches and rewrites across these programming environments.