ast-grep

Solid

Searches and rewrites code by AST shape across 25 languages. Use when the target is a syntax pattern (every call/class/import shaped like X, a codemod, a YAML rule) rather than literal text; for plain strings, comments, or filenames, use rg.

AI & Automation 68,941 stars 5670 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
9 months ago
Last Updated
today
Language
TypeScript
License
NOASSERTION

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category