use-ast-grep

use-ast-grep is a command for Claude Code from automazeio/claude-code-for-power-users. It costs 0 tokens per session (1,080 once invoked), scanned A, original, MIT.

Instructions for using ast-grep, a code-search tool that understands program structure, when ordinary text search is not enough. It can match functions, classes, assignments, and imports according to their code shape.

In plain words
What is it for?
It helps find code patterns, rename or update code safely, analyze usages, and search across languages such as Ruby and TypeScript in a monorepo, which is one repository containing multiple projects.
Why use it?
Plain text search can miss code that is written differently but has the same structure, and it can produce unrelated matches. Structural search makes these investigations and refactors more targeted.

Command for Claude Code

Written for Claude Code: a Claude Code command (commands/*.md). Also seen: mentions Cursor.

Good fit It helps find code patterns, rename or update code safely, analyze usages, and search across languages such as Ruby and TypeScript in a monorepo, which is one repository containing multiple projects.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/automazeio/claude-code-for-power-users/use-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.

Clone the repo
git clone --depth 1 https://github.com/automazeio/claude-code-for-power-users

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 use-ast-grep

README.md
[![agentmods](https://agentmods.dev/badge/commands/automazeio/claude-code-for-power-users/use-ast-grep.svg)](https://agentmods.dev/commands/automazeio/claude-code-for-power-users/use-ast-grep)
Your own site
<a href="https://agentmods.dev/commands/automazeio/claude-code-for-power-users/use-ast-grep"><img src="https://agentmods.dev/badge/commands/automazeio/claude-code-for-power-users/use-ast-grep.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,080 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.00000 $0.01080
Opus 5 $0.00000 $0.00540
Sonnet 5 $0.00000 $0.00216
Haiku 4.5 $0.00000 $0.00108

Measured 7d ago against content hash eca18d8111d0, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

use-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.

commands/use-ast-grep.md · 107 lines

How it starts

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

AST-Grep Integration Protocol for Cursor Agent

When to Use AST-Grep

Use ast-grep (if installed) instead of plain regex or text search when:

  • Structural code patterns are involved (e.g., finding all function calls, class definitions, or method implementations)
  • Language-aware refactoring is required (e.g., renaming variables, updating function signatures, or changing imports)
  • Complex code analysis is needed (e.g., finding all usages of a pattern across different syntactic contexts)
  • Cross-language searches are necessary (e.g., working with both Ruby and TypeScript in a monorepo)
  • Semantic code understanding is important (e.g., finding patterns based on code structure, not just text)

AST-Grep Command Patterns

Basic Search Template:

ast-grep --pattern '$PATTERN' --lang $LANGUAGE $PATH

Common Use Cases

  • Find function calls: ast-grep --pattern 'functionName($$$)' --lang javascript .
  • Find class definitions: ast-grep --pattern 'class $NAME { $$$ }' --lang typescript .
  • Find variable assignments: ast-grep --pattern '$VAR = $$$' --lang ruby .
  • Find import statements: ast-grep --pattern 'import { $$$ } from "$MODULE"' --lang javascript .
  • Find method calls on objects: ast-grep --pattern '$OBJ.$METHOD($$$)' --lang typescript .
  • Find React hooks: ast-grep --pattern 'const [$STATE, $SETTER] = useState($$$)' --lang typescript .
  • Find Ruby class definitions: ast-grep --pattern 'class $NAME < $$$; $$$; end' --lang ruby .

Pattern Syntax Reference

  • $VAR — matches any single node and captures it
  • $$$ — matches zero or more nodes (wildcard)
  • $$ — matches one or more nodes
  • Literal code — matches exactly as written

Supported Languages

  • javascript, typescript, ruby, python, go, rust, java, c, cpp, html, css, yaml, json, and more

Integration Workflow

Before using ast-grep:

  1. Check if ast-grep is installed: If not, skip and fall back to regex/semantic search.
    command -v ast-grep >/dev/null 2>&1 || echo "ast-grep not installed, skipping AST search"
    
  2. Identify if the task involves structural code patterns or language-aware refactoring.
  3. Determine the appropriate language(s) to search.
  4. Construct the pattern using ast-grep syntax.
  5. Run ast-grep to gather precise structural information.
  6. Use results to inform code edits, refactoring, or further analysis.

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

Subscribe to this mod's changes

use-ast-grep is a command published in the GitHub repository automazeio/claude-code-for-power-users (220 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,080 tokens. 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.