ast-grep

ast-grep is a skill for Claude Code from mishahanin/heading-os. It costs 80 tokens per session (2,105 once invoked), scanned A, original, Apache-2.0.

A guide for using ast-grep, a code-search tool that matches the structure of programs rather than just their words.

In plain words
What is it for?
Use it to design searches for patterns such as particular function calls, asynchronous functions without error handling, or other code structures.
Why use it?
Ordinary text search can miss code patterns when formatting or names differ. Structural searches can find matching language constructs more precisely.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Good fit Use it to design searches for patterns such as particular function calls, asynchronous functions without error handling, or other code structures.

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

Made for: Claude Code.

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/mishahanin/heading-os/ast-grep/github.svg)](https://agentmods.dev/skills/mishahanin/heading-os/ast-grep)
Your own site
<a href="https://agentmods.dev/skills/mishahanin/heading-os/ast-grep"><img src="https://agentmods.dev/badge/skills/mishahanin/heading-os/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/mishahanin/heading-os/ast-grep"><img src="https://agentmods.dev/badge/skills/mishahanin/heading-os/ast-grep.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 80 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,105 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.00080 $0.02105
Opus 5 $0.00040 $0.01052
Sonnet 5 $0.00016 $0.00421
Haiku 4.5 $0.00008 $0.00211

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

.claude/skills/ast-grep/SKILL.md · 218 lines

How it starts

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

Adapted from upstream ast-grep/agent-skill. Workspace-customized frontmatter; body refactored 2026-06-16 (CLI catalog split to references/cli-cookbook.md, voice/never sections added).

Overview

This skill helps translate natural language queries into ast-grep rules for structural code search. The ast-grep tool uses Abstract Syntax Tree (AST) patterns to match code by its structure rather than its text. This makes code search precise across large codebases.

When to Use This Skill

Use this skill when users:

  • Need to search for code patterns using structural matching (e.g., "find all async functions that don't have error handling")
  • Want to locate specific language constructs (e.g., "find all function calls with specific parameters")
  • Request searches that require understanding code structure rather than just text
  • Ask to search for code with particular AST characteristics
  • Need to perform complex code queries that traditional text search cannot handle

Step 0: Check the binary before anything else

Run this first, every time:

command -v ast-grep

If it prints nothing, ast-grep is not installed. Say so and stop. Tell the operator to install it, then wait. Do not draft a rule, and do not write a test file. Every command below fails without the binary.

Never accept sg as proof that ast-grep is present. Upstream ships sg as a short alias, but on Ubuntu /usr/bin/sg is a different program from the login package. It runs a command under another group ID, through /bin/sh. MEASURED on this machine 2026-09-02: ast-grep was absent while command -v sg still resolved. A check written against sg therefore reports a healthy install. Every command after it then fails.

The same confusion reached the tool grant. This skill's allowed-tools carried Bash(sg:*) until 2026-09-02. A grant is a grant and never a limit, so that line permitted sg <group> -c "<any command>", which is a general command runner. Nothing in this skill or its two reference files ever invoked sg, so the grant bought nothing. It is removed. Do not put it back.

Read the full file on GitHub · 218 lines

Files

What ships with it

2 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. 6d ago Changed · +25 lines abe6872a371b
  2. 10d ago First seen · 193 lines · 80 tokens per session scan A a9e0262b6e5a

Subscribe to this mod's changes

ast-grep is a skill published in the GitHub repository mishahanin/heading-os (11 stars, last pushed yesterday), licensed Apache-2.0. It adds 80 tokens to every session and 2,105 once invoked, about $0.0004 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-30.