ast-grep-transforms

Automate code rewriting and transformation using ast-grep rules with metavariables.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill automates rewriting and transforming code with ast-grep rules, reducing manual refactors and enabling precise metavariable-driven edits.

Core Features & Use Cases

  • Automate code rewriting with patterns and metavariable substitution to produce deterministic fixes.
  • Apply transform operations (replace, substring, convert, rewrite) to manipulate captured text before substitution.
  • Chain rewriters for recursive or selective transformations and reuse FixConfig for advanced behavior (expandStart, expandEnd).
  • Use codemods to perform large-scale refactors across languages supported by ast-grep.

Quick Start

Create a simple rule to rename a JavaScript variable from var to let using metavariables and a fix.

Frequently Asked Questions about ast-grep-transforms

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

FAQPage Schema
How do I write an ast-grep codemod to refactor code automatically?

Automate code refactoring by defining ast-grep pattern-based rules with metavariables, then applying transformation operations like replace, substring, convert, or rewrite to manipulate captured text and produce deterministic fixes.

What are metavariables used for in ast-grep rules?

Metavariables in ast-grep rules capture specific syntax nodes during pattern matching so you can manipulate the captured text with transform operations and substitute it back into the rewritten code.

Can I use regex to replace captured text in an ast-grep transformation?

Yes, ast-grep transformations support a replace operation that uses regex to manipulate text captured by metavariables before substituting it back into the rewritten code structure.

Does ast-grep support recursive code transformations across multiple files?

Yes, ast-grep supports chaining rewriters for recursive or selective transformations, allowing you to perform large-scale codemods and complex text transformations across multiple files in supported languages.

How do I expand text selection boundaries when writing ast-grep fixes?

Use the FixConfig options expandStart and expandEnd in your ast-grep rule to adjust the text selection boundaries before applying the transformation and generating the final code fix.

What is the difference between substring and rewrite operations in ast-grep transforms?

Substring extracts a portion of the captured metavariable text, while rewrite applies a structural transformation to the matched code node, both manipulating text before substitution in ast-grep rules.