ast-grep

ast-grep is a skill for Claude Code, Codex from fmind/dot. It costs 19 tokens per session (1,118 once invoked), scanned A, original, MIT.

A code search and rewrite tool that understands a program’s structure rather than matching plain text. It uses patterns with placeholders to find code while ignoring formatting, comments, and strings.

In plain words
What is it for?
Use it to search code by syntax, define lint rules, preview changes, apply bulk refactors, and produce machine-readable results.
Why use it?
It avoids false matches from text search and makes broad code changes more precise across many files or call sites.

Skill for Claude CodeCodex

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

Good fit Use it to search code by syntax, define lint rules, preview changes, apply bulk refactors, and produce machine-readable results.

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

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/fmind/dot/ast-grep/github.svg)](https://agentmods.dev/skills/fmind/dot/ast-grep)
Your own site
<a href="https://agentmods.dev/skills/fmind/dot/ast-grep"><img src="https://agentmods.dev/badge/skills/fmind/dot/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/fmind/dot/ast-grep"><img src="https://agentmods.dev/badge/skills/fmind/dot/ast-grep.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 19 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,118 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.00019 $0.01118
Opus 5.5 $0.00008 $0.00447
Sonnet 5.5 $0.00004 $0.00224
Haiku 4.5 $0.00002 $0.00112

Measured 14d ago against content hash c8c9bd70442f, 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.

skills/ast-grep/SKILL.md · 54 lines

How it starts

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

ast-grep

Structural code search and rewrite: a pattern is real code with meta-variables, matched against the syntax tree. A call-expression pattern distinguishes a call from similar text inside a string or comment; string and comment nodes can also be matched deliberately. Use it where rg gives false positives; plain text search stays with rg.

Commands

ast-grep outline -l python src/                                                 # symbols, imports, and members per file
ast-grep run -p 'print($$$ARGS)' -l python src/                                      # scope search to the relevant source
ast-grep run -p 'print($$$ARGS)' -r 'logger.info($$$ARGS)' -l python src/             # dry run: prints the diff, changes nothing
ast-grep run -p 'print($$$ARGS)' -r 'logger.info($$$ARGS)' -l python --update-all src/ # apply after reviewing the dry run (-i to confirm per hunk)
ast-grep run -p 'os.getenv($KEY)' -l python --json=compact src/                       # structured output after narrowing paths
ast-grep scan                                                                    # every rule in sgconfig.yml
ast-grep scan -r rules/no-print.yml --format github                              # one rule file; GitHub annotations in CI

Workflow

  1. Write the pattern as code: $NAME matches one node, $$$NAME a sequence (arguments, statements), $_ a node without binding; always pass -l <lang> so the pattern parses in the right grammar, and use --debug-query=ast when a pattern that should match does not.
  2. Search first: map unfamiliar files with ast-grep outline before reading full source; pass the relevant path or --globs; use --files-with-matches when only filenames are needed, then read selected matches with -C 2. Use JSON only for structured processing. Widen scope deliberately, and use --no-ignore vcs (or hidden; the flag requires a value) only when skipped files are relevant.
  3. Rewrite in two steps: add -r to see the diff, then --update-all (or -i for an interactive session); captured meta-variables are reused in the replacement.
  4. Promote to a rule: for a lint or a repeated refactor, ast-grep new project scaffolds sgconfig.yml and rules/; a rule file has id, language, rule (pattern, kind, inside, has, not), optional fix, severity, and message; ast-grep test runs its valid and invalid cases.
  5. Wire into the gate: run ast-grep scan inside check:lint (see mise) so hooks and CI apply the same rules.

Read the full file on GitHub · 54 lines

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 c8c9bd70442f
  2. 15d ago Changed · +1 lines · +1 tokens per session 1d94a9193ee1
  3. 23d ago Changed 4873b050e5a9
  4. 26d ago Changed · +1 lines eabfd47020fe
  5. 1mo ago Changed · +1 lines · -25 tokens per session 62138cb71c09
  6. 1mo ago Changed · +1 lines 512e97bed462
  7. 1mo ago Changed · -7 lines 05023224d2bb
  8. 1mo ago First seen · 57 lines · 43 tokens per session scan A 0762aa76e687

Subscribe to this mod's changes

ast-grep is a skill published in the GitHub repository fmind/dot (12 stars, last pushed today), licensed MIT. It adds 19 tokens to every session and 1,118 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-09-03.

Related

Other skills, from other repositories

diff-review

Inspect changed code in an exact diff, patch, branch, PR, or candidate for correctness defects. Use for pre-merge or self-review, spec compliance, test gaps, and regression risk — not whole-repo audit, release go/no-go, or plan review.

fmind/dotfiles · 57 tokens

repository-review

Audit a whole repository across architecture, source, tests, tooling, security, CI/CD, docs, and releases. Use for cross-cutting audits, readiness, or technical-debt reviews with ranked findings — not one diff or release candidate.

fmind/dotfiles · 51 tokens

systematic-debugging

Diagnose unknown-cause bugs, test/build or auth failures, flakes, and runtime performance regressions. Investigate, reduce, localize, falsify hypotheses, and explain root cause before implementation.

fmind/dotfiles · 45 tokens

dotfiles-bootstrap

Bootstrap a workstation with the dotfiles framework. Takes a GitHub user / owner+repo / explicit clone URL and runs dot init (which shells out to chezmoi) with the right safety prompts. Honors the active agent profile (ask / plan / apply / audit) so it defaults to dry-run in safer modes and full apply in apply.

sebastienrousseau/dotfiles · 88 tokens

vibe

Delegate a coding task to a cheap AI model (Mistral Vibe by default, but any provider Vibe knows about — DeepSeek, Gemini Flash, etc.) and supervise the result via git diff. Claude orchestrates, the cheap model codes. Claude consumes 500-1500 tokens per delegation regardless of how many file reads the delegate does…

sebastienrousseau/dotfiles · 137 tokens

poke-holes

Adversarial verification with three competing agents (issue-finder, disprover, judge). Triggers "double check", "are you sure", "poke holes", or a critical fix before production.

darkroomengineering/cc-settings · 44 tokens