Skip to content
Back to skills

Ast Grep 2

ASecurity

Read-only structural code search with ast-grep/sg. Grep/rg/sed alternative for AST-aware CLI exploration, pattern search, and fast code discovery. Activates on ast-grep/sg, structural search, AST search, find usages, tree-sitter.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
researchrailsperformance

Works with

  • cli

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill ast-grep-2 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ast Grep 2?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ast Grep 2
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-ast-grep-2/badge)](https://www.skillsdirectory.com/skills/david-li0406-ast-grep-2)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ast-grep
description: "Read-only structural code search with ast-grep/sg. Grep/rg/sed alternative for AST-aware CLI exploration, pattern search, and fast code discovery. Activates on ast-grep/sg, structural search, AST search, find usages, tree-sitter."
---

# 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`. Last resort: `nix run nixpkgs#ast-grep --`.
- Basic pattern search:
  - `sg -p 'console.log($MSG)' -l ts src`
- Files with matches only:
  - `sg -p 'console.log($$$)' -l ts --files-with-matches src`
- Show JSON (stream):
  - `sg -p 'console.log($$$)' -l ts --json=stream src`

## Workflow
- Locate: start with narrow paths + `--globs` include/exclude.
- Verify language: set `-l/--lang` for stdin or ambiguous files.
- Inspect: use `--debug-query` or `--inspect summary` when matches surprise.
- Report: `--files-with-matches` or `--json=stream` for pipelines.
 - Prefer read-only search; skip rewrite flags.

## Tasks
- Pattern search: `run` (default) with `-p/--pattern`.
- Context: `-A/-B/-C` for line context.
- Performance: narrow paths, `--globs`, `--files-with-matches`, `--json=stream`.

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

## Resources
- `reference.md`: patterns, strictness, selectors, output formats.
- `cookbook/`: practical recipes.

Files in this skill

  • SKILL.md1.4 KB
  • cookbook/advanced.md1.4 KB
  • cookbook/basics.md1.2 KB
  • cookbook/troubleshooting.md1.2 KB
  • reference.md1.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…