ast-grep-refactor

Refactor code across files by matching AST patterns and applying rewrites.

1|Updated Apr 20, 2026
One-click install
npx skills add https://github.com/IndianBoy42/dot-opencode --skill ast-grep-refactor
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep-refactor
Source: https://github.com/IndianBoy42/dot-opencode/tree/main/skills/ast-grep-refactor
Command: npx skills add https://github.com/IndianBoy42/dot-opencode --skill ast-grep-refactor

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Automate large-scale code refactoring by applying structural transformations that preserve semantics, reducing manual search-and-replace errors across files.

Core Features & Use Cases

  • Systematic refactoring using AST-based rewrite rules across a codebase
  • API migrations and code modernization through pattern-driven transformations
  • Creation of reusable transformation rules for scalable maintenance

Quick Start

Create or load an ast-grep rule and run it against your project to perform structural refactors safely.

Frequently Asked Questions about ast-grep-refactor

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

FAQPage Schema
How do I perform a bulk API migration across multiple files safely?

Bulk API migration is performed by defining AST patterns to match outdated code and applying structural rewrite rules across the codebase. This approach preserves program semantics and reduces manual search-and-replace errors during large refactoring tasks.

How does AST-based code transformation work for large codebase refactoring?

AST-based code transformation works by parsing source code into an Abstract Syntax Tree, matching specific structural patterns, and applying rewrite rules. This method ensures program semantics are preserved while systematically modernizing code across multiple files.

What is the best way to automate code modernization without breaking program semantics?

Automating code modernization safely requires pattern-driven structural transformations using AST rules. By matching abstract syntax tree patterns rather than raw text, the refactoring process preserves program semantics and prevents errors common in manual edits.

Do I need ast-grep tooling installed to run structural refactor rules?

Yes, ast-grep tooling must be installed to execute structural refactor rules. The process relies on ast-grep to parse AST patterns and apply rewrites, requiring rule-driven configuration alongside dry-run and review workflows to ensure safe transformations.

Can I dry-run AST rewrites before applying bulk refactoring changes?

Yes, dry-run and review workflows are required to ensure safe transformations during bulk refactoring. Running structural rewrite rules in a dry-run state allows you to verify AST pattern matches and preview code transformations before committing changes across the codebase.

Why use AST pattern matching instead of regex for large-scale code refactoring?

AST pattern matching identifies structural code constructs rather than matching raw text strings like regex. This structural approach ensures program semantics are preserved during API migrations and bulk refactoring, systematically preventing errors that arise from manual search-and-replace.