Codemod — AI-Powered Code Migration CLI
Scaffold, share, and run large-scale code migrations with AI. First-class ast-grep support, multi-step YAML workflows, community codemod registry. Apache-2.0, 970+ stars.
What it is
Codemod is an AI-powered command-line tool for scaffolding, sharing, and running large-scale code migrations. It supports ast-grep for AST-based pattern matching, multi-step YAML workflows for complex migrations, and a community registry of pre-built codemods for common framework upgrades (Next.js, React, etc.).
Codemod targets developers and teams facing framework upgrades, API deprecations, or codebase-wide refactoring. Instead of manual find-and-replace or writing custom scripts, you run a codemod that understands your code's syntax tree.
How it saves time or tokens
Manual code migration is error-prone and tedious at scale. Codemod automates transformations using AST awareness, meaning it understands code structure rather than treating it as text. Pre-built codemods in the registry handle common migration paths (e.g., Next.js 12 to 13 app router). Creating your own codemods lets you share migration logic across teams and projects.
How to use
- Run a community codemod:
npx codemod @codemod/next/13/app-routerto apply a pre-built migration. - Create your own codemod:
npx codemod init my-migrationto scaffold a new codemod project. - Publish to the registry:
npx codemod publish my-migrationto share with others.
Example
# Apply a community codemod
npx codemod @codemod/next/13/app-router
# Create a custom codemod
npx codemod init my-migration
cd my-migration
# Define transformation in codemod.yaml
# Uses ast-grep patterns for AST matching
# codemod.yaml example
name: replace-deprecated-api
engine: ast-grep
pattern: 'oldFunction($ARGS)'
fix: 'newFunction($ARGS)'
language: typescript
Related on TokRepo
- Coding AI Tools — AI-powered development and refactoring tools
- Automation Tools — Code automation and migration tools
Common pitfalls
- Codemods modify source files in place. Always commit your code before running a codemod so you can revert if the transformation produces unexpected results.
- AST-based transformations are language-specific. A TypeScript codemod will not work on Python code. Verify the codemod targets your language.
- Community codemods may not cover all edge cases in your codebase. Review the diff after running and handle edge cases manually.
Frequently Asked Questions
ast-grep is a tool for searching and transforming code using abstract syntax tree (AST) patterns. Unlike regex, AST patterns understand code structure, so they match semantic patterns regardless of whitespace or formatting variations.
The registry includes codemods for Next.js migrations, React upgrades, TypeScript transformations, and other common framework changes. Browse the registry at codemod.com or search with npx codemod search.
Yes. Codemod processes entire directories and applies transformations across all matching files. Multi-step YAML workflows let you chain multiple transformations in sequence.
Codemod can use AI to generate codemod rules from examples of before/after code. You provide sample transformations, and the AI generates the AST pattern and fix template.
Yes. Codemod is open-source under the Apache 2.0 license. The CLI, registry, and community codemods are all free to use.
Citations (3)
- Codemod GitHub— Codemod provides AI-powered code migration with ast-grep support
- ast-grep Documentation— ast-grep for AST-based code pattern matching
- Codemod Official Site— Code migration automation and refactoring patterns
Related on TokRepo
Source & Thanks
Created by Codemod. Licensed under Apache-2.0.
codemod/codemod — ⭐ 970+
Thanks to the Codemod team for making large-scale code migrations manageable.
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.