CLI ToolsApr 9, 2026·2 min read

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.

TL;DR
Codemod scaffolds, shares, and runs large-scale code migrations with AI assistance, ast-grep support, and a community codemod registry.
§01

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.

§02

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.

§03

How to use

  1. Run a community codemod: npx codemod @codemod/next/13/app-router to apply a pre-built migration.
  2. Create your own codemod: npx codemod init my-migration to scaffold a new codemod project.
  3. Publish to the registry: npx codemod publish my-migration to share with others.
§04

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
§05

Related on TokRepo

§06

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

What is ast-grep?+

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.

What codemods are available in the registry?+

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.

Can Codemod handle multi-file migrations?+

Yes. Codemod processes entire directories and applies transformations across all matching files. Multi-step YAML workflows let you chain multiple transformations in sequence.

How does AI assist in code migration?+

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.

Is Codemod free?+

Yes. Codemod is open-source under the Apache 2.0 license. The CLI, registry, and community codemods are all free to use.

Citations (3)
🙏

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

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets