ast-grep

ast-grep is a skill for Claude Code, Codex from rolandbrecht/agent-skills. It costs 193 tokens per session (2,018 once invoked), scanned A, original, MIT.

A tool guide for searching, checking, and rewriting code by its syntax structure rather than by matching plain text. It uses patterns that resemble code and supports many programming languages.

In plain words
What is it for?
It helps find code patterns, run syntax-based lint rules, inspect file symbols and imports, and perform repeated code replacements or migrations.
Why use it?
It lowers the risk of changing comments, strings, or the wrong text when applying broad code edits. It is useful when code spans multiple lines or contains nested brackets.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit It helps find code patterns, run syntax-based lint rules, inspect file symbols and imports, and perform repeated code replacements or migrations.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/rolandbrecht/agent-skills/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 rolandbrecht/agent-skills --skill ast-grep
Clone the repo
git clone --depth 1 https://github.com/rolandbrecht/agent-skills

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/rolandbrecht/agent-skills/ast-grep/github.svg)](https://agentmods.dev/skills/rolandbrecht/agent-skills/ast-grep)
Your own site
<a href="https://agentmods.dev/skills/rolandbrecht/agent-skills/ast-grep"><img src="https://agentmods.dev/badge/skills/rolandbrecht/agent-skills/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/rolandbrecht/agent-skills/ast-grep"><img src="https://agentmods.dev/badge/skills/rolandbrecht/agent-skills/ast-grep.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 193 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,018 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.
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.00193 $0.02018
Opus 5 $0.00097 $0.01009
Sonnet 5 $0.00039 $0.00404
Haiku 4.5 $0.00019 $0.00202

Measured 10d ago against content hash dbfe380b9d55, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, 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 10d ago.

The scan reads SKILL.md. This mod also ships 3 executable files (scripts/install.sh, scripts/json-summary.py, tests/test_json_summary.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

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.

ast-grep/SKILL.md · 147 lines

How it starts

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

ast-grep — Structural Code Search, Lint, and Rewrite

Content verified against ast-grep 0.45.1. Flags can drift between versions — when a command fails, check ast-grep <cmd> --help.

Overview

ast-grep is a fast, Rust-based CLI tool. It parses code with tree-sitter and matches the syntax tree, not the text. You write patterns that look like the code you search for. Metavariables ($NAME, $$$ARGS) act as wildcards for AST nodes.

Three main modes:

Mode Command Use for
Search / rewrite ast-grep run -p '<pattern>' (default command) One-time queries and codemods
Lint ast-grep scan YAML rule sets, CI checks, complex rules
Explore ast-grep outline Symbols, imports, exports of files

It supports 25+ languages: JavaScript, TypeScript, TSX, Python, Rust, Go, Java, C, C++, C#, Kotlin, Swift, Ruby, PHP, and more. See the language table in references/cli-reference.md.

Installation

Check first: which ast-grep. If it is not installed, run the bundled helper:

bash <SKILL_DIR>/scripts/install.sh

The script tries brew, cargo, npm, pip3, and MacPorts in order, and verifies the result. For manual installation see https://ast-grep.github.io/guide/quick-start.html.

Note: some systems have a different sg binary (shell group). Always use the full name ast-grep.

Tool Selection: grep vs ast-grep vs LSP

The question is about... Use
Text: strings, error messages, config values, file names grep / rg / fd
Syntax: "all calls that look like X", pattern rewrites, codemods, lint rules ast-grep
Semantics: go-to-definition, find-references across scopes, types, scope-aware rename LSP / compiler tooling
Graphs: transitive callers, circular imports, dead-code detection across a whole codebase A graph script over ast-grep --json output; ast-grep alone sees only per-file matches

ast-grep matches syntax, not semantics. It cannot tell two same-named symbols in different scopes apart. A rename with ast-grep is an exact syntactic replace (it skips comments, strings, and oldNameHelper), but it hits every scope. For a true semantic rename, prefer an LSP rename; use ast-grep when no LSP is available and verify the diff.

Read the full file on GitHub · 147 lines

Files

What ships with it

7 files 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. 10d ago First seen · 147 lines · 193 tokens per session scan A dbfe380b9d55

Subscribe to this mod's changes

ast-grep is a skill published in the GitHub repository rolandbrecht/agent-skills (4 stars, last pushed 27d ago), licensed MIT. It adds 193 tokens to every session and 2,018 once invoked, about $0.0010 per session on Opus 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-31.