Claude Skill MartBrowse skillsWhat is a Skill?
Back to list

ast-grep Structural Code Search & Rewrite

Search and rewrite code across 25 languages by syntax shape (AST) instead of text, with a safe two-pass codemod workflow.

Dev & CodingIntermediate67,5315,507AI score 9/10Last updated: Aug 9, 2026

What it does

Drives ast-grep (sg) to match and rewrite code structurally: $VAR matches one AST node, $$$ matches zero or more. Ideal when the question depends on code shape rather than bytes.

  • Ships a stdlib-only Python wrapper (scripts/ast_grep_helper.py) with search, replace, scan, validate, langs, doctor, and install subcommands.
  • Validates patterns offline first, catching the regex-misuse mistakes (\w, .*, |) that cause most "0 matches" sessions.
  • Handles ast-grep's biggest scripting gotcha automatically: --json and --update-all are mutually exclusive, so it runs a preview pass then an apply pass.
  • replace is dry-run by default and always reports match count and number of files touched.
  • Supports YAML rules via sg scan for reusable lint rules, auto-fixes, and CI annotations.
  • Includes a decision tree for when to use ast-grep vs rg/grep vs LSP-based tooling.

Who it's for

  • Engineers running large migrations (require → import, Optional[X]X | None, API renames).
  • Anyone burned by grep false positives during refactors.
  • Team leads adding custom structural lint rules to CI.
  • Users who want Claude Code to "change them all" without silent damage.

Examples

  1. Logger migration: "Rewrite every console.log(x) to logger.info(x)" → dry-run preview with blast radius, then --apply.
  2. Type cleanup: "Strip all as any casts in TypeScript and list what's left" → structural matching skips strings and comments.
  3. Codebase audit: "Find empty catch blocks and turn it into a YAML rule for CI" → author a rule in rules/, run sg scan --report-style short.

· · · Install guide · · ·

Install in the Claude app (no terminal)
  1. Download the ZIP with the button below.
  2. In Claude, open Settings → Capabilities and turn on 'Code execution and file creation'. (one time)
  3. Go to Customize → Skills → + → 'Upload a skill' and upload the ZIP.
Download ZIP
Install in Claude Code

Let Claude do it — paste this into Claude Code

Install the skill I found on Claude Skill Mart.
Copy the packages/shared-skills/skills/ast-grep folder from the GitHub repo code-yeongyu/oh-my-openagent into my ~/.claude/skills/ast-grep/.
When it's done, tell me in one line what this skill can do.

Install with a command instead

git clone https://github.com/code-yeongyu/oh-my-openagent.git && mkdir -p ~/.claude/skills && cp -r oh-my-openagent/packages/shared-skills/skills/ast-grep ~/.claude/skills/

This is a third-party skill. Check the source repository before installing.

  1. Open a terminal and confirm Python 3 exists: python3 --version.
  2. Clone the repo: git clone https://github.com/code-yeongyu/oh-my-openagent.git
  3. Copy the skill: mkdir -p ~/.claude/skills && cp -r oh-my-openagent/packages/shared-skills/skills/ast-grep ~/.claude/skills/
  4. Install the binary: bash ~/.claude/skills/ast-grep/install.sh (Windows: run install.ps1 in PowerShell), or use brew install ast-grep / cargo install ast-grep.
  5. Verify with python3 ~/.claude/skills/ast-grep/scripts/ast_grep_helper.py doctor.
  6. Restart Claude Code, then ask something like "find every function that takes a Request parameter".
  7. Before any rewrite, commit your work, review the dry-run output, and only then add --apply. On Linux prefer the ast-grep binary name over sg.
View source on GitHubLicense: NOASSERTION