Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Searches and rewrites code by syntax structure across 25 languages using the ast-grep tool and a Python helper.
Use this skill ↓33% 83%+50 ptsof test cases passed
Passed 20 of 24 test cases with the skill, and 8 of 24 without it.
3 of 3 safety checks passed
Not used yet
ast-grep (binary also named sg) 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.
Upstream source: vendored from code-yeongyu/ast-grep-skill (MIT), as shipped in oh-my-openagent's shared-skills bundle.
Use it whenever the question is about code structure, not bytes:
Request parameter."console.log(x) to logger.info(x)."as any cast."require(...) with import across the repo."Optional[X] to X | None."Switch to search_files (or plain 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, search_files.
Hermes integration notes:
sg through the terminal tool. Single-quote every pattern so the shell never expands $VAR.--json-out and process with execute_code rather than piping through interpreters.patch tool: patch is for targeted edits you author; ast-grep is for pattern-driven bulk rewrites across many sites.The wildcards are $VAR (one AST node) and $$$ (zero or more nodes). Regex syntax fails silently:
| You wrote | What ast-grep saw | What you wanted |
|---|
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.