# Ast Grep

> Use when code search needs AST structure, ast-grep, sg, structural matching, or read-only find-usages.

- Skill: `anntnzrb/ast-grep` (Agent Skill, multi-file: 5 files)
- Install (CLI): `npx skillmds@latest add anntnzrb/ast-grep`
- Raw SKILL.md: https://api.skillmd.com/api/skills/anntnzrb/ast-grep/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: AGPL-3.0-or-later
- Author: anntnzrb (https://skillmd.com/u/anntnzrb)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/anntnzrb/ast-grep

---


# ast-grep

## Overview

Read-only CLI search with `sg` or `ast-grep`. AST-aware grep for code exploration and SWE tasks.

## Quick start

- Prefer `sg`. Fallback `ast-grep run`. Last resort: `nix run nixpkgs#ast-grep -- run`
- Example: `sg -p 'console.log($MSG)' -l ts src`
- Files only: `sg -p 'console.log($$$)' -l ts --files-with-matches src`

## Guardrails

- Read-only: never use `--rewrite`, `-r`, `--update-all`, or `--interactive`
- Stdin requires `--lang`

## Required follow-up reads

| Need | Read | When |
| --- | --- | --- |
| Flags and matching semantics | `reference.md` | For strictness, selectors, output, globs, config, or stdin |
| Basic patterns | `cookbook/basics.md` | For common read-only find-usage recipes |
| Advanced patterns | `cookbook/advanced.md` | For selectors, relationships, or tighter scope control |
| Recovery | `cookbook/troubleshooting.md` | When parsing, language detection, quoting, or binary resolution fails |

