ast-grep

ast-grep is a skill for Claude Code, Codex from wunki/dotfiles. It costs 70 tokens per session (776 once invoked), scanned A, original, MIT.

A tool for searching and analyzing code by its syntax and structure, rather than only matching text. It can also help plan safe code rewrites.

In plain words
What is it for?
Use it to find functions, components, imports, or repeated code shapes; inspect their usage; create search rules; and plan structural refactors.
Why use it?
Text search can miss structural matches or find unrelated text. Syntax-aware searches are more precise for code patterns.

Skill for Claude CodeCodex

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

Good fit Use it to find functions, components, imports, or repeated code shapes; inspect their usage; create search rules; and plan structural refactors.

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

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/wunki/dotfiles/ast-grep/github.svg)](https://agentmods.dev/skills/wunki/dotfiles/ast-grep)
Your own site
<a href="https://agentmods.dev/skills/wunki/dotfiles/ast-grep"><img src="https://agentmods.dev/badge/skills/wunki/dotfiles/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/wunki/dotfiles/ast-grep"><img src="https://agentmods.dev/badge/skills/wunki/dotfiles/ast-grep.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 70 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 776 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.00070 $0.00776
Opus 5.5 $0.00028 $0.00310
Sonnet 5.5 $0.00014 $0.00155
Haiku 4.5 $0.00007 $0.00078

Measured 1mo ago against content hash 9f050a64f883, 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 1mo 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.

agents/skills/ast-grep/SKILL.md · 89 lines

How it starts

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

Use ast-grep (sg) when the task depends on code structure: calls, imports, functions, components, conditionals, object literals, nested constructs, or safe repeated rewrites.

Prefer rg for plain text/content search.

Default commands

Check availability:

ast-grep --version || sg --version

Search by AST pattern:

ast-grep run --lang <language> -p '<pattern>' [path]
# short form when sg is installed:
sg run --lang <language> -p '<pattern>' [path]

Use JSON when output may be parsed or large:

ast-grep run --lang ts -p 'console.log($$$ARGS)' --json=stream

Preview rewrites before applying:

ast-grep run --lang js -p 'var $NAME = $VALUE' -r 'let $NAME = $VALUE'
ast-grep run --lang js -p 'var $NAME = $VALUE' -r 'let $NAME = $VALUE' --update-all

Only use --update-all after inspecting the preview.

Pattern reminders

  • Patterns should look like real source code in the target language.
  • $A captures one AST node.
  • $$$ARGS captures zero or more nodes.
  • Always set --lang explicitly (js, ts, jsx, tsx, json, yaml, python, go, rust, etc.).
  • Quote patterns with single quotes to avoid shell expansion.
  • If a pattern fails unexpectedly, inspect it with --debug-query=ast.

Common patterns

# console calls
ast-grep run --lang ts -p 'console.log($$$ARGS)'

# function declarations
ast-grep run --lang ts -p 'function $NAME($$$ARGS) { $$$BODY }'

# React hook usage
ast-grep run --lang tsx -p 'useEffect($$$ARGS)'

# imports from a package
ast-grep run --lang ts -p 'import { $$$IMPORTS } from "$PKG"'

# YAML key/value shape
ast-grep run --lang yaml -p '$KEY: $VALUE'

Rule workflow

For complex searches or reusable rules:

  1. Start from a small code example that should match.
  2. Write the simplest working -p pattern first.
  3. Add YAML rule constraints only after the basic pattern works.
  4. Use --json=stream and/or --debug-query=ast to inspect matches.
  5. If it fails, remove constraints and debug one condition at a time.
  6. Preview rewrites; apply only after reviewing matches.

Read the full file on GitHub · 89 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. 1mo ago First seen · 89 lines · 70 tokens per session scan A 9f050a64f883

Subscribe to this mod's changes

ast-grep is a skill published in the GitHub repository wunki/dotfiles (47 stars, last pushed 5d ago), licensed MIT. It adds 70 tokens to every session and 776 once invoked, about $0.0003 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.

Related

Other skills, from other repositories

diagnose-ci

Investigate failing REMOTE CI runs on GitHub Actions: find the failed run, pull the failed-step logs with gh, identify the root cause (compile error, test failure, lint, missing secret, timeout), and recommend a fix. Read-only: it does not commit, push, or edit. Use when CI is red, a GitHub Actions run failed, or the…

urmzd/dotfiles · 130 tokens

triage-dotfiles-env

Playbook of known failure modes in this dotfiles stack: pipx "bad interpreter" after Python rebuilds, gpg commit-signing failures, direnv/nix shellHook running bash instead of zsh, Powerlevel10k instant-prompt warnings, and Neovim plugin errors from removed Lua APIs. Use when a shell startup error, git signing…

urmzd/dotfiles · 138 tokens

fix-and-retry

Diagnose a failing CI run, apply the code fix, commit it, push, and watch the re-run until it passes or fails -- the full fix-and-retry loop in one shot. Use after a pipeline fails and the user says "fix it and retry", "fix the CI and push", or "make CI green". Do NOT use for a read-only investigation that stops at a…

urmzd/dotfiles · 106 tokens

diagnose-runtime

Triage LOCAL runtime failures on your own machine: crashes and errors, hangs and deadlocks, slowness and high CPU/memory, and hardware/serial/USB issues. Method: reproduce, isolate (bisect, log, strace/dtruss, sample), form a hypothesis, verify the fix holds. Read-mostly: it inspects processes and logs, it does not…

urmzd/dotfiles · 171 tokens

save-debug-experience

Record a debugging session's findings into a timestamped markdown file under debugexperience/. Captures problem, root cause, solution, and key learnings in a structured, reusable format. Use when: you've just resolved a non-obvious bug, found an undocumented edge case, encountered an issue that took multiple attempts…

magic3007/dotfiles · 113 tokens

heap-snapshot-inspection

Investigating memory issues and leaks in Chromium-based environments (Chrome, Node.js, Electron) using heap snapshots and the @paulirish/agents CLI.

paulirish/dotfiles · 37 tokens