Cette page est affichée en anglais. Une traduction française est en cours.
CLI ToolsApr 9, 2026·2 min de lecture

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.

Prêt pour agents

Staging sûr pour cet actif

Cet actif est d'abord staged. Le prompt copié demande à l'agent d'inspecter les fichiers staged avant d'activer scripts, config MCP ou config globale.

Stage only · 17/100Policy : staging
Surface agent
Tout agent MCP/CLI
Type
CLI Tool
Installation
Stage only
Confiance
Confiance : Established
Point d'entrée
step-1.md
Commande de staging sûr
npx -y tokrepo@latest install a414acda-33ca-11f1-9bc6-00163e2b0d79 --target codex

Stage les fichiers d'abord; l'activation exige la revue du README et du plan staged.

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.

Questions fréquentes

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.

Sources citées (3)
🙏

Source et remerciements

Created by Codemod. Licensed under Apache-2.0.

codemod/codemod — ⭐ 970+

Thanks to the Codemod team for making large-scale code migrations manageable.

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires