Agent skill

ast-grep

Use ast-grep (sg) for AST-aware code search and rewrite across 25 languages. Trigger for structural code matching or deterministic codemods: find every function/call/class/import shaped like X, rewrite console.log to logger.info, strip `as any`, migrate require() to import, find empty catch blocks or missing await, and scan/apply YAML rules. Prefer this over rg/grep when the target is syntax shape rather than text; use rg for string contents, comments, filenames, or regex-style byte searches.

YeonGyu-Kim69,732★ · +488/wk · 2 repos on radarProfile →
claude-codecodexcursorships scriptsNOASSERTION
Install
npx skills add code-yeongyu/oh-my-openagent --skill ast-grep --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 17
SKILL.md size: 12 KB
Bundled scripts: yes
Path: packages/shared-skills/skills/ast-grep/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 67,209 · +483 this week
Language: TypeScript
Read our review of the source →

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

From the SKILL.md

# ast-grep `sg` (also installed as `ast-grep`) is an **AST-aware search and rewrite tool** across 25 languages. It treats your pattern as code, parses it the same way it parses your project, and matches structurally. It is the right tool whenever your question depends on **code shape** rather than text bytes. This skill ships a Python wrapper at `scripts/ast_grep_helper.py` and platform install scripts at `install.sh` (POSIX) and `install.ps1` (Windows). The helper adds offline pattern validation, the two-pass write trick, and binary auto-resolution. Use it as your default entry point. --- ## When to use this skill Use it whenever the user's question is about **code structure**, not bytes: - "Find every function that takes a `Request` parameter." - "Rewrite every `console.log(x)` to `logger.info(x)`." - "Strip every `as any` cast." - "Replace `require(...)` with `import` across the repo." - "Find empty catch blocks." - "Migrate `Optional[X]` to `X | None`." - "Apply this codemod across these 200 files." - "Run our YAML lint rules and surface violations." Switch to plain `grep` / `rg` when the question is text-shaped (string literal contents, comments, license headers, file names, c

What's inside
Steps it walks through
  1. When to use this skill
  2. Three things the agent must internalize
  3. 1. ast-grep is NOT regex
  4. 2. Patterns must be valid code
  5. 3. --update-all and --json are mutually exclusive (silently)
  6. The helper script — scripts/astgrephelper.py
  7. search — find all matches of a pattern
  8. replace — rewrite by pattern, dry-run by default
  9. scan — run YAML rules
  10. validate — offline pattern check (no sg call)
  11. langs / doctor / install
  12. Direct sg use (when the helper isn't enough)
  13. Decision tree — what to use, when
  14. Always run dry-run first when rewriting
Ships with 16 files
  • .gitignore
  • LICENSE
  • README.md
  • SOURCE
  • install.ps1
  • install.sh
  • references/cli.md
  • references/install.md
  • references/patterns.md
  • references/pitfalls.md
  • references/recipes.md
  • references/sgconfig.md
  • references/yaml-rules.md
  • scripts/ast_grep_helper.py
  • tests/smoke.ps1
  • tests/smoke.sh
Commands it runs
sg run -p P -r R --json=compact .   # pass 1: see what would change
sg run -p P -r R --update-all .     # pass 2: actually apply
python3 scripts/ast_grep_helper.py search 'console.log($MSG)' --lang ts src/
Dry-run preview (default — no files mutated)
python3 scripts/ast_grep_helper.py replace 'console.log($MSG)' 'logger.info($MSG)' --lang ts src/
Actually apply
python3 scripts/ast_grep_helper.py replace 'console.log($MSG)' 'logger.info($MSG)' --lang ts src/ --apply
Discover sgconfig.yml from cwd and run all rules
python3 scripts/ast_grep_helper.py scan src/
Run a single rule file
More from oh-my-openagent
All skills →
About this skill
What does the ast-grep skill do?

Use ast-grep (sg) for AST-aware code search and rewrite across 25 languages. Trigger for structural code matching or deterministic codemods: find every function/call/class/import shaped like X, rewrite console.log to logger.info, strip `as any`, migrate require() to import, find empty catch blocks or missing await, and scan/apply YAML rules. Prefer this over rg/grep when the target is syntax shape rather than text; use rg for string contents, comments, filenames, or regex-style byte searches.

How do I install it?

Run `npx skills add code-yeongyu/oh-my-openagent --skill ast-grep --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.

Where does this skill come from?

From code-yeongyu/oh-my-openagent, a repository with 67,209 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.

Is a popular skill a good skill?

Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.

Keep going