CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

Codemod CLI

$ codemod 官方出品 中风险
Codemod · 文件检索与编辑 · Apache-2.0 · macos / linux / windows

Codemod CLI 可通过本地工作流或注册表配方自动化框架升级与 AST 代码迁移。支持 --dry-run、--no-interactive 及 --format json / --format jsonl 机器可读输出,便于 CI 与编码 Agent 集成。

FCRS-1.0 综合评分
84 /100
良好 (Good)
中置信度 (源码/文档)
零摩擦安装命令
npm install -g codemod
CLI vs MCP 选型建议 优先选 CLI

codemod --dry-run --format jsonl 直接在本地仓库执行多文件 AST 转换,无需经由 MCP 代理源码树。

Agent 友好度体检单

✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
✓ 支持 Dry-Run
— 只读模式开关
— 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md

当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。

FCRS-1.0 六维评分拆解

Agent 友好度 22 / 25

原生提供 --format json / --format jsonl、--dry-run 与 --no-interactive 等专为自动化设计的参数。

  • Supports --dry-run, --format jsonl, and --no-interactive
安全与权限边界 21 / 25

--dry-run 可安全阻断磁盘写入,但执行远程注册表配方会在本地运行 JavaScript/AST 代码。

  • --dry-run verifies transforms prior to writing
  • Registry recipes execute local scripts
安装与运行摩擦 13 / 15

可在 macOS、Linux 与 Windows 上通过 npm install -g codemod 或 npx codemod 运行(需 Node.js)。

  • Cross-platform npm/npx distribution
能力覆盖与边际价值 12 / 15

整合社区框架升级配方、工作流编排及多种 AST 引擎。

  • Supports jscodeshift, ast-grep, and multi-step workflows
维护与来源背书 8 / 10

由 Codemod 官方团队(codemod/codemod)遵循 Apache-2.0 协议持续积极维护。

  • Official codemod/codemod repository
文档与可验证性 8 / 10

docs.codemod.com 提供结构化的 CLI 参数、工作流与 JSONL 控制协议文档。

  • Official docs at docs.codemod.com

安全边界、鉴权与放权指南

鉴权方式
无需鉴权 环境变量密钥 本地配置文件
凭证存储位置

本地工作流无需鉴权;可选的注册表/云端登录将令牌存于 ~/.codemod 或通过 API 密钥环境变量传入。

潜在副作用
只读查询 本地写入
费用与配额提示

CLI 采用 Apache-2.0 开源免费,本地与注册表运行免费;企业托管平台功能为付费服务。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# Codemod CLI Agent Rules
- Always run with `--dry-run --format jsonl` and `--no-interactive` before applying changes.
- Inspect third-party registry recipes before running them locally, as codemod recipes execute Node/AST logic.

Agent 高频安全命令配方

只读查询(安全推荐)

以 JSONL 输出试运行 codemod 工作流
codemod workflow run -w ./codemod.yaml --target ./src --dry-run --format jsonl

使用 --dry-run 模拟迁移流程并输出结构化 JSONL 事件,不修改任何文件。

受控写入与预演

无交互运行本地 codemod 工作流
codemod workflow run -w ./codemod.yaml --target ./src --no-interactive

在无交互提示的情况下将已审核的工作流应用至 ./src。

核心优势

  • + 原生提供 --dry-run、--no-interactive 与 --format jsonl 等适合 Agent 编排的参数。
  • + 丰富的注册表配方可加速常见框架版本升级。

注意事项与踩坑点

  • ! 主版本间命令形态有所演进(如 codemod 与 codemod@next),若子命令差异请以 --help 为准。
  • ! 运行外部注册表配方会在本地执行第三方转换脚本。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI