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

Written for no agent in particular: nothing here depends on one. Also seen: mentions OpenCode.

Good fit Use it for multi-file renames, API migrations, import updates, coding-standard changes, and other syntax-sensitive refactors.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/usefulmove/enso/ast-grep-refactor
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.

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/github.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/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for ast-grep-refactor

Your own site · 80×15
<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="Reviewed on agentmods" width="80" 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. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00091 $0.01436
Opus 5.5 $0.00036 $0.00574
Sonnet 5.5 $0.00018 $0.00287
Haiku 4.5 $0.00009 $0.00144

Measured 3mo ago against content hash 724288aa715f, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 3mo 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.log → logger.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. 3mo 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 5mo ago), licensed MIT. It adds 91 tokens to every session and 1,436 once invoked, about $0.0004 per session on Opus 5.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

ast-grep-refactor compared with skills from other repositories

ast-grep-refactor next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
ast-grep-refactorusefulmove/ensoSkill25mo agoMITA91Claude Code, Codex
last30Dayschaitanyagiri/munder-difflinSkill10k2d agoMITA83Claude Code
thisQuarterchaitanyagiri/munder-difflinSkill10k2d agoMITA78Claude Code
thisWeekchaitanyagiri/munder-difflinSkill10k2d agoMITA77Claude Code
md-fetch-summarizechaitanyagiri/munder-difflinSkill10k2d agoMITA93Claude Code
harnessrevfactory/harnessSkill9.4k2mo agoApache-2.0A184Claude Code
brainstorminghuiliyi37/Tianshu-harnessSkill1.4k4d agoApache-2.0A37Claude Code, Codex