ast-grep

Locate code by AST structure across JavaScript, TypeScript, Python, and Go.

20|2|Updated Oct 18, 2025
One-click install
npx skills add https://github.com/xdg/xdg-claude --skill ast-grep-xdg
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/xdg/xdg-claude/tree/main/context-efficient-tools/skills/ast-grep
Command: npx skills add https://github.com/xdg/xdg-claude --skill ast-grep-xdg

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Solve the "old_string not unique" problem by matching code structure instead of exact text, enabling robust refactoring across formatting variations and language constructs.

Core Features & Use Cases

  • Structural pattern matching: locate code by AST structure rather than literal text, reducing false positives.
  • Language-aware searches: operate across JavaScript/TypeScript, Python, Go, and other languages with precise syntax.
  • Safe refactoring workflows: compose transformations that preserve behavior while updating calls, imports, and definitions.

Quick Start

Provide an ast-grep pattern to locate all usages of a target function and refactor them with the new signature.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I fix the "old_string not unique" error when refactoring code?

Structural code search resolves the "old_string not unique" error by matching AST-based patterns to locate code by structure rather than exact text, enabling safe refactoring across formatting variations.

What is AST-based pattern matching for JavaScript and TypeScript refactoring?

AST-based pattern matching locates function calls, imports, and class patterns by syntax structure using metavariables like $VAR and $$STMT, reducing false positives compared to literal text search.

Can I use structural search and refactoring across multi-language codebases?

Yes, structural search operates across multi-language codebases including JavaScript, TypeScript, Python, and Go, requiring explicit language targeting with the -l flag to ensure precise syntax parsing.

How do I locate and update all function call signatures in a codebase?

You can locate and refactor function calls by providing an ast-grep pattern to find all target usages and applying transformations that update calls, imports, and definitions while preserving behavior.

Does structural code search work with non-interactive refactoring workflows?

Yes, structural code search supports non-interactive search-and-refactor workflows, allowing you to compose transformations that locate function definitions and apply updates automatically across the codebase.