ast-grep

ast-grep is a skill for Claude Code, Codex from vinhnx/VTCode. It costs 24 tokens per session (24,520 once invoked), scanned A, original, Apache-2.0.

A guide to ast-grep, a tool that searches and rewrites code by understanding its structure instead of treating it as plain text.

In plain words
What is it for?
Use it to set up ast-grep, scan projects, author and test rules, inspect query matches, and preview structural code changes.
Why use it?
It provides a safer workflow for writing rules, debugging unexpected matches, and reviewing automated rewrites before applying them.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: positional $N argument.

Good fit Use it to set up ast-grep, scan projects, author and test rules, inspect query matches, and preview structural code changes.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/vinhnx/vtcode/ast-grep
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add vinhnx/VTCode --skill ast-grep
Clone the repo
git clone --depth 1 https://github.com/vinhnx/VTCode

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for ast-grep

README.md
[![agentmods](https://agentmods.dev/badge/skills/vinhnx/vtcode/ast-grep/github.svg)](https://agentmods.dev/skills/vinhnx/vtcode/ast-grep)
Your own site
<a href="https://agentmods.dev/skills/vinhnx/vtcode/ast-grep"><img src="https://agentmods.dev/badge/skills/vinhnx/vtcode/ast-grep/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for ast-grep

Your own site · 80×15
<a href="https://agentmods.dev/skills/vinhnx/vtcode/ast-grep"><img src="https://agentmods.dev/badge/skills/vinhnx/vtcode/ast-grep.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 24 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 24,520 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00024 $0.24520
Opus 5.5 $0.00010 $0.09808
Sonnet 5.5 $0.00005 $0.04904
Haiku 4.5 $0.00002 $0.02452

Measured 14d ago against content hash 735655cecde4, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

ast-grep scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 14d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

crates/codegen/vtcode-skills/src/skills/assets/samples/ast-grep/SKILL.md · 1,848 lines

How it starts

The opening of the file, as written. The whole thing — 1,848 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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

  • ast-grep ships many built-in languages. Common aliases include bash, c, cc / cpp, cs, css, ex, go / golang, html, java, js / javascript / jsx, json, kt, lua, md / markdown, php, py / python, rb, rs / rust, swift, ts / typescript, tsx, and yml.
  • --lang <alias> and YAML language: <alias> use those built-in aliases. File-system scans infer language from built-in extensions unless the project overrides them.
  • Pass --lang <alias> to the CLI when extension inference is insufficient.
  • Use languageGlobs when the repository needs a different extension mapping than ast-grep’s built-in defaults.

Read the full file on GitHub · 1,848 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 14d ago Changed · +436 lines 735655cecde4
  2. 1mo ago First seen · 1,412 lines · 24 tokens per session scan A 8771519d9649

Subscribe to this mod's changes

ast-grep is a skill published in the GitHub repository vinhnx/VTCode (880 stars, last pushed yesterday), licensed Apache-2.0. It adds 24 tokens to every session and 24,520 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.