ast-grep-patterns

ast-grep-patterns is a skill for Claude Code from FlorianBruniaux/claude-code-plugins. It costs 85 tokens per session (1,569 once invoked), scanned A, original, MIT.

A structural code-search and refactoring method that matches the shape of code rather than its exact formatting. It uses ast-grep, a tool that reads code syntax, to find or rewrite matching patterns across files.

In plain words
What is it for?
Use it to find code patterns and apply tested structural rewrites across a repository. It is intended for repeated or large-scale changes rather than a one-off text lookup.
Why use it?
It avoids fragile text searches when code has different spacing or formatting. It is useful for broad changes such as renaming calls, changing function signatures, or migrating an API.

Skill for Claude Code

Written for Claude Code: effort in frontmatter.

Part of the code-quality plugin — 17 skills, 6 agents shipped together

Good fit Use it to find code patterns and apply tested structural rewrites across a repository. It is intended for repeated or large-scale changes rather than a one-off text lookup.

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

Made for: Claude Code.

Or install code-quality, the plugin that ships this one along with the rest of its 17 skills, 6 agents.

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-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/florianbruniaux/claude-code-plugins/ast-grep-patterns/github.svg)](https://agentmods.dev/skills/florianbruniaux/claude-code-plugins/ast-grep-patterns)
Your own site
<a href="https://agentmods.dev/skills/florianbruniaux/claude-code-plugins/ast-grep-patterns"><img src="https://agentmods.dev/badge/skills/florianbruniaux/claude-code-plugins/ast-grep-patterns/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-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/florianbruniaux/claude-code-plugins/ast-grep-patterns"><img src="https://agentmods.dev/badge/skills/florianbruniaux/claude-code-plugins/ast-grep-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 85 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,569 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.00085 $0.01569
Opus 5.5 $0.00034 $0.00628
Sonnet 5.5 $0.00017 $0.00314
Haiku 4.5 $0.00009 $0.00157

Measured 4d ago against content hash a4fd18044cf1, 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-patterns 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 4d 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.

plugins/code-quality/skills/ast-grep-patterns/SKILL.md · 197 lines

How it starts

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

ast-grep patterns

ast-grep matches code by syntax tree, so it survives formatting differences and needs no regex escaping. The patterns below were run against ast-grep 0.51.3 on small TypeScript and TSX samples. Test each one on a small file before running it across a repository.

Install

brew install ast-grep            # or: npm install --global @ast-grep/cli
ast-grep --version

The binary is ast-grep (alias sg). An optional agent skill is published at ast-grep/agent-skill (install command not verified here).

When to use it

Request Tool
Find a string, a name, an import Grep
Find code by meaning ("where is auth handled") A semantic search tool such as grepai, or an LSP or symbol-aware MCP server
Find or rewrite code by structure ast-grep
Rename every call, change an API signature, migrate a framework ast-grep

For a small project or a one-off lookup, Grep is enough. ast-grep pays off when the same structural change touches many files.

Quick commands

# One-off pattern ($X = one node, $$$X = zero or more nodes)
ast-grep run -p 'console.log($$$ARGS)' -l ts src/

# Rewrite (preview first, then add --update-all to apply)
ast-grep run -p 'oldApi($A)' -r 'newApi($A)' -l ts src/

# Run a YAML rule file
ast-grep scan -r rules/async-no-try.yml src/

# Machine-readable output
ast-grep run -p 'class $C extends React.Component { $$$ }' -l tsx --json=compact src/

# Print the syntax tree of a pattern when it does not match
ast-grep run --debug-query=ast -p 'foo($A)' -l ts

The language is required for run; use ts for .ts files and tsx for .tsx files, because a rule written for one does not scan the other.

Rule recipes

Each recipe is saved as a rule file (id, language, rule) and run with ast-grep scan -r <file> <path>.

Async functions without try/catch

id: async-no-try
language: tsx
rule:
  pattern: async function $F($$$P) { $$$B }
  not:
    has:
      kind: try_statement
      stopBy: end

Read the full file on GitHub · 197 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. 4d ago First seen · 197 lines · 85 tokens per session scan A a4fd18044cf1

Subscribe to this mod's changes

ast-grep-patterns is a skill published in the GitHub repository FlorianBruniaux/claude-code-plugins (47 stars, last pushed 5d ago), licensed MIT. It adds 85 tokens to every session and 1,569 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-11-26.

Related

ast-grep-patterns compared with skills from other repositories

ast-grep-patterns next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
ast-grep-patternsFlorianBruniaux/claude-code-pluginsSkill475d agoMITA85Claude Code
oraclesteipete/oracleSkill4.1k3d agoMITA18Claude Code, Codex
review-loopsangrokjung/claude-forgeSkill8862mo agoMITA100Claude Code
pentest-forensicsfatihkan/badiSkill81mo agoMITA60Claude Code
pentest-malwarefatihkan/badiSkill81mo agoMITA69Claude Code
security-checkfatihkan/badiSkill81mo agoMITA91Claude Code
bughunterirfad7/claude-power-skillsSkill44mo agoMITA103Claude Code