ast-refactoring-scripts

ast-refactoring-scripts is a skill for Claude Code from alivirgo/Major-AI-Skills. It costs 33 tokens per session (1,384 once invoked), scanned A, original, MIT.

A method for making one local code-transformation script that updates many source files through their abstract syntax trees. An abstract syntax tree is a structured representation of code that lets a tool change code elements without treating the file as plain text.

In plain words
What is it for?
It is for repository-wide changes such as renaming a method across many services, using tools such as libcst, ts-morph, or jscodeshift.
Why use it?
Editing every file through an AI conversation uses repeated context and can introduce inconsistent changes. A local transformer applies the same migration across the codebase in a more controlled way.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: positional $N argument; mentions Codex.

Part of the major-ai-skills plugin — 147 skills, 8 plugins shipped together

Good fit It is for repository-wide changes such as renaming a method across many services, using tools such as libcst, ts-morph, or jscodeshift.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/alivirgo/major-ai-skills/ast-refactoring-scripts
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 alivirgo/Major-AI-Skills --skill ast-refactoring-scripts
Clone the repo
git clone --depth 1 https://github.com/alivirgo/Major-AI-Skills

Made for: Claude Code.

Or install major-ai-skills, the plugin that ships this one along with the rest of its 147 skills, 8 plugins.

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-refactoring-scripts

README.md
[![agentmods](https://agentmods.dev/badge/skills/alivirgo/major-ai-skills/ast-refactoring-scripts/github.svg)](https://agentmods.dev/skills/alivirgo/major-ai-skills/ast-refactoring-scripts)
Your own site
<a href="https://agentmods.dev/skills/alivirgo/major-ai-skills/ast-refactoring-scripts"><img src="https://agentmods.dev/badge/skills/alivirgo/major-ai-skills/ast-refactoring-scripts/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-refactoring-scripts

Your own site · 80×15
<a href="https://agentmods.dev/skills/alivirgo/major-ai-skills/ast-refactoring-scripts"><img src="https://agentmods.dev/badge/skills/alivirgo/major-ai-skills/ast-refactoring-scripts.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 33 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,384 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.00033 $0.01384
Opus 5 $0.00016 $0.00692
Sonnet 5 $0.00007 $0.00277
Haiku 4.5 $0.00003 $0.00138

Measured yesterday against content hash 8b635135fe1b, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-12, from the pricing page.

Security

Grade A, and why

ast-refactoring-scripts 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 yesterday.

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-refactoring-scripts/SKILL.md · 146 lines

How it starts

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

AST-Delegated Local Refactoring (Scripts over Token Rewrites)

Overview

When tasked with a repository-wide codebase migration ("Rename method getUserById to fetchUserRecord across all 45 microservice files"), naive AI agents attempt to open, edit, and rewrite all 45 files sequentially through LLM tool calls.

This naive approach consumes 100,000+ tokens, takes 5 minutes of streaming latency, and frequently introduces subtle hallucinated syntax regressions.

The AST-Delegated Refactoring Protocol directs the agent to write a single 20-line local AST transformer script (using Python libcst, TypeScript ts-morph, or jscodeshift) and execute it locally via run_command. The entire codebase is refactored deterministically in 200 milliseconds using only 350 tokens.


LLM Multi-File Rewriting vs. AST Local Delegation

┌─────────────────────────────────────────────────────────────┐
│                 Refactoring Architecture Comparison         │
│                                                             │
│  Naive LLM File-by-File Rewrite (45 Files):                 │
│  • 45 sequential `replace_file_content` tool calls          │
│  • ~120,000 tokens billed                                   │
│  • 4-6 minutes execution latency                            │
│  • High risk of missed edge cases or broken imports         │
│                                                             │
│  AST-Delegated Local Execution:                             │
│  1. Agent writes 1 local Python / TS AST script (350 tokens)│
│  2. Agent runs: `python scratch/refactor.py` (Local CPU)    │
│  ↳ 45 files mutated in 180ms with 100% syntactic precision  │
│  ↳ 99.7% Token Reduction ($1.80 $\rightarrow$ $0.005)       │
└─────────────────────────────────────────────────────────────┘

Production AST Transformer Recipes

1. Python libcst Argument Renaming Script

Use when renaming function arguments or decorators across multiple Python modules while preserving exact comments and formatting:

Read the full file on GitHub · 146 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. yesterday Changed · -15 tokens per session 8b635135fe1b
  2. 7d ago First seen · 146 lines · 48 tokens per session scan A e86ed3271dca

Subscribe to this mod's changes

ast-refactoring-scripts is a skill published in the GitHub repository alivirgo/Major-AI-Skills (1 stars, last pushed today), licensed MIT. It adds 33 tokens to every session and 1,384 once invoked, about $0.0002 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-09-05.

Related

Other skills, from other repositories

agent-framework-azure-ai-py

Build persistent agents on Azure AI Foundry using the Microsoft Agent Framework Python SDK.

sickn33/agentic-awesome-skills · 24 tokens

build-fullstack-backend

MANDATORY reading before writing ANY backend, API, server, or fullstack application code (createartifact types fullstack-stateless-app / fullstack-stateful-app, or anything that will be launched with launchbackend). Contains the complete hard contract: the canonical FastAPI+Mangum backend.py template, SECRETS…

mindsdb/anton · 115 tokens

detecting-languages

Use when the user wants to know which programming language a file or snippet is. Covers implicit detection in ts-pack parse/process, confirming support with ts-pack list/info, and the SDK detection functions for path, extension, and raw content.

xberg-io/tree-sitter-language-pack · 60 tokens

gograph

Go repository intelligence for Claude Code. Use when reading, navigating, editing, reviewing, or refactoring a Go codebase. Exposes 64 query, analysis, and workflow capabilities through the local gograph MCP server, including bounded first-call exploration, AST-aware call graphs, blast-radius analysis, impact, and…

ozgurcd/gograph · 69 tokens

windows-compat

Audit and harden this Rust repo (code-graph-mcp) for Windows correctness: path-spelling drift between producers, the 32,767-char command-line cap, index-key mismatches, and path predicates that assume one ecosystem's layout. Use whenever touching code that builds, compares, prints, or stores a filesystem path; that…

sdsrss/code-graph-mcp · 165 tokens

1c-cfe-init

A command that creates the starter XML files for a 1C configuration extension, which changes or adds to an existing 1C business application.

Desko77/cursor-1c-skills · 49 tokens