ast-grep Structural Search & Rewrite
Search and refactor code by syntax structure (AST) instead of text across 25 languages, with dry-run-first codemods.
Dev & CodingIntermediate★ 67,531⑂ 5,507AI score 9/10Last updated: Aug 9, 2026
What it does
- Matches code by its syntax tree rather than raw bytes, using
$VAR(one node) and$$$(zero or more nodes) wildcards. - Ships a stdlib-only Python helper (
scripts/ast_grep_helper.py) withsearch,replace,scan,validate,langs, anddoctorsubcommands. - Validates patterns offline to catch regex misuse (
\w+,.*,|) before ever invokingsg, killing most "0 matches" debug loops. replacedefaults to dry-run and only mutates files with--apply; it works around the silent--jsonvs--update-allconflict via a two-pass run.- Scales up to YAML rules (
sg scan) for reusable lint rules, auto-fixes, and CI reporting.
Who it's for
- Developers doing API migrations or large-scale refactors across a codebase.
- Teams building lint rules or codemods that run in CI.
- Anyone burned by regex-based find/replace hitting the wrong code.
Example uses
- Rewrite every
console.log($MSG)tologger.info($MSG)— preview affected files, then apply. - Strip all
as anycasts in TypeScript, or migraterequire(...)calls toimport. - In Python, convert
Optional[X]toX | None, or hunt down empty catch blocks and missingawait.
· · · Install guide · · ·
Try it now, no install
Paste this into Claude to use the skill without installing anything.
Read the instructions in this file and follow them to help me: https://raw.githubusercontent.com/code-yeongyu/oh-my-openagent/HEAD/packages/shared-skills/skills/ast-grep/SKILL.md What I want: (describe your task here)
If Claude can't open the link, open it yourself and paste the contents instead.
↓ If it works for you, download the ZIP below and install it. Then it runs on its own — no pasting each time.
Install in the Claude app (no terminal)
- Download the ZIP with the button below.
- In Claude, open Settings → Capabilities and turn on 'Code execution and file creation'. (one time)
- Go to Customize → Skills → + → 'Upload a skill' and upload the 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 /tmp/oh-my-openagent && mkdir -p ~/.claude/skills && cp -r /tmp/oh-my-openagent/packages/shared-skills/skills/ast-grep ~/.claude/skills/⚠ This is a third-party skill. Check the source repository before installing.
- Install the ast-grep binary:
brew install ast-grep, orcargo install ast-grep --locked, ornpm i -g @ast-grep/cli. - Clone the repo:
git clone https://github.com/code-yeongyu/oh-my-openagent.git /tmp/oh-my-openagent - Copy the whole skill folder (it needs scripts/ and references/):
mkdir -p ~/.claude/skills && cp -r /tmp/oh-my-openagent/packages/shared-skills/skills/ast-grep ~/.claude/skills/ - Verify the setup:
python3 ~/.claude/skills/ast-grep/scripts/ast_grep_helper.py doctor - Restart Claude Code and try a prompt like "find every function in this repo that takes a Request parameter".
- On Linux,
sgcollides with thesetgroupstool — addalias sg=ast-grepto your shell profile.
View source on GitHub ↗License: NOASSERTION