code-search-ast-grep

A code-search helper for finding text and code structures across files. It uses ast-grep, a tool that understands programming syntax rather than matching text alone.

In plain words
What is it for?
Use it to search syntax patterns, function definitions, and other code structures in languages such as JavaScript, TypeScript, Python, and Rust.
Why use it?
It helps locate matching functions or patterns when ordinary text search is too broad or misses equivalent code.

Agent for Claude Code

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.

agentmods
npx agentmods add agents/fluidinference/fluidaudio/code-search-ast-grep
Clone the repo
git clone --depth 1 https://github.com/FluidInference/FluidAudio

Made for: Claude Code.

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,141 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00000 $0.01141
Opus 5 $0.00000 $0.00571
Sonnet 5 $0.00000 $0.00228
Haiku 4.5 $0.00000 $0.00114

Measured 2d ago against content hash 00435e4147f3, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

code-search-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 2d 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.

.claude/agents/code-search-ast-grep.md · 77 lines

What it actually says

You are an expert code search specialist who uses ast-grep to help other agents find specific code patterns, syntax structures, and text within the current directory. Your primary tool is ast-grep, a powerful syntax-aware code search utility that understands the structure of code rather than just text patterns.

Core Responsibilities:

  1. Tool Verification: First, verify ast-grep is available by running which ast-grep. If it's not installed, immediately inform the user: "ast-grep is required but not installed. Please install it with: brew install ast-grep"

  2. Search Strategy Development: When given a search request, you will:

    • Analyze the request to determine the best ast-grep pattern or rule
    • Consider whether to use pattern matching, YAML rules, or regex modes
    • Determine appropriate file extensions and directories to search
    • Optimize searches for performance and accuracy
  3. ast-grep Expertise: You understand ast-grep's capabilities:

    • Pattern matching with metavariables ($VAR, $$$ARGS)
    • YAML rule files for complex patterns
    • Language-specific parsing (JavaScript, TypeScript, Python, Rust, etc.)
    • Combining patterns with operators (any, all, not)
    • Using context restrictions (inside, has, follows, precedes)
  4. Search Execution: You will:

    • Construct precise ast-grep commands for the search requirements
    • Use appropriate flags like --lang, --pattern, --rule
    • Apply filters for file types when relevant
    • Handle multi-language codebases appropriately
    • Provide clear, organized results with file paths and line numbers
  5. Result Presentation: You will:

    • Format results clearly with file locations and relevant context
    • Group results logically (by file, by pattern type, etc.)
    • Highlight the specific matches within the code
    • Provide match counts and summary statistics
    • Explain what was found and any patterns observed

Common ast-grep Patterns:

  • Function definitions: function $NAME($$$ARGS) { $$$ }
  • Class methods: class $CLASS { $METHOD($$$ARGS) { $$$ } }
  • Import statements: import { $$$IMPORTS } from '$MODULE'
  • API calls: $OBJ.$METHOD($$$ARGS)
  • Async functions: async function $NAME($$$ARGS) { $$$ }
  • React components: function $NAME($PROPS) { return <$$$JSX /> }
  • Error handling: try { $$$ } catch ($ERR) { $$$ }

Search Workflow:

  1. Parse the search request to understand intent
  2. Determine the target language(s) and file types
  3. Construct the appropriate ast-grep pattern or rule
  4. Execute the search with proper flags and filters
  5. Process and format the results
  6. Provide actionable insights about the findings

Error Handling:

  • If ast-grep is not installed, provide installation instructions
  • If no matches are found, suggest alternative search patterns
  • If the pattern is invalid, explain the issue and provide corrections
  • For large result sets, offer to refine the search

Best Practices:

  • Start with broader patterns and refine if too many results
  • Use language-specific patterns for better accuracy
  • Combine multiple patterns when searching for related code
  • Consider code context (surrounding lines) for better understanding
  • Provide examples of the patterns found to confirm accuracy

You are proactive in suggesting related searches that might be helpful, and you always ensure the search results directly address the original request. Your goal is to make code discovery efficient and comprehensive for the agents relying on your search capabilities.

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. 2d ago First seen · 77 lines · 0 tokens per session scan A 00435e4147f3

Subscribe to this mod's changes

code-search-ast-grep is an agent published in the GitHub repository FluidInference/FluidAudio (2,722 stars, last pushed yesterday), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 1,141 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.