CLI Tools2026年4月9日·1 分钟阅读

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.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 17/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Stage only
信任
信任等级:Established
入口
step-1.md
安全暂存命令
npx -y tokrepo@latest install a414acda-33ca-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

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.

常见问题

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.

引用来源 (3)
🙏

来源与感谢

Created by Codemod. Licensed under Apache-2.0.

codemod/codemod — ⭐ 970+

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产