skills/developer-tools-integrations/ast-grep/SKILL.md
Write, debug, and validate ast-grep structural code search rules. Use this skill when the user needs syntax-aware code search, AST pattern matching, structural refactor discovery, language-construct queries, or searches that plain text tools like rg can miss, such as finding functions with particular descendants, calls inside specific contexts, missing error handling, React hook shapes, decorators, or other Tree-sitter-backed code structures.
npx skillsauth add bahayonghang/my-claude-code-settings ast-grepInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use ast-grep when the user needs code structure, not just text. The useful outcome is a validated rule plus a clear statement of what it matches and what it may miss.
Start with the smallest tool that can answer the question.
rg for exact names, strings, comments, or simple text.If ast-grep is not installed, say so and offer an rg fallback only when the
fallback will not pretend to be structural.
Identify the language and target files.
Write a tiny fixture before searching the real repository.
Start with the simplest pattern.
ast-grep run --pattern ... --lang ... for a single-node search.has, inside, not, any,
all, regex, nthChild, or reusable metadata.Debug the parsed structure when the first rule misses.
ast-grep run --pattern '<sample code>' --lang <lang> --debug-query=ast.--debug-query prints diagnostic output and may exit non-zero; treat the
printed tree as useful debug output, not as a failed repository search.Validate on the fixture before running on the repository.
Report the final rule, command, and caveats.
Rule files avoid most shell quoting problems and are the preferred form for complex searches.
On Windows, save rule files as UTF-8 without BOM. If ast-grep scan --rule
reports missing field language even though the YAML has language, check for
a BOM at the start of the file.
# async-await.yml
id: async-await
language: javascript
rule:
any:
- kind: function_declaration
- kind: arrow_function
- kind: method_definition
has:
pattern: await $EXPR
stopBy: end
$rule = @'
id: async-await
language: javascript
rule:
any:
- kind: function_declaration
- kind: arrow_function
- kind: method_definition
has:
pattern: await $EXPR
stopBy: end
'@
[System.IO.File]::WriteAllText(
"async-await.yml",
$rule,
[System.Text.UTF8Encoding]::new($false)
)
ast-grep scan --rule async-await.yml .\src
ast-grep scan --rule async-await.yml .\src --json
ast-grep scan --rule async-await.yml ./src
ast-grep scan --rule async-await.yml ./src --json
Use inline rules only for quick checks. In PowerShell, single-quoted here-strings
preserve $META variables without escaping.
$rule = @'
id: console-call
language: javascript
rule:
pattern: console.log($$$ARGS)
'@
"console.log('debug', value);" | ast-grep scan --inline-rules $rule --stdin
In POSIX shells, quote the YAML with single quotes or escape $.
printf '%s\n' "console.log('debug', value);" |
ast-grep scan --inline-rules 'id: console-call
language: javascript
rule:
pattern: console.log($$$ARGS)' --stdin
Every scan --inline-rules example must include id, language, and rule.
When a rule produces no matches:
--lang javascript is different from --lang tsx.--debug-query=ast or --debug-query=cst.pattern or one kind.stopBy: end to deep has / inside searches.Do not assume one node kind covers a user concept.
For JavaScript and TypeScript, "function" may include:
function_declarationfunctionarrow_functionmethod_definitionFor React, decide whether the user means .js, .jsx, .ts, or .tsx.
For Python, inspect the parsed shape before relying on indentation-sensitive multi-line patterns.
When answering an ast-grep task, include:
Rule: the YAML rule or inline pattern.Validation: the fixture command you used or recommend.Repository command: the command for the user's target path.Caveats: likely false positives, false negatives, and language forms not
covered.Load references/rule_reference.md when the task needs detailed syntax for
atomic rules, relational rules, composite rules, metavariables, or troubleshooting.
tools
文献深度解读助手,像研究生导师一样交互式解读 Zotero 库中的学术论文,面向计算机科学、深度学习、自动化等方向(个人向)。当用户提供文献题目、DOI、PDF 或要求解读某篇论文时触发,通过 Zotero MCP 优先获取全文,并根据用户意图自动选择快速筛选、导师深读或研究复盘模式。完整深读时先完成叙事类型判断、阅读前预检、novelty 校准和作者思考路径重建,再整体概览,并基于图例、正文和表格逐图详细解读(Zotero MCP 无法提取 PDF 图片,解读基于文字信息,必要时提醒上传图片)。适用于:(1)快速判断文献是否值得深读 (2)深入理解某篇论文 (3)学习文章中的方法和技术 (4)批判性分析研究设计 (5)寻找研究灵感。需要多篇论文综合、对比或找研究空白,或 arXiv/DOI 批量规范化时,改用 paper-workbench。
development
Review Codex, Claude, OpenAI, or other agent skill directories as reusable capability packages. Use when asked to audit, review, improve, score, rewrite, debrand, package, or document a SKILL.md, skill package, marketplace skill, or agent skill directory, especially when the user wants a comprehensive findings-first report with concrete patch recommendations and validation steps.
development
Turn vague or complex Codex tasks into strong `/goal` commands with outcome, verification, constraints, boundaries, iteration policy, completion evidence, and pause/block conditions. Use when the user asks for Codex goal instructions, Goal 指令, 目标指令, `/goal` prompts, 中文 Goal 模板, plan-to-goal interviews, success criteria, verification commands, or bounded agent work definitions.
development
Use when the user asks to ground an ambitious proposal, avoid over-grand designs, make a bold direction executable, pressure-test feasibility, prevent "too much vision and too little landing", or turn a strategy/refactor/product idea into the smallest verifiable first move with stop rules. Trigger for requests such as 落地, 先落地, 别太飘, 收一收, 可执行, 可验证, 止损, and for follow-ups after geju-style big-picture thinking. Do not trigger for ordinary code review or implementation unless the user explicitly asks to ground or shrink the plan first.