# Ast Grep

Use for ast-grep project setup, rule authoring, rule debugging, and structural search...

- Repository: https://github.com/vinhnx/VTCode (897 stars)
- Category: Testing
- License: Apache-2.0
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add vinhnx/VTCode --skill ast-grep -g -a claude-code -y`
Codex: `npx skills add vinhnx/VTCode --skill ast-grep -g -a codex -y`
Cursor: `npx skills add vinhnx/VTCode --skill ast-grep -g -a cursor -y`
Gemini CLI: `npx skills add vinhnx/VTCode --skill ast-grep -g -a gemini-cli -y`

## Description

Use for ast-grep project setup, rule authoring, rule debugging, and structural search workflows.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Ast-Grep

Use this skill for ast-grep project setup, rule authoring, rule debugging, and CLI workflows that go beyond a single
structural query.

## Routing

- Use `exec_command` for ast-grep queries, project scans, rule tests, debug output, and rewrite previews.
- Use `ast-grep scan` for project rules and `ast-grep test` for rule tests.
- Use `ast-grep run --pattern=... --rewrite=... --json=compact --color=never` for dry-run rewrite previews. Review every
  replacement before applying changes.
- Use `ast-grep run --debug-query` when a query matches an unexpected syntax node.
- Use `--kind` to match node kinds. Ast-grep supports ESQuery-style compound selectors and pseudo-selectors in supported
  releases.
- Keep this skill read-only unless the user explicitly authorises applying a rewrite.

## Quick Start

- In VT Code, prefer `vtcode dependencies install ast-grep` before suggesting system package managers.
- External install routes such as Homebrew, Cargo, npm, pip, MacPorts, or Nix are fallback options when the user
  explicitly wants a system-managed install.
- After installation, validate availability with `ast-grep --help`.
- On Linux, prefer the full `ast-grep` binary name over `sg` because `sg` may already refer to `setgroups`.
- When running CLI patterns with shell metavariables like `$PROP`, use single quotes so the shell does not expand them
  before ast-grep sees the pattern.
- A good first rewrite example is optional chaining, for example rewriting `$PROP && $PROP()` to `$PROP?.()`.

## Command Overview

- `ast-grep run`: ad-hoc query execution and one-off rewrites.
- `ast-grep scan`: project rule scanning.
- `ast-grep new`: scaffold and rule generation.
- `ast-grep test`: rule-test execution.
- `ast-grep lsp`: editor integration via language server.

## Built-In Languages

The rest: https://github.com/vinhnx/VTCode/blob/HEAD/crates/codegen/vtcode-skills/src/skills/assets/samples/ast-grep/SKILL.md
