cc2codex
一个 CLI 工具,用于将 CC 市场插件同步到 Codex。每个源插件会生成一个
cc-<名称> 桥接,CC 代理 Markdown 文件会被转换为 Codex TOML 格式,并且
每个工件都会被打上 x-cc-bridge 标记,以便 list / update / uninstall 命令
可以批量管理它们。
安装
该包已发布在 PyPI 上。选择以下调用方式之一——下面的例子假设 cc2codex 在 $PATH 中:
-
uvx零安装(推荐,始终为最新版本):uvx --from cc-plugin-to-codex cc2codex --help -
uv tool install(持久化):uv tool install cc-plugin-to-codex cc2codex --help -
原生 pip:
pip install cc-plugin-to-codex cc2codex --help
5 个命令
| 命令 | 作用 |
|---|---|
plugin-browse | 只读地列出源市场暴露的插件 |
plugin-sync | 安装桥接:复制文件 + 转换代理 + 更新注册表 |
plugin-list | 显示已安装的桥接(通过 x-cc-bridge 标记识别) |
plugin-update | 根据标记中记录的源重新同步 |
plugin-uninstall | 通过标记移除桥接 |
核心概念
- 作用域:
global=~/.codex/ ~/.agents/;project=$PWD/.codex/ $PWD/.agents/。 严格模式下需要指定--scope。 - 源:一个 Git URL(
git@host:org/repo.git、https://…/repo.git、ssh://…、git://…或纯git@host:path)或包含.claude-plugin/marketplace.json的本地目录路径。 Git 源会被克隆到/tmp中,之后会被清理。--ref接受分支、标签或提交 SHA。 x-cc-bridge标记:在桥接的plugin.json中的顶级字段,以及每个桥接代理 TOML 文件的第一行注释。没有该标记的文件被视为用户编写的,工具除非传入--force参数, 否则永远不会覆盖它们。- 命名:桥接名称为
cc-<源插件名称>;代理 TOML 文件名为cc_<插件snake>_<代理snake>.toml(kebab-case → snake_case)。
典型流程
同步一个或所有插件(AI 友好)
# 特定插件
cc2codex plugin-sync \
--source https://github.com/your-org/cc-marketplace.git \
--plugin ios-dev --plugin base \
--scope global \
--non-interactive --yes
# 所有插件
cc2codex plugin-sync \
--source /path/to/cc-marketplace \
--all-plugins --scope global \
--non-interactive --yes
重新同步同一个源是安全的:旧标记中存在的、但源中不再有的代理会被自动清理。
⚠️ 执行
plugin-sync后,用户必须在 Codex 中安装桥接Codex 不会热加载
~/.agents/plugins/marketplace.json。一旦 cc2codex 完成文件写入,用户需要 重启 Codex(或启动新会话),运行/plugins, 在“CC 桥接插件”市场中选取新添加的桥接并进行安装。直到这个安装步骤执行, Codex 才会加载技能和代理。在解释同步成功后,务必附上这条指示。
检查状态
cc2codex plugin-list # 人类可读文本
cc2codex plugin-list --scope global --json # 机器可读 JSON
更新
cc2codex plugin-update cc-ios-dev --scope global --non-interactive --yes
cc2codex plugin-update --all --non-interactive --yes
无需再次传递 --source——工具会从标记中读取。
卸载
cc2codex plugin-uninstall cc-ios-dev --scope global --non-interactive --yes
cc2codex plugin-uninstall --all --scope all --non-interactive --yes
移除插件目录 + 所有关联的代理 TOML + 注册表条目。
⚠️ Codex 有自己的缓存;卸载只完成了一半工作
cc2codex 只移除它自己写入的文件。Codex 有 两个额外的状态位置 cc2codex 无法触及:
~/.codex/plugins/cache/cc-bridged-plugins/<桥接>/<版本>/——当用户执行/plugins install时,Codex 会将桥接复制到这里,并在运行时从这里加载。~/.codex/config.toml,[plugins."<桥接>@cc-bridged-plugins"] enabled = true部分——Codex 自身的启用状态。因此,即使 cc2codex 卸载后,之前已在 Codex 中安装的桥接仍然会从缓存加载。 在解释卸载成功后,还要告诉用户在 Codex 中运行
/plugins并卸载相同的桥接, 以便 Codex 清理自己的缓存和配置。或者,手动操作:
rm -rf ~/.codex/plugins/cache/cc-bridged-plugins/<桥接>并编辑~/.codex/config.toml删除对应的[plugins."…"]部分。
严格模式规则(重要)
当没有 TTY 或传入了任一 --yes / --json / --non-interactive 时,
命令以 严格模式 运行。在严格模式下,每个决策都必须显式提供:
| 缺失项 | 错误消息 |
|---|---|
--source | 未指定源;请通过 --source <git-url-or-path> 指定 |
--plugin 或 --all-plugins | 未选择插件;请通过 --plugin <名称>(可重复)或 --all-plugins 指定 |
--scope | `未指定作用域;请通过 --scope global |
uninstall/update 未指定名称或 --all | 必须指定桥接名称或 --all 来执行 X(已安装:…) |
从 AI 或脚本调用时,请预先传递所有标志——不要依赖默认值。
交互模式
在真实的 TTY 中,省略标志会弹出一个 questionary 选择器:
- 源类型:Git URL / 本地路径 / 扫描
~/.claude/plugins/marketplaces/ - 插件:多选复选框
- 作用域:global / project
uninstall/update桥接目标:多选复选框
常见陷阱
- 非桥接冲突:目标路径上已存在插件目录但没有
x-cc-bridge标记→被拒绝 (保护用户编写的内容)。传入--force以覆盖。 - 源切换冲突:同名的桥接之前从源 A 同步,现在指向源 B →被拒绝。
先运行
plugin-uninstall,或传入--force。 - 插件名称 vs 桥接名称:
--plugin接受 源 名称(例如ios-dev), 而不是桥接名称(cc-ios-dev)。plugin-uninstall/plugin-update的位置参数接受 桥接 名称。 - 注册表策略:每个注册表条目的写入方式为
installation: INSTALLED_BY_DEFAULT+authentication: ON_USE, 因此 Codex 会在安装后自动激活桥接。 - 清理失效代理是安全的:只有带有
x-cc-bridge注释的 TOML 会被删除; 用户手工编写的 TOML 不受影响。
完整标志参考
共享标志
| 标志 | 含义 |
|---|---|
--source <url-or-path> | Git URL(git@host:org/repo.git、https://…/repo.git)或本地路径(包含 .claude-plugin/marketplace.json 的目录)。省略则以交互方式选择。 |
--ref <branch|tag|sha> | 当 --source 是 Git URL 时要检出的引用。默认 master。SHA 会通过 fetch + checkout 处理;其他内容使用 clone --branch。本地源忽略。 |
--scope {global,project} | 目标作用域。global → ~/.codex/ ~/.agents/;project → $PWD/.codex/ $PWD/.agents/。plugin-sync 在严格模式下必须指定。 |
--scope {global,project,all} | plugin-list、plugin-update、plugin-uninstall 的作用域过滤器。默认 all。 |
--plugin <名称> | 可重复。接受源端插件名称(无 cc- 前缀)。与 --all-plugins 互斥。 |
--all-plugins | 同步源暴露的所有插件。 |
--all | 将 plugin-update / plugin-uninstall 应用于目标作用域中的每个桥接。 |
--yes | 跳过确认提示(隐含严格模式)。 |
--non-interactive | 强制严格模式;当 stdin 不是 TTY 时自动启用。 |
--force | 绕过冲突保护(非桥接覆盖、不同源)。 |
--json | 以 JSON 格式输出到 stdout(隐含严格模式)。 |
plugin-browse
只读列出源市场中的插件。不会写入任何内容。
cc2codex plugin-browse --source <url-or-path> [--ref <ref>] [--json]
非交互式:--source 是必需的。
plugin-sync
核心安装命令。流程:
- 解析源(Git 克隆到
/tmp,或读取本地路径)。 - 读取
<source>/.claude-plugin/marketplace.json以列出可用插件。 - 通过
--plugin/--all-plugins过滤。 - 对于每个选中的插件:
- 预转换每个
agents/*.md(快速失败)。 - 检查代理 TOML 冲突(用户编写的→拒绝,除非使用
--force)。 - 暂存一个同级目录并复制(黑名单排除
.claude-plugin/、.codex-plugin/、hooks/、commands/、agents/、VCS/构建噪音)。 - 写入
.codex-plugin/plugin.json,包含x-cc-bridge标记和最终的代理列表。 - POSIX 原子重命名暂存目录覆盖旧的桥接。
- 写入代理 TOML(
# x-cc-bridge: {…}注释在第 1 行)。 - 移除失效代理(在旧标记中但不在新列表中)。
- 插入或更新
marketplace.json条目(policy.installation = INSTALLED_BY_DEFAULT)。
- 预转换每个
cc2codex plugin-sync \
--source <url-or-path> [--ref <ref>] \
--scope {global|project} \
{--plugin <名称> [--plugin <名称>] … | --all-plugins} \
[--force] [--yes] [--non-interactive] [--json]
非交互式:--source、--scope 和 --plugin|--all-plugins 都是必需的。
plugin-list
扫描目标作用域中的每个插件目录,列出带有 x-cc-bridge 标记的目录。
cc2codex plugin-list [--scope {global|project|all}] [--json]
文本模式输出每个作用域的 pluginsDir / agentsDir / registry 路径,
以及桥接清单和代理名称。JSON 模式按作用域分组相同数据。
plugin-update
使用桥接的 x-cc-bridge.source + .ref 重新解析源并运行同步流程。
不需要再次传入源参数。
cc2codex plugin-update [cc-<名称> | --all] \
[--scope {global|project|all}] \
[--force] [--yes] [--non-interactive] [--json]
- 位置参数是 桥接 名称(带
cc-前缀)。 --all更新目标作用域中的每个桥接。- 在严格模式下,缺少名称 /
--all会触发错误,列出已安装的桥接。
plugin-uninstall
由 x-cc-bridge.agents 驱动的清理。仅移除带有标记的文件;
用户编写的插件和代理始终安全。
cc2codex plugin-uninstall [cc-<名称> | --all] \
[--scope {global|project|all}] \
[--yes] [--non-interactive] [--json]
删除顺序:
x-cc-bridge.agents下列出的每个代理 TOML。scope.plugins_dir/cc-<名称>/目录本身。scope.registry中的条目(marketplace.json的plugins[]数组)。
marketplace.json 文件本身永不会被删除,即使数组变为空(plugins: [])。
JSON 模式
plugin-browse --json
{
"marketplace": {
"name": "<string>",
"source": "<string>",
"sourceKind": "git|local",
"ref": "<string or null>",
"commit": "<string>"
},
"plugins": [
{
"name": "<string>",
"version": "<string>",
"description": "<string>",
"skillCount": 0,
"agentCount": 0,
"hasCodexManifest": true
}
]
}
plugin-sync --json
{
"scope": "global|project",
"synced": [
{
"bridgeName": "cc-<name>",
"bridgeDir": "<absolute path>",
"agents": ["cc_<plugin>_<agent>", "..."]
}
]
}
plugin-list --json
{
"scopes": {
"global": {
"pluginsDir": "<path>",
"agentsDir": "<path>",
"registry": "<path>",
"bridges": [
{
"name": "cc-<name>",
"version": "<string>",
"sourcePlugin": "<source name>",
"source": "<url-or-path>",
"sourceKind": "git|local",
"ref": "<string or null>",
"commit": "<sha or 'local'>",
"marketplace": "<source market name>",
"syncedAt": "<ISO-8601 UTC>",
"agents": ["cc_<plugin>_<agent>", "..."]
}
]
},
"project": { "...": "same shape" }
}
}
plugin-update --json
{
"updated": [
{"bridgeName": "cc-<name>", "commit": "<sha>", "scope": "global|project"}
]
}
plugin-uninstall --json
{
"removed": [
{"bridge": "cc-<name>", "agents": ["cc_<plugin>_<agent>", "..."], "scope": "global|project"}
]
}
退出码
| 码 | 含义 |
|---|---|
0 | 成功 |
1 | 运行时错误(桥接未找到、未解决的冲突、SyncConflictError 等) |
2 | 缺少/无效参数(严格模式、未知插件名称等) |
x-cc-bridge 标记格式
写入 <scope.plugins_dir>/cc-<名称>/.codex-plugin/plugin.json 的顶层:
{
"x-cc-bridge": {
"sourcePlugin": "<不带 cc- 前缀的源名称>",
"source": "<URL 或绝对路径>",
"sourceKind": "git|local",
"ref": "<分支/标签/sha 或 null>",
"commit": "<sha 或 'local'>",
"marketplace": "<来自源 marketplace.json 的名称>",
"syncedAt": "<ISO-8601 UTC>",
"tool": "cc-plugin-to-codex/<版本>",
"agents": ["cc_<插件>_<代理>", "..."]
}
}
每个桥接代理 TOML 的第一行注释:
# x-cc-bridge: {"sourcePlugin":"<名称>","sourceAgent":"<原始名称>","bridgePlugin":"cc-<名称>","syncedAt":"..."}
name = "cc_<插件>_<代理>"
description = "..."
developer_instructions = """..."""
检测规则:
plugin.json是桥接当且仅当它包含顶级x-cc-bridge字典。- 代理 TOML 是桥接当且仅当其第一行匹配正则表达式
^# x-cc-bridge: (\{.*\})$,JSON 负载解析成功,且四个必需键都存在。
任何不匹配的内容都被视为用户编写;工具不会触碰它。--force 是唯一覆盖方式。