ast-grep-cli

Automate AST-based code searches, rewrites, and rule testing via YAML rules.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

AST-driven code search, rewrite, and rule testing can be verbose and error-prone when done manually. This skill provides a cohesive CLI to locate patterns, apply safe transformations, and validate rules against codebases.

Core Features & Use Cases

  • Run one-off searches and rewrites using AST patterns to automate refactoring.
  • Manage projects with sgconfig.yml to organize rule directories and tests.
  • Scan codebases and validate rules with snapshot tests to ensure stability.
  • Debug pattern parsing and tune queries with advanced options to improve accuracy.

Quick Start

Run a sample search with a pattern to locate matches in your codebase.

Frequently Asked Questions about ast-grep-cli

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

FAQPage Schema
How do I use AST pattern matching for code search and refactoring?

AST pattern matching for code search and refactoring uses YAML-defined rules to locate and rewrite code structures safely. This approach leverages abstract syntax trees to automate transformations across JavaScript and TypeScript codebases via a CLI.

How do I validate and test custom code rewrite rules against a codebase?

Validating and testing custom code rewrite rules uses snapshot-based validation to ensure rule stability. You define test cases in your project configuration to scan the codebase and verify that pattern matches and transformations produce expected results.

Can I use YAML rules to search JavaScript and TypeScript code?

Yes, you can use YAML rules to search JavaScript and TypeScript code effectively. The system applies these YAML-defined rules through the ast-grep CLI to execute structured abstract syntax tree searches across your project files.

What is the best way to organize AST code search rules in a project?

Organizing AST code search rules in a project uses an sgconfig.yml file to define and manage rule directories. This configuration establishes a cohesive project setup that enables the CLI to locate and apply your custom pattern-matching rules accurately.

Why do manual AST-driven code rewrites fail when refactoring large codebases?

Manual AST-driven code rewrites fail when refactoring large codebases because they are verbose and error-prone without a cohesive CLI. Automating searches and applying safe transformations through snapshot validation prevents structural errors during execution.