Agent skill

Structural Code Search with ast-grep

by warp-drive-data in warp-drive-data/warp-drive

Turns natural-language code queries into ast-grep rules for structural search, testing each rule against an example file before running it on a codebase.

MITAuto-check passedDevelopment

Install Structural Code Search with ast-grep

skills CLI
$ npx skills add warp-drive-data/warp-drive --skill ast-grep -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install warp-drive-data/warp-drive ast-grep --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/warp-drive-data/warp-drive.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/ast-grep .claude/skills/ast-grep && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
ast-grep
GitHub stars
3.2k
Used in
5 other repos
Token cost
~2.4k tokens
SKILL.md length
835 words
Files
2 (incl. references)
Skills in repo
3
Repo updated
First seen
Licence
MIT

At a glance

Turns natural-language code queries into ast-grep rules for structural search, testing each rule against an example file before running it on a codebase.

  • Works in 5 steps: Understand the Query → Create Example Code → Write the ast-grep Rule → …
  • Finding every async function without error handling across a codebase
  • SKILL.md covers Overview, When to Use This Skill, General Workflow and ast-grep CLI Commands, plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

ast-grep matches code by its syntax tree rather than plain text, so it can answer questions such as which async functions lack error handling or which calls use particular arguments. The skill converts a request into a rule through a fixed workflow: clarify what to find and in which language, write a small example snippet to a temporary file, write the rule starting simple, test it against the example, and then search the real code.

Key principles are to set stopBy: end on relational rules such as inside and has so the search runs to the end of its direction, to use pattern for simple structures and kind with has or inside for complex ones, and to break big queries into sub-rules with all, any and not. Rules can be tested inline for quick iteration or from a rule file such as test_rule.yml, and references/rule_reference.md holds the full rule documentation. It also applies when working with @ast-grep/napi.

When your agent uses it

  • Finding every async function without error handling across a codebase
  • Locating calls to a function with particular arguments
  • Writing and debugging a new ast-grep rule in YAML
  • Code queries that plain text search cannot express

Example prompts

  • “Find all async functions in src that use await but have no try/catch.”
  • “Write an ast-grep rule for React components that call useEffect without a dependency array.”
  • “Test this ast-grep rule against my example file and tighten it until it matches only the intended code.”

Requirements

  • The ast-grep CLI

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Understand the Query
  2. Create Example Code
  3. Write the ast-grep Rule
  4. Test the Rule
  5. Search the Codebase

What it can do on your machine

Read from SKILL.md and the folder at commit 34ad57e. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are bash, yaml and javascript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Structural Code Search with ast-grep loads about 2.4k tokens when it runs, and up to ~5k if it reads all its reference files. Until then it costs about 120 tokens; SKILL.md has 835 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~120
When it runs · the whole SKILL.md, loaded when a task matches
~2.4k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from warp-drive-data/warp-drive at commit 34ad57e, republished under its MIT licence (© warp-drive-data). 835 words, ~2,370 tokens.

Download SKILL.mdSave it as .claude/skills/ast-grep/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
ast-grep
description
Guide for writing ast-grep rules to perform structural code search and analysis. Use when users need to search codebases using Abstract Syntax Tree (AST) patterns, find specific code structures, write new rules, working with @ast-grep/napi or perform complex code queries that go beyond simple text search. This skill should be used when users ask to search for code patterns, find specific language constructs, or locate code with particular structural characteristics.

Overview

This skill helps translate natural language queries into ast-grep rules for structural code search. ast-grep uses Abstract Syntax Tree (AST) patterns to match code based on its structure rather than just text, enabling powerful and precise code search across large codebases.

When to Use This Skill

Use this skill when users:

  • Need to search for code patterns using structural matching (e.g., "find all async functions that don't have error handling")
  • Want to locate specific language constructs (e.g., "find all function calls with specific parameters")
  • Request searches that require understanding code structure rather than just text
  • Ask to search for code with particular AST characteristics
  • Need to perform complex code queries that traditional text search cannot handle

General Workflow

Follow this process to help users write effective ast-grep rules:

Step 1: Understand the Query

Clearly understand what the user wants to find. Ask clarifying questions if needed:

  • What specific code pattern or structure are they looking for?
  • Which programming language?
  • Are there specific edge cases or variations to consider?
  • What should be included or excluded from matches?
Step 2: Create Example Code

Write a simple code snippet that represents what the user wants to match. Save this to a temporary file for testing.

Example: If searching for "async functions that use await", create a test file:

javascript
// test_example.js
async function example() {
  const result = await fetchData();
  return result;
}
Step 3: Write the ast-grep Rule

Translate the pattern into an ast-grep rule. Start simple and add complexity as needed.

Key principles:

  • Always use stopBy: end for relational rules (inside, has) to ensure search goes to the end of the direction
  • Use pattern for simple structures
  • Use kind with has/inside for complex structures
  • Break complex queries into smaller sub-rules using all, any, or not

Example rule file (test_rule.yml):

yaml
id: async-with-await
language: javascript
rule:
  kind: function_declaration
  has:
    pattern: await $EXPR
    stopBy: end

See references/rule_reference.md for comprehensive rule documentation.

Step 4: Test the Rule

Use ast-grep CLI to verify the rule matches the example code. There are two main approaches:

Option A: Test with inline rules (for quick iterations)

bash
echo "async function test() { await fetch(); }" | ast-grep scan --inline-rules "id: test
language: javascript
rule:
  kind: function_declaration
  has:
    pattern: await \$EXPR
    stopBy: end" --stdin

Option B: Test with rule files (recommended for complex rules)

bash
ast-grep scan --rule test_rule.yml test_example.js

Debugging if no matches:

  1. Simplify the rule (remove sub-rules)
  2. Add stopBy: end to relational rules if not present
  3. Use --debug-query to understand the AST structure (see below)
  4. Check if kind values are correct for the language
Step 5: Search the Codebase

Once the rule matches the example code correctly, search the actual codebase:

For simple pattern searches:

bash
ast-grep run --pattern 'console.log($ARG)' --lang javascript /path/to/project

For complex rule-based searches:

bash
ast-grep scan --rule my_rule.yml /path/to/project

For inline rules (without creating files):

bash
ast-grep scan --inline-rules "id: my-rule
language: javascript
rule:
  pattern: \$PATTERN" /path/to/project

ast-grep CLI Commands

Inspect Code Structure (--debug-query)

Dump the AST structure to understand how code is parsed:

bash
ast-grep run --pattern 'async function example() { await fetch(); }' \
  --lang javascript \
  --debug-query=cst

Available formats:

  • cst: Concrete Syntax Tree (shows all nodes including punctuation)
  • ast: Abstract Syntax Tree (shows only named nodes)
  • pattern: Shows how ast-grep interprets your pattern

Use this to:

  • Find the correct kind values for nodes
  • Understand the structure of code you want to match
  • Debug why patterns aren't matching

Example:

bash
# See the structure of your target code
ast-grep run --pattern 'class User { constructor() {} }' \
  --lang javascript \
  --debug-query=cst

# See how ast-grep interprets your pattern
ast-grep run --pattern 'class $NAME { $$$BODY }' \
  --lang javascript \
  --debug-query=pattern
Test Rules (scan with --stdin)

Test a rule against code snippet without creating files:

bash
echo "const x = await fetch();" | ast-grep scan --inline-rules "id: test
language: javascript
rule:
  pattern: await \$EXPR" --stdin

Add --json for structured output:

bash
echo "const x = await fetch();" | ast-grep scan --inline-rules "..." --stdin --json
Show full SKILL.md (344 more words)Show less
Search with Patterns (run)

Simple pattern-based search for single AST node matches:

bash
# Basic pattern search
ast-grep run --pattern 'console.log($ARG)' --lang javascript .

# Search specific files
ast-grep run --pattern 'class $NAME' --lang python /path/to/project

# JSON output for programmatic use
ast-grep run --pattern 'function $NAME($$$)' --lang javascript --json .

When to use:

  • Simple, single-node matches
  • Quick searches without complex logic
  • When you don't need relational rules (inside/has)
Search with Rules (scan)

YAML rule-based search for complex structural queries:

bash
# With rule file
ast-grep scan --rule my_rule.yml /path/to/project

# With inline rules
ast-grep scan --inline-rules "id: find-async
language: javascript
rule:
  kind: function_declaration
  has:
    pattern: await \$EXPR
    stopBy: end" /path/to/project

# JSON output
ast-grep scan --rule my_rule.yml --json /path/to/project

When to use:

  • Complex structural searches
  • Relational rules (inside, has, precedes, follows)
  • Composite logic (all, any, not)
  • When you need the power of full YAML rules

Tip: For relational rules (inside/has), always add stopBy: end to ensure complete traversal.

Tips for Writing Effective Rules

Always Use stopBy: end

For relational rules, always use stopBy: end unless there's a specific reason not to:

yaml
has:
  pattern: await $EXPR
  stopBy: end

This ensures the search traverses the entire subtree rather than stopping at the first non-matching node.

Start Simple, Then Add Complexity

Begin with the simplest rule that could work:

  1. Try a pattern first
  2. If that doesn't work, try kind to match the node type
  3. Add relational rules (has, inside) as needed
  4. Combine with composite rules (all, any, not) for complex logic
Use the Right Rule Type
  • Pattern: For simple, direct code matching (e.g., console.log($ARG))
  • Kind + Relational: For complex structures (e.g., "function containing await")
  • Composite: For logical combinations (e.g., "function with await but not in try-catch")
Debug with AST Inspection

When rules don't match:

  1. Use --debug-query=cst to see the actual AST structure
  2. Check if metavariables are being detected correctly
  3. Verify the node kind matches what you expect
  4. Ensure relational rules are searching in the right direction
Escaping in Inline Rules

When using --inline-rules, escape metavariables in shell commands:

  • Use \$VAR instead of $VAR (shell interprets $ as variable)
  • Or use single quotes: '$VAR' works in most shells

Example:

bash
# Correct: escaped $
ast-grep scan --inline-rules "rule: {pattern: 'console.log(\$ARG)'}" .

# Or use single quotes
ast-grep scan --inline-rules 'rule: {pattern: "console.log($ARG)"}' .

Common Use Cases

Find Functions with Specific Content

Find async functions that use await:

bash
ast-grep scan --inline-rules "id: async-await
language: javascript
rule:
  all:
    - kind: function_declaration
    - has:
        pattern: await \$EXPR
        stopBy: end" /path/to/project
Find Code Inside Specific Contexts

Find console.log inside class methods:

bash
ast-grep scan --inline-rules "id: console-in-class
language: javascript
rule:
  pattern: console.log(\$\$\$)
  inside:
    kind: method_definition
    stopBy: end" /path/to/project
Find Code Missing Expected Patterns

Find async functions without try-catch:

bash
ast-grep scan --inline-rules "id: async-no-trycatch
language: javascript
rule:
  all:
    - kind: function_declaration
    - has:
        pattern: await \$EXPR
        stopBy: end
    - not:
        has:
          pattern: try { \$\$\$ } catch (\$E) { \$\$\$ }
          stopBy: end" /path/to/project

Resources

references/

Contains detailed documentation for ast-grep rule syntax:

  • rule_reference.md: Comprehensive ast-grep rule documentation covering atomic rules, relational rules, composite rules, and metavariables

Load these references when detailed rule syntax information is needed.

© warp-drive-data, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file (references) in .claude/skills/ast-grep of warp-drive-data/warp-drive.

  • SKILL.md
  • references/rule_reference.md

Open the folder on GitHubat commit 34ad57e

Used in 5 other repositories

We found 5 copies of this SKILL.md (exact, near-identical or edited) in other folders, from 5 other GitHub owners. This page covers the copy in warp-drive-data/warp-drive, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Structural Code Search with ast-grep next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Structural Code Search with ast-grep compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Structural Code Search with ast-grep this skillwarp-drive-data/warp-drive3.2k5 repos~2.4kAutomated safety check: PassMIT
ast-grep Structural Searchcode-yeongyu/oh-my-openagent70k—~3.3kAutomated safety check: PassMIT
Eslint Migrate Optionsbiomejs/biome26k—~1.4kAutomated safety check: PassApache-2.0
New Rule for sonar-javaSonarSource/sonar-java1.2k—~833Automated safety check: PassCustom licence
Openqodexopenqodex/openqodex470—~2.4kAutomated safety check: PassApache-2.0
Gograph Go Repository Intelligenceozgurcd/gograph228—~4.8kAutomated safety check: NotesMIT

Similar skills

  • ast-grep Structural Search

    code-yeongyu/oh-my-openagent

    Searches and rewrites code by syntax-tree shape across 25 languages with ast-grep, for codemods, structural queries and YAML lint rules, using a Python wrapper script.

    70k GitHub stars~3.3k tokensUpdated today
    DevelopmentAuto-check passed
  • Official

    A skill your agent uses when biome migrate eslint must preserve configurable ESLint rule options through source-option models, Biome conversions, typed rule variants, and migration fixtures.

    26k GitHub stars~1.4k tokensUpdated today
    DevelopmentAuto-check passed
  • New Rule for sonar-java

    SonarSource/sonar-java

    Official

    Sets the sonar-java conventions for adding an analyzer rule: metadata from rule-api, test locations, MethodMatchers and what not to commit or change.

    1.2k GitHub stars~833 tokensUpdated today
    DevelopmentAuto-check passed
  • Openqodex

    openqodex/openqodex

    Code review for the current change, before it is pushed. An agent skill from openqodex/openqodex.

    470 GitHub stars~2.4k tokensUpdated today
    DevelopmentAuto-check passed
  • Gives an agent working in a Go codebase a structural view through a local MCP server: call graphs, blast-radius and impact analysis, and bounded first-call exploration.

    228 GitHub stars~4.8k tokensUpdated yesterday
    DevelopmentAuto-check: notes
  • Golang Continuous Integration

    samber/cc-skills-golang

    GitHub Actions CI/CD pipeline configuration for Golang projects — workflow files for test, lint, SAST, coverage and vulnerability-scan jobs, Dependabot and Renovate config files, GoReleaser release…

    3.4k GitHub stars~3.7k tokensUpdated 7 days ago
    DevelopmentAuto-check passed

More from warp-drive-data/warp-drive

  • ast-grep Codemod Reference

    warp-drive-data/warp-drive

    Reference for writing and debugging TypeScript and JavaScript codemods with @ast-grep/napi: parsing, node queries, meta-variables, rule objects and editing.

    3.2k GitHub stars~2.6k tokensUpdated today
    Auto-check passed
  • Mock Cache Check-In

    warp-drive-data/warp-drive

    Ensures `.mock-cache` fixture directories under `tests/*` are staged and committed whenever a change adds or modifies a test that uses…

    3.2k GitHub stars~264 tokensUpdated today
    Auto-check passed

Categories

Questions about Structural Code Search with ast-grep

What does Structural Code Search with ast-grep do?

Turns natural-language code queries into ast-grep rules for structural search, testing each rule against an example file before running it on a codebase. ast-grep matches code by its syntax tree rather than plain text, so it can answer questions such as which async functions lack error handling or which calls use particular arguments. The skill converts a request into a rule through a fixed workflow: clarify what to find and in which language, write a small example snippet to a temporary file, write the rule starting simple, test it against the example, and then search the real code.

When should I use Structural Code Search with ast-grep?

Structural Code Search with ast-grep fits situations like: finding every async function without error handling across a codebase; locating calls to a function with particular arguments; writing and debugging a new ast-grep rule in YAML; code queries that plain text search cannot express.

How do I install Structural Code Search with ast-grep in Claude Code?

Run `npx skills add warp-drive-data/warp-drive --skill ast-grep -a claude-code`. Or copy the skill folder (.claude/skills/ast-grep in warp-drive-data/warp-drive) into .claude/skills/ast-grep in your project. Claude Code loads it when a task matches its description.

How do I install Structural Code Search with ast-grep in Codex?

Run `npx skills add warp-drive-data/warp-drive --skill ast-grep -a codex`. Or copy the skill folder (.claude/skills/ast-grep in warp-drive-data/warp-drive) into .agents/skills/ast-grep in your project. Codex loads it when a task matches its description.

Can I use Structural Code Search with ast-grep in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add warp-drive-data/warp-drive --skill ast-grep -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/ast-grep, .gemini/skills/ast-grep, .github/skills/ast-grep and .opencode/skills/ast-grep in your project.

What does Structural Code Search with ast-grep need to run?

SKILL.md names no scripts, command-line tools or credentials: Structural Code Search with ast-grep is instructions for the agent only. Our summary lists: The ast-grep CLI.

Does Structural Code Search with ast-grep access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Structural Code Search with ast-grep safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Structural Code Search with ast-grep use?

Structural Code Search with ast-grep is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Structural Code Search with ast-grep use?

About 2.4k tokens (SKILL.md is roughly 9.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 2.7k tokens, read only when the agent opens those files.

What are the alternatives to Structural Code Search with ast-grep?

Skills that share tags, products or a category with Structural Code Search with ast-grep: ast-grep Structural Search (code-yeongyu/oh-my-openagent, 70k stars), Eslint Migrate Options (biomejs/biome, 26k stars), New Rule for sonar-java (SonarSource/sonar-java, 1.2k stars) and Openqodex (openqodex/openqodex, 470 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Structural Code Search with ast-grep?

warp-drive-data (a GitHub organization) maintains it in warp-drive-data/warp-drive, which has 3,158 GitHub stars. The repository holds 3 skills in this directory. The repository was last updated on October 9, 2026.

Source: warp-drive-data/warp-drive on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.