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 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。
npx -y tokrepo@latest install a414acda-33ca-11f1-9bc6-00163e2b0d79 --target codex先暂存文件;激活前需要读取暂存 README 和安装计划。
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.
常见问题
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.
引用来源 (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
来源与感谢
Created by Codemod. Licensed under Apache-2.0.
codemod/codemod — ⭐ 970+
讨论
相关资产
LLxprt Code — Multi-Provider AI Coding CLI
LLxprt Code is an open-source AI coding CLI that switches across providers (Anthropic, Gemini, Codex, local). Install via brew or npm.
Open Interpreter — Local Code Interpreter CLI
Open Interpreter runs a local code interpreter in your terminal. Install from GitHub, run `interpreter`, then write files and run commands with approvals.
OpenAI Codex CLI — Terminal Coding Agent by OpenAI
Official OpenAI terminal coding agent. Reads your codebase, writes code, runs commands, and manages files from the command line. Multi-model support with sandbox execution. 20,000+ stars.
dingtalk-workspace-cli — Agent-Ready DingTalk CLI
dingtalk-workspace-cli (dws) is DingTalk’s open-source CLI for humans and AI agents, with OAuth login and `--dry-run` request previews.