Codemods & AST Tools
Programmatic code transformation — codemods, refactors, lint fixes.
When you need to upgrade 200 files, swap an API across a monorepo, or migrate to a new framework version, AST tools beat regex.
TypeScript / JavaScript AST
- ★ ts-morph — high-level TypeScript Compiler API wrapper. The default when you need full type info during transformation.
- ★ jscodeshift (Meta) — the codemod runner; ships with React's official codemods. Lower-level than ts-morph.
@babel/core+@babel/parser— when you need full Babel ecosystem.- swc +
@swc/wasm-web— Rust-based parser; very fast. - OXC — fastest JS toolchain (parser, transformer, linter). Used inside oxlint.
- Recast — preserves formatting in AST output.
- Prettier as a step at the end — re-format whatever you generated.
High-level codemod orchestration
- ★ codemod.com / Intuita — registry of codemods + a runner;
codemodCLI applies framework / library upgrades. The default in 2026. @codemod/cli— runs jscodeshift, ts-morph, ast-grep recipes uniformly.grit— pattern-based transforms; SQL-like for code.semgrep— pattern-based code search + autofix; great for security and style rules.
Tree-sitter / multi-language
- ★ tree-sitter — incremental parser for many languages; bindings for everything.
- ★ ast-grep (sg) — Rust CLI for tree-sitter pattern matching; "grep with structure." Excellent for cross-language refactors.
- comby — alternative pattern-based rewrite tool.
- GritQL — Grit's query language.
CSS / config / docs AST
- PostCSS — CSS AST.
- stylelint — CSS lint rules / autofix.
- YAML AST:
yaml(eemeli/yamlpackage) preserves comments. - TOML AST:
@iarna/tomletc. - JSON5 for JSON-with-comments parsing.
- mdast / hast / xast — markdown / HTML / XML ASTs (used by remark / rehype).
Auto-fix in editors
- ESLint
--fix— your existing rules already do half this work. - Biome — formatter + linter with autofix.
- dprint — formatter with plugin system.
When to reach for codemods
- Migrating Next.js 15 → 16 or Astro 5 → 6 — official codemods exist.
- Renaming a hook / API across hundreds of files.
- Converting
importpatterns (default → named). - Removing dead feature-flag branches after a flag is fully rolled out.
- Adopting a new validation library (Zod → Valibot, etc.).
When not to
- "Find a string and replace it" — use
sed/rg --replace. - One-off renames in 5 files — let your editor do it.
- Truly novel transformations specific to your domain — sometimes a quick script is faster than learning ts-morph.
Pick this if…
- Default upgrade-from-X-to-Y: check codemod.com first; the codemod likely exists.
- Type-aware transformation: ts-morph.
- Cross-language pattern rewrite: ast-grep.
- Security / style rules with autofix: semgrep.
- Formatting after transform: Prettier or Biome.