From ast-grep
ALWAYS ACTIVE — Structural code search and rewrite protocol. You MUST use ast-grep instead of Grep/sed for any 'find/rewrite by code shape' task (AST patterns, not text). Falls back to Grep for exact literals only.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ast-grep:ast-grepThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
You have ast-grep (tree-sitter AST pattern matcher + rewriter) via the `ast-grep` / `sg` CLI.
You have ast-grep (tree-sitter AST pattern matcher + rewriter) via the ast-grep / sg CLI.
This protocol is MANDATORY and ALWAYS ACTIVE.
ast-grep run -p '<pattern>' BEFORE Grep when the query is about code shape (AST), not text.ast-grep run -p '...' -r '...' BEFORE sed/Edit-loops when rewriting many call sites.-l <lang> for clarity (typescript, tsx, javascript, rust, python, go, ...).comemory → "what was decided / where is X" (memory)
ast-grep → "find / rewrite this code shape" (AST structural) ← here
Grep → "find exact literal `FOO_BAR`" (text)
Glob → "list paths matching `**/*.test.ts`" (paths)
Read → "open known file" (verify)
✓ "Find all useState($X) calls without initial value"
✓ "Find all try blocks without catch"
✓ "Replace console.log($X) with logger.info($X) repo-wide"
✓ "Find all functions returning Promise<void>"
✓ "Find all export default function declarations"
✓ "Find all await fetch($URL) without error handling"
✓ Bulk safe refactor across many files (AST-aware, comment-preserving)
✗ Semantic intent ("how does auth work") → check comemory memory, then Grep on keywords + Read on hits
✗ Exact literal in config files (*.toml, *.md, *.json) → Grep
✗ Path/filename patterns → Glob
✗ Single-file targeted edit → Read + Edit
ast-grep run -p '<pattern>' -l <lang> [paths...]
ast-grep run -p '<pattern>' -l typescript apps/api/src
ast-grep run -p '<pattern>' -r '<replacement>' -l <lang> [paths...]
Shows diff. Add -U (or --update-all) to apply.
ast-grep run -p '<pattern>' -r '<replacement>' -l <lang> -U [paths...]
ast-grep run -p '<pattern>' -l <lang> --debug-query=ast
--strictness smart # default — ignores trivia
--strictness relaxed # ignores comments
--strictness signature # ignores text — match by shape only
$X — single named metavariable (any node)$$$ARGS — multi-node metavariable (zero or more)$_ — anonymous wildcardExamples:
| Want | Pattern |
|---|---|
any console.log call | console.log($$$) |
useState with no arg | useState() |
| same var assigned to itself | $X = $X |
| arrow fn with single body expr | ($$$) => $BODY |
catch-all try no catch | try { $$$ } finally { $$$ } |
--debug-query=ast once to verify shape.ast-grep run -p '...' -l <lang> <paths>.--strictness smart or extra context nodes.$_ / $$$, recheck AST.-U until diff looks right.ast-grep run -p '...' -r '...' -l <lang> <paths>.-U.detect_node_pm / detect_rust in hooks/lib/detect.sh) to verify zero regressions.comemory plugin is installed, persist it via its wrapper: comemory.sh save "ast-grep <name> pattern" "<pattern + what it matches>" --kind pattern --tags "ast-grep"."Am I about to write a regex over multi-line code? → ast-grep instead." "Am I about to Edit-loop the same change across many files? → ast-grep rewrite instead." "Am I searching for code by shape (call form, signature, control flow)? → ast-grep, not Grep."
If a recurring rule emerges (e.g. forbid console.log in apps/api), promote it to sgconfig.yml:
ast-grep new project # bootstrap config
ast-grep new rule # add reusable rule
ast-grep scan # run all configured rules
Hold off until pattern is proven across ≥3 files.
skills/agent-memory/SKILL.mdCLAUDE.mdCreates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub falconiere/toolu --plugin ast-grep