Community编程与开发github.com

ProAlexUSC/cc-plugin-to-codex

将 Claude Code 市场插件桥接到 Codex(技能 + 子代理)

cc-plugin-to-codex 是什么?

cc2codex 是一个命令行工具,用于将 Claude Code (CC) 市场插件同步到 Codex 系统中。每个源插件会被转换为一个以 cc- 为前缀的桥接插件,CC 代理的 Markdown 文件会被转换为 Codex 兼容的 TOML 格式,并且所有工件都会被打上 x-cc-bridge 标记,以便批量管理(列表、更新、卸载)。它支持 Git URL 或本地路径作为源,提供 global 和 project 两种作用域,并且通过严格模式确保 AI 或脚本调用的确定性。该工具还包含了冲突保护、自动清理失效代理以及对象级别的注册策略配置。

兼容平台✓Claude Code✓Codex CLI~Cursor
npx skills add ProAlexUSC/cc-plugin-to-codex

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

cc2codex

一个 CLI 工具,用于将 CC 市场插件同步到 Codex。每个源插件会生成一个 cc-<名称> 桥接,CC 代理 Markdown 文件会被转换为 Codex TOML 格式,并且 每个工件都会被打上 x-cc-bridge 标记,以便 list / update / uninstall 命令 可以批量管理它们。

安装

该包已发布在 PyPI 上。选择以下调用方式之一——下面的例子假设 cc2codex 在 $PATH 中:

  1. uvx 零安装(推荐,始终为最新版本):

    uvx --from cc-plugin-to-codex cc2codex --help
    
  2. uv tool install(持久化):

    uv tool install cc-plugin-to-codex
    cc2codex --help
    
  3. 原生 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 桥接目标:多选复选框

常见陷阱

  1. 非桥接冲突:目标路径上已存在插件目录但没有 x-cc-bridge 标记→被拒绝 (保护用户编写的内容)。传入 --force 以覆盖。
  2. 源切换冲突:同名的桥接之前从源 A 同步,现在指向源 B →被拒绝。 先运行 plugin-uninstall,或传入 --force。
  3. 插件名称 vs 桥接名称:--plugin 接受 源 名称(例如 ios-dev), 而不是桥接名称(cc-ios-dev)。plugin-uninstall / plugin-update 的位置参数接受 桥接 名称。
  4. 注册表策略:每个注册表条目的写入方式为 installation: INSTALLED_BY_DEFAULT + authentication: ON_USE, 因此 Codex 会在安装后自动激活桥接。
  5. 清理失效代理是安全的:只有带有 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

核心安装命令。流程:

  1. 解析源(Git 克隆到 /tmp,或读取本地路径)。
  2. 读取 <source>/.claude-plugin/marketplace.json 以列出可用插件。
  3. 通过 --plugin / --all-plugins 过滤。
  4. 对于每个选中的插件:
    • 预转换每个 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]

删除顺序:

  1. x-cc-bridge.agents 下列出的每个代理 TOML。
  2. scope.plugins_dir/cc-<名称>/ 目录本身。
  3. 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 是唯一覆盖方式。

相关技能