ast-grep-refactor

ast-grep-refactor is a skill for Claude Code, Codex from usefulmove/enso. It costs 91 tokens per session (1,436 once invoked), scanned A, original, MIT.

A tool for finding and rewriting code by its syntax structure rather than by matching text. It is intended for TypeScript, TSX, JavaScript, and C++ codebases.

In plain words
What is it for?
Use it for multi-file renames, API migrations, import updates, coding-standard changes, and other syntax-sensitive refactors.
Why use it?
Structure-aware changes reduce accidental edits when the same text appears in unrelated code or when a large migration spans many files.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/usefulmove/enso/ast-grep-refactor
Any agent
npx skills add usefulmove/enso --skill ast-grep-refactor
Clone the repo
git clone --depth 1 https://github.com/usefulmove/enso

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for ast-grep-refactor

README.md
[![agentmods](https://agentmods.dev/badge/skills/usefulmove/enso/ast-grep-refactor.svg)](https://agentmods.dev/skills/usefulmove/enso/ast-grep-refactor)
Your own site
<a href="https://agentmods.dev/skills/usefulmove/enso/ast-grep-refactor"><img src="https://agentmods.dev/badge/skills/usefulmove/enso/ast-grep-refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 91 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,436 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00091 $0.01436
Opus 5 $0.00046 $0.00718
Sonnet 5 $0.00018 $0.00287
Haiku 4.5 $0.00009 $0.00144

Measured 5d ago against content hash 724288aa715f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

ast-grep-refactor scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/ast-grep-refactor/SKILL.md · 174 lines

How it starts

The opening of the file, as written. The whole thing — 174 lines — stays where its author put it; the contents beside it link to each section on GitHub.

When to Use

Load this skill when:

  • Renaming a prop, type, function, or symbol across many files where text-replace would be ambiguous
  • Migrating an API pattern (e.g., deprecated import path → new path, callback style → async/await)
  • Enforcing a code convention at scale (e.g., console.loglogger.debug everywhere)
  • The agent would otherwise reach for sed, awk, or a custom Python parser to modify source files
  • The change touches 5+ files where broken syntax would be hard to detect without running the compiler

Do not use for single-file edits — use the Edit tool directly. This skill is for codebase-scale changes.


Prerequisites

Verify ast-grep is installed before starting:

sg --version
# Expected: ast-grep 0.x.x

If missing:

npm install -g @ast-grep/cli
# Then ensure ~/.npm-global/bin is on PATH
export PATH="$HOME/.npm-global/bin:$PATH"

Language Reference

Language --lang flag File extensions
TypeScript ts .ts
TSX (React) tsx .tsx
JavaScript js .js, .jsx
C++ cpp .cpp, .h, .hpp

Omit --lang to let ast-grep infer from file extensions (safe for single-language directories).


Pattern Syntax

Patterns look like the code you want to match. Replace variable parts with metavariables.

Metavariable Matches Example
$VAR Any single AST node $OBJ.$METHOD()
$$$ARGS Zero or more nodes (variadic) foo($$$ARGS)
$_ Any node (unnamed/throwaway) if ($_ ) { $$$ }

Common Patterns for TS/TSX/JS

Goal Pattern Rewrite
Rename function call oldFn($$$ARGS) newFn($$$ARGS)
Rename method on any object $OBJ.oldMethod($$$ARGS) $OBJ.newMethod($$$ARGS)
Replace import path import $X from 'old-path' import $X from 'new-path'
Replace named import import { oldName } from '$MOD' import { newName } from '$MOD'
Null guard → optional chaining $X && $X.$METHOD() $X?.$METHOD()
JSX prop rename <$C $OLD={$V} /> <$C $NEW={$V} />
console.log → logger console.log($$$ARGS) logger.debug($$$ARGS)

Read the full file on GitHub · 174 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 174 lines · 91 tokens per session scan A 724288aa715f

Subscribe to this mod's changes

ast-grep-refactor is a skill published in the GitHub repository usefulmove/enso (2 stars, last pushed 2mo ago), licensed MIT. It adds 91 tokens to every session and 1,436 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

last30Days

Resolve "last30Days" to a concrete ISO date range relative to your run time — a rolling 30-day window ending today. Returns inclusive civil dates plus exact UTC instants so you have temporal context without computing dates by hand. Read-only: no writes, no network. Use before a "last 30 days" / trailing-month task…

chaitanyagiri/munder-difflin · 83 tokens

thisQuarter

Resolve "thisQuarter" to a concrete ISO date range relative to your run time — this quarter so far (quarter start → today). Returns inclusive civil dates plus exact UTC instants so you have temporal context without computing dates by hand. Read-only: no writes, no network. Use before a quarter-to-date task (QTD…

chaitanyagiri/munder-difflin · 78 tokens

thisWeek

Resolve "thisWeek" to a concrete ISO date range relative to your run time — this week so far (Monday → today). Returns inclusive civil dates plus exact UTC instants so you have temporal context without computing dates by hand. Read-only: no writes, no network. Use before a week-to-date task (this week's activity…

chaitanyagiri/munder-difflin · 77 tokens

harness

하네스를 구성합니다. 전문 에이전트를 정의하며, 해당 에이전트가 사용할 스킬을 생성하는 메타 스킬. (1) '하네스 구성해줘', '하네스 구축해줘' 요청 시, (2) '하네스 설계', '하네스 엔지니어링' 요청 시, (3) 새로운 도메인/프로젝트에 대한 하네스 기반 자동화 체계를 구축할 때, (4) 하네스 구성을 재구성하거나 확장할 때, (5) '하네스 점검', '하네스 감사', '하네스 현황', '에이전트/스킬 동기화' 등 기존 하네스 운영/유지보수 요청 시 사용.

revfactory/harness · 170 tokens

md-hive-sync

Munder Difflin hive sync — runs the start-of-task hive protocol steps: reads memory.md, checks inbox/ for new messages, and reminds you to record durable facts in memory.md and write coordination files before ending. Use when asked to "sync with the hive", "check my inbox", "hive status", or "hive sync". Proactively…

chaitanyagiri/munder-difflin · 109 tokens

md-fetch-summarize

Fetch a URL and return a concise markdown summary of its content. Read-only: no files are written; the summary is returned as output only. Use when asked to "fetch and summarize", "summarize this URL", "what does this page say", or "get the content of ". Proactively suggest when the user pastes a URL and asks what it…

chaitanyagiri/munder-difflin · 93 tokens