/context-efficient-tools:ast-grepfrom context-efficient-tools
Structural code search and refactoring using ast-grep. Use when Edit fails with ambiguous matches, for formatting-independent rewrites, or matching code shape instead of text.
Ships in context-efficient-tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Default invocation:
ast-grep -l LANG -p 'PATTERN' # search
ast-grep -l LANG -p 'OLD' -r 'NEW' # preview rewrite
ast-grep -l LANG -p 'OLD' -r 'NEW' --update-all # apply
-l is required -- auto-detect is unreliable. Interactive mode (-i) does not work from this harness.
$VAR -- one AST node (an expression, an identifier, ...)$$$ARGS -- zero or more items in a list (function args, statement bodies)$$STMT -- multiple statements# Rename a function across all call sites
ast-grep -l typescript -p 'oldFn($$$ARGS)' -r 'newFn($$$ARGS)'
# Rename a method on any receiver
ast-grep -l javascript -p '$OBJ.oldMethod($$$ARGS)' -r '$OBJ.newMethod($$$ARGS)'
# Rewrite imports
ast-grep -l typescript -p 'import $WHAT from "old-pkg"' -r 'import $WHAT from "new-pkg"'
Workflow: run without -r to see matches, run with -r to preview the diff, then add --update-all. For surgical per-site control, use ast-grep to find locations and Edit to apply.
To list a file's or package's structure (functions, types, imports/exports) rather than match a pattern, use the outline subcommand -- see the code-structure skill.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub xdg/xdg-claude --plugin context-efficient-tools5 skills in this plugin
/code-structureOutline a file or package (functions, classes, methods, types, imports, exports) instead of reading it whole. Use before opening an unfamiliar or large file to orient, when surveying a package's API surface, or to find where a symbol is defined so you can Read just that range -- any "what's in / list / show me the structure of" need. Not for "where is X used" (search) or "how does X work" (read the body)./jqExtract a known field from a JSON file by running jq instead of reading the whole file./ripgrepSearch code and text files via ripgrep (rg) in Bash. Prefer rg over the Grep tool: rg gives full unredacted output, supports pipe composition, and exposes flags Grep does not (-F, -w, -L, -v)./yqExtract a known field from a YAML file by running yq instead of reading the whole file.Other plugins' skills for the same job