AI Skill MartBrowse skillsPromptsProgramsLearnWhat is a Skill?
← Back to list

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) with search, replace, scan, validate, langs, and doctor subcommands.
  • Validates patterns offline to catch regex misuse (\w+, .*, |) before ever invoking sg, killing most "0 matches" debug loops.
  • replace defaults to dry-run and only mutates files with --apply; it works around the silent --json vs --update-all conflict 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

  1. Rewrite every console.log($MSG) to logger.info($MSG) — preview affected files, then apply.
  2. Strip all as any casts in TypeScript, or migrate require(...) calls to import.
  3. In Python, convert Optional[X] to X | None, or hunt down empty catch blocks and missing await.

· · · 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)
  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 AI 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.

  1. Install the ast-grep binary: brew install ast-grep, or cargo install ast-grep --locked, or npm i -g @ast-grep/cli.
  2. Clone the repo: git clone https://github.com/code-yeongyu/oh-my-openagent.git /tmp/oh-my-openagent
  3. 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/
  4. Verify the setup: python3 ~/.claude/skills/ast-grep/scripts/ast_grep_helper.py doctor
  5. Restart Claude Code and try a prompt like "find every function in this repo that takes a Request parameter".
  6. On Linux, sg collides with the setgroups tool — add alias sg=ast-grep to your shell profile.
View source on GitHub ↗License: NOASSERTION