Agent Skills › poteto/noodle › ast-grep

ast-grep

GitHub

基于 AST 的结构化代码搜索工具,适用于查找特定代码模式、关系及重构场景。

.agents/skills/ast-grep/SKILL.md poteto/noodle

Trigger Scenarios

查找特定结构的代码片段 执行代码重构 分析代码元素关系

Install

npx skills add poteto/noodle --skill ast-grep -g -y
More Options

Non-standard path

npx skills add https://github.com/poteto/noodle/tree/main/.agents/skills/ast-grep -g -y

Use without installing

npx skills use poteto/noodle@ast-grep

指定 Agent (Claude Code)

npx skills add poteto/noodle --skill ast-grep -a claude-code -g -y

安装 repo 全部 skill

npx skills add poteto/noodle --all -g -y

预览 repo 内 skill

npx skills add poteto/noodle --list

SKILL.md

Frontmatter
{
    "name": "ast-grep",
    "description": "Structural code search via ast-grep — use when code shape and element relationships matter, not just text. E.g., \"find async functions without error handling\", \"refactor foo(a, b) to foo({ a, b })\". Use Grep for simple name lookups."
}

ast-grep

Workflow

  1. Write a test snippet representing the target code
  2. Write the rule (start with pattern, escalate to kind + has/inside if needed)
  3. Test with --stdin before searching the codebase
  4. Search the codebase once the rule matches

Critical Gotchas

Always use stopBy: end on relational rules

Without it, has/inside stop at the first non-matching node instead of traversing the full subtree:

# WRONG — will miss deeply nested matches
has:
  pattern: await $EXPR

# RIGHT
has:
  pattern: await $EXPR
  stopBy: end

Escape metavariables in shell

$VAR gets interpreted by the shell. Either escape or single-quote:

# Double-quoted: escape with backslash
ast-grep scan --inline-rules "id: test
language: javascript
rule:
  pattern: await \$EXPR" .

# Single-quoted: no escaping needed
ast-grep scan --inline-rules 'id: test
language: javascript
rule:
  pattern: await $EXPR' .

Metavariables must be the sole content of an AST node

These don't work: obj.on$EVENT, "Hello $WORLD", a $OP b, $jq

Use $$OP for unnamed nodes (operators, punctuation). Use $$$ARGS for zero-or-more nodes.

Testing with --stdin

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

Debugging with --debug-query

When rules don't match, inspect the AST to find correct kind values:

ast-grep run --pattern 'your code here' --lang javascript --debug-query=cst

Formats: cst (all nodes), ast (named only), pattern (how ast-grep sees your pattern).

Rule syntax

See references/rule_reference.md for the full rule reference (atomic, relational, composite rules, and metavariables).

Version History

  • 82d2921 Current 2026-11-19 21:08

Same Skill Collection

.agents/skills/adversarial-review/SKILL.md
.agents/skills/brain/SKILL.md
.agents/skills/codex/SKILL.md
.agents/skills/commit/SKILL.md
.agents/skills/debugging/SKILL.md
.agents/skills/execute/SKILL.md
.agents/skills/find-skills/SKILL.md
.agents/skills/frontend-design/SKILL.md
.agents/skills/go-best-practices/SKILL.md
.agents/skills/interaction-design/SKILL.md
.agents/skills/make-interfaces-feel-better/SKILL.md
.agents/skills/meditate/SKILL.md
.agents/skills/noodle/SKILL.md
.agents/skills/oops/SKILL.md
.agents/skills/plan/SKILL.md
.agents/skills/quality/SKILL.md
.agents/skills/react-best-practices/SKILL.md
.agents/skills/refine/SKILL.md
.agents/skills/reflect/SKILL.md
.agents/skills/review/SKILL.md
.agents/skills/ruminate/SKILL.md
.agents/skills/schedule/SKILL.md
.agents/skills/skill-creator/SKILL.md
.agents/skills/testing/SKILL.md
.agents/skills/todo/SKILL.md
.agents/skills/unslop/SKILL.md
.agents/skills/worktree/SKILL.md
examples/minimal/.agents/skills/execute/SKILL.md
examples/minimal/.agents/skills/schedule/SKILL.md
examples/multi-skill/.agents/skills/execute/SKILL.md
examples/multi-skill/.agents/skills/schedule/SKILL.md
skills/skill-creator/SKILL.md
.agents/skills/ts-best-practices/SKILL.md
examples/multi-skill/.agents/skills/deploy/SKILL.md
examples/multi-skill/.agents/skills/test/SKILL.md

Metadata

Files
0
Version
82d2921
Hash
1e44d57b
Indexed
2026-11-19 21:08

홈 - 위키
Copyright © 2011-2026 iteam. Current version is 2.156.0. UTC+08:00, 2026-11-19 22:13
浙ICP备14020137号-1