/odin-code:ast-grepfrom ODIN Code
Runs AST-based structural search, lint, and rewrite of code when regex is too fragile. Validates patterns, dry-runs rewrites, and applies changes with blast-radius review.
Ships in ODIN Code. 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.
Read when SKILL.md points to them; scripts run unread.
| Field | Bound contract |
|---|---|
| Trigger | AST-based modification, structural search, lint, or replacement too fragile for regex. |
| Authority | Reversible local: writes only VCS-tracked source files (search is read-only; rewrites apply only through the helper after dry-run review); rollback is version control. No remote mutation. |
| Side effect | Local file writes through the helper two-pass validate/dry-run/apply flow; no remote, credential, or published mutation. |
| Done | Pattern validated and blast radius reviewed; any rewrite landed at the correct scope (search/lint-only runs are valid). |
$VAR reaches ast-grep unexpanded.--lang) or a single target path whose extension auto-detects it; required for stdin patterns.! to exclude), context lines, JSON output mode.python3 scripts/ast_grep_helper.py validate '<pattern>' --lang <L>. Exit 0 means ast-grep parses it cleanly; exit 2 means malformed (the helper prints the parsed pattern tree showing the ERROR node). Fix and re-validate. Done when: validate exits 0.python3 scripts/ast_grep_helper.py replace '<pattern>' '<rewrite>' --lang <L> <paths>. Read the diff and the N matches across M files count. If the blast radius is wrong, stop and refine the pattern (tighten meta-variables, add --lang, add context); re-run the dry-run. Done when: the dry-run diff and match count are correct.python3 scripts/ast_grep_helper.py replace '<pattern>' '<rewrite>' --lang <L> <paths> --apply. The helper writes via a separate --update-all pass. Done when: files are updated via --update-all.ast-grep, never sg: sg collides with the setgroups binary on many systems. Done when: ast-grep is invoked, not sg.Pattern syntax: $VAR matches any single node; $$$ARGS matches zero or more nodes; $_ matches any node (non-capturing).
Invariants: validate before searching; dry-run before applying; single-quote patterns; --lang is required for stdin; a pattern is code, not regex; switch to grep the moment |, .*, \w, or [...] would be needed. The helper keeps --json and --update-all as separate passes because combining them makes --json silently win and the write is dropped with no error.
For complex tasks, ast-grep supports YAML rule files (sgconfig.yml, ast-grep new project) with rule, fix, inside, any, and matches fields; invoke ast-grep scan/run/test directly for these.
validate exits 2 and prints the pattern debug tree with the ERROR node. No files touched. Fix the pattern and re-validate.--apply. Refine the pattern and re-run the dry-run. No files touched.--lang (tsx is not ts; the wrong dialect silently matches nothing); (3) ast-grep run -p '<pattern>' -l <L> --debug-query=pattern and look for ERROR; (4) inspect the target's actual tree with --debug-query=ast on a known-matching snippet; (5) reproduce in the online playground. No files touched until a correct match is confirmed.validate skips the parse check (regex-smell only) and warns; replace exits 2 without running. Install ast-grep before proceeding.validate: exit 0 (valid) or 2 (malformed, with the pattern debug tree); advisory regex-smell hints on stderr.replace dry-run: a compact unified diff and an N matches across M files summary; no files modified.replace --apply: VCS-tracked files updated via --update-all plus a confirmation line.ast-grep search: matched code locations.agents/openai.yaml (opens in a new tab)references/cli.md (opens in a new tab)references/core-concepts.md (opens in a new tab)references/pattern-syntax.md (opens in a new tab)references/pitfalls.md (opens in a new tab)references/project-setup.md (opens in a new tab)references/recipes.md (opens in a new tab)references/rewriting.md (opens in a new tab)references/rule-config.md (opens in a new tab)references/utility-rules.md (opens in a new tab)references/yaml-reference.md (opens in a new tab)scripts/ast_grep_helper.py (opens in a new tab)tests/smoke.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub outlinedriven/odin-claude-plugin --plugin odin-code35 skills in this plugin
/api-and-interface-designUse when asked to design or change a public API, route, CLI flag, or module boundary. Not for remote, credential, publish, deploy, or irreversible changes./architectUse when non-trivial code needs a design, codebase design or architecture needs improving, or one module needs targeted interface narrowing, seams, or testability. Not for diagrams, deploy, or irreversible changes./breaking-drivenUse when bloated code needs clean re-derivation, or the user says "this module is bloated" or "break it and rebuild". Not for untracked data or changes without VCS rollback./clean-clean-cutUse when asked to run /clean-clean-cut to cut accumulated records and residue. Not for untracked or non-VCS changes, or branch/worktree cleanup: use git-cleanup./code-simplificationUse when the user asks to simplify, clean, or refine code. Not for new abstractions or whole-codebase refactors./constraint-driven-developmentUse when asked to implement under non-negotiable constraints: performance budgets, platform limits, legal or API rules. Not for remote, credential, publish, deploy, or irreversible changes.Other plugins' skills for the same job