ast-grep

ast-grep is a skill for Claude Code from bahayonghang/my-ai-cli-toolkit. It costs 64 tokens per session (1,427 once invoked), scanned A, original, MIT.

Guidance for searching and checking source code by its syntax and structure, rather than only matching written text. ast-grep is a tool that uses a code tree to find patterns such as calls inside particular functions.

In plain words
What is it for?
Writing and validating ast-grep rules, finding specific function or call patterns, checking decorators and nested code, and locating constructs across supported programming languages.
Why use it?
Plain text search can miss code that is formatted differently or match code in the wrong context. Structural searches make these findings more precise and can reveal refactoring targets.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Good fit Writing and validating ast-grep rules, finding specific function or call patterns, checking…

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

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/bahayonghang/my-ai-cli-toolkit/ast-grep.svg)](https://agentmods.dev/skills/bahayonghang/my-ai-cli-toolkit/ast-grep)
Your own site
<a href="https://agentmods.dev/skills/bahayonghang/my-ai-cli-toolkit/ast-grep"><img src="https://agentmods.dev/badge/skills/bahayonghang/my-ai-cli-toolkit/ast-grep.svg" alt="Measured on agentmods" height="20"></a>
Per session 64 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,427 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.00064 $0.01427
Opus 5 $0.00032 $0.00714
Sonnet 5 $0.00013 $0.00285
Haiku 4.5 $0.00006 $0.00143

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

skills/developer-tools-integrations/ast-grep/SKILL.md · 192 lines

How it starts

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

Use ast-grep when the user needs code structure, not just text. The useful outcome is a validated rule plus a clear statement of what it matches and what it may miss.

Triage

Start with the smallest tool that can answer the question.

  • Use rg for exact names, strings, comments, or simple text.
  • Use language tooling for semantic facts such as type resolution, references, imports, or rename safety.
  • Use ast-grep for syntax shape: descendants, ancestors, call forms, decorators, missing constructs, nested contexts, or multi-language structural searches.

If ast-grep is not installed, say so and offer an rg fallback only when the fallback will not pretend to be structural.

Workflow

  1. Identify the language and target files.

    • Infer from paths and extensions when possible.
    • Ask only if the language or include/exclude scope cannot be inferred.
  2. Write a tiny fixture before searching the real repository.

    • Include at least one positive example.
    • Add a negative example when false positives would be costly.
  3. Start with the simplest pattern.

    • Use ast-grep run --pattern ... --lang ... for a single-node search.
    • Move to a YAML rule when the search needs has, inside, not, any, all, regex, nthChild, or reusable metadata.
  4. Debug the parsed structure when the first rule misses.

    • Use ast-grep run --pattern '<sample code>' --lang <lang> --debug-query=ast.
    • --debug-query prints diagnostic output and may exit non-zero; treat the printed tree as useful debug output, not as a failed repository search.
  5. Validate on the fixture before running on the repository.

    • Keep the rule as simple as possible until it matches the fixture.
    • Then scan the real path and report expected false-negative boundaries.
  6. Report the final rule, command, and caveats.

    • Name node kinds or language constructs intentionally excluded.
    • Prefer JSON output when a downstream script will consume matches.

Read the full file on GitHub · 192 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. 7d ago First seen · 192 lines · 64 tokens per session scan A e1299a8af6da

Subscribe to this mod's changes

ast-grep is a skill published in the GitHub repository bahayonghang/my-ai-cli-toolkit (16 stars, last pushed yesterday), licensed MIT. It adds 64 tokens to every session and 1,427 once invoked, about $0.0003 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.

Related

Other skills, from other repositories

sensegrep-cli

Semantic-first code discovery via the sensegrep CLI. Default to sensegrep search for behavior, concepts, structure, and exploration; reserve sensegrep literal for known exact strings, regexes, exhaustive occurrence audits, or verification after discovery.

Stahldavid/sensegrep · 50 tokens

sensegrep

Semantic-first code discovery via MCP. Default to sensegrepsearch for behavior, concepts, structure, and exploration; reserve sensegrepliteral for known exact strings, regexes, exhaustive occurrence audits, or verification after discovery.

Stahldavid/sensegrep · 46 tokens

ccc

This skill should be used when code search is needed (whether explicitly requested or as part of completing a task), when indexing the codebase after changes, or when the user asks about ccc, cocoindex-code, or the codebase index. Trigger phrases include 'search the codebase', 'find code related to', 'update the…

cocoindex-io/cocoindex-code · 80 tokens

health-check

Get an overall Python code quality health score using pyscn. Use when user asks how healthy or good the code is, wants a quality overview, a grade, a summary of technical debt, or a before/after quality comparison.

ludo-technologies/pyscn · 49 tokens

x-ray

Deep codebase exploration using semantic search and relationship mapping. Use when you need to understand the current codebase.

bartolli/codanna · 25 tokens

bloat-detector

Detects codebase bloat via dead code, duplication, complexity, and doc bloat scans. Use when codebase feels large or before a release.

athola/claude-night-market · 36 tokens