codemod
Execute mechanical, multi-file code refactoring using ts-morph for structural consistency.
Install
mkdir -p .claude/skills/codemod && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/9593" && unzip -o skill.zip -d .claude/skills/codemod && rm skill.zipInstalls to .claude/skills/codemod
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Mechanical, multi-file, type-aware refactors powered by ts-morph. Use when aKey capabilities
- →Perform multi-file refactors
- →Apply type-aware transformations
- →Automate structural changes
How it works
It uses ts-morph to perform type-aware AST transformations across multiple files.
Inputs & outputs
When to use codemod
- →Rename interfaces across packages
- →Migrate component structures
- →Apply batch code fixes
About this skill
🔧 Codemods
Mechanical, multi-file, type-aware refactors powered by
ts-morph. Use when a pattern repeats across many
files and regex is too fragile.
When to use
| Situation | Approach |
|---|---|
| < 5 files, simple rename | Find-and-replace or manual |
| 5–20 files, structural pattern | Codemod |
| Cross-package type migration | Codemod + build verification |
| One-off exploratory refactor | Codemod in dry-run as a scout |
How to run
# Dry run (default) — reports what would change without writing:
npx tsx codemods/run.ts <transform-name>
# Apply for real:
npx tsx codemods/run.ts <transform-name> --apply
Always dry-run first to scout the pattern before committing to a rewrite shape.
Writing a transform
Create codemods/transforms/<name>.ts exporting three things:
import type { SourceFile } from "ts-morph";
/** Human-readable summary shown by the runner. */
export const description = "Short summary of what this does";
/** Glob patterns relative to repo root. */
export const include = ["packages/visual-editor/src/**/*.ts"];
/**
* Called once per matched file. Mutate `file` in place via ts-morph's API.
* Return `true` if changes were made, `false` otherwise.
*/
export function transform(file: SourceFile): boolean {
// ... your transform logic
return changed;
}
The runner (codemods/run.ts) handles Project creation, file matching, dry-run
reporting, and saving — transforms only need to focus on the AST logic.
Best practices
- Scout first — Start with a detection-only transform (return
falsealways) to find and count all instances before deciding on the rewrite shape. - Bottom-up node replacement — When replacing multiple nodes in the same file, process them in reverse order to avoid position shifts invalidating later references.
- Capture before replace — Any data you need from a node (line number, text)
must be captured before calling
replaceWithText, which invalidates the node reference. - Verify the build — After applying, always run
tsc --noEmitand the relevant test suite. Codemods can introduce type errors in consumers.
Existing transforms
| Transform | Description |
|---|---|
unseen-cast | Rewrites unsafe (evt as StateEvent<T>).detail casts in actions to typed parameters |
When not to use it
- →Simple renames
- →One-off exploratory changes
- →Regex-based changes
Prerequisites
Limitations
- →Requires AST logic
- →Requires build verification
How it compares
It is a mechanical, type-aware tool for large-scale refactors where regex is too fragile.
Compared to similar skills
codemod side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| codemod (this skill) | 0 | 5mo | Review | Advanced |
| typescript-expert | 10 | 6mo | Review | Advanced |
| agent-coder | 3 | 6mo | No flags | Intermediate |
| functional | 3 | 2mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
typescript-expert
davila7
TypeScript and JavaScript expert with deep knowledge of type-level programming, performance optimization, monorepo management, migration strategies, and modern tooling. Use PROACTIVELY for any TypeScript/JavaScript issues including complex type gymnastics, build performance, debugging, and architectural decisions. If a specialized expert is a better fit, I will recommend switching and stop.
agent-coder
ruvnet
Agent skill for coder - invoke with $agent-coder
functional
citypaul
Functional programming patterns with immutable data. Use when writing logic or data transformations.
modern-javascript-patterns
sickn33
Master ES6+ features including async/await, destructuring, spread operators, arrow functions, promises, modules, iterators, generators, and functional programming patterns for writing clean, efficient JavaScript code. Use when refactoring legacy code, implementing modern patterns, or optimizing JavaScript applications.
migrate-honcho-ts
plastic-labs
Migrates Honcho TypeScript SDK code from v1.6.0 to v2.0.0. Use when upgrading @honcho-ai/sdk, fixing breaking changes after upgrade, or when errors mention removed APIs like .core, getConfig, observations, or snake_case properties.
agent-implementer-sparc-coder
ruvnet
Agent skill for implementer-sparc-coder - invoke with $agent-implementer-sparc-coder