ast-grep

Solid

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.

AI & Automation 66,650 stars 5430 forks Updated today NOASSERTION

Install

View on GitHub

Quality Score: 83/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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, cross-language regex). When in doubt, ask: "does the answer depend on the language's syntax tree, or just on the file's bytes?" If the former, ast-grep. If the latter, grep. --- ## Three things the agent must internalize ### 1. ast-grep is NOT regex The wildcards are `$VAR` (one AST node) ...

Details

Author
code-yeongyu
Repository
code-yeongyu/oh-my-openagent
Created
7 months ago
Last Updated
today
Language
TypeScript
License
NOASSERTION

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category