Agent skill · nousresearch

ast-grep

AST-aware structural code search and rewrite via ast-grep.

What it needs

About 8k tokens when loaded.

What this skill does

ast-grep 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/astgrephelper.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. --- When to use this skill Use it whenever the 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 searchfiles (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, searchfiles. Hermes integration notes: Run the helper and sg through the terminal tool. Single-quote every pattern so the shell never expands $VAR. For find→read chains around matches, use --json-out and process with executecode rather than piping through interpreters. This complements (does not replace) Hermes's patch tool: patch is for targeted edits you author; ast-grep is for pattern-driven bulk rewrites across many sites. --- Three things the agent must internalize 1. ast-grep is NOT regex The wildcards are $VAR (one AST node) and $$ (zero or more nodes). …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills nousresearch/ast-grep

View the source on GitHub

Browse the @skills marketplace