cc2codex
CLI 工具,用於將 CC 市集外掛同步至 Codex。每個來源外掛會變成一個
cc-<name> 橋接,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 來源會被 clone 到/tmp並在使用後清理。--ref接受分支、標籤或 commit SHA。 x-cc-bridge標記:在橋接的plugin.json中作為頂層欄位,並且在每個橋接代理 TOML 的 第一行作為註解。沒有標記的檔案被視為使用者自製,除非傳入--force,否則工具絕不會覆寫。- 命名:橋接名稱是
cc-<source-plugin>;代理 TOML 檔名為cc_<plugin-snake>_<agent-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 Bridged Plugins」市集中選取新加入的橋接並安裝。在該安裝步驟 完成之前,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/<bridge>/<version>/— 當使用者執行/plugins install時,Codex 會將橋接複製到此處,並在執行時期從此處載入。~/.codex/config.toml,區段[plugins."<bridge>@cc-bridged-plugins"] enabled = true— Codex 自身的啟用狀態。因此,一個之前已在 Codex 內安裝的橋接,在 cc2codex 卸載後仍會從快取中被載入。 在說明卸載成功後,也請告知使用者到 Codex 內執行
/plugins並卸載相同的橋接, 讓 Codex 清理自己的快取 + 設定。或者手動操作:
rm -rf ~/.codex/plugins/cache/cc-bridged-plugins/<bridge>並編輯~/.codex/config.toml刪除對應的[plugins."…"]區段。
嚴格模式規則(重要)
當沒有 TTY 或傳入了任何 --yes / --json / --non-interactive 時,
指令會以嚴格模式執行。在嚴格模式中,每個決策都必須明確提供:
| 缺少項目 | 錯誤訊息 |
|---|---|
--source | source not specified; pass --source <git-url-or-path> |
--plugin 或 --all-plugins | no plugins selected; pass --plugin <name> (repeatable) or --all-plugins |
--scope | `scope not specified; pass --scope global |
uninstall/update 沒有名稱或 --all | must specify a bridge name or --all to X (installed: …) |
從 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 |
--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 <name> | 可重複。接受來源端外掛名稱(無 cc- 前綴)。與 --all-plugins 互斥。 |
--all-plugins | 同步來源暴露的所有外掛。 |
--all | 將 plugin-update / plugin-uninstall 套用至目標範圍內所有橋接。 |
--yes | 跳過確認提示(隱含嚴格模式)。 |
--non-interactive | 強制嚴格模式;當標準輸入不是 TTY 時自動啟用。 |
--force | 繞過衝突保護(非橋接覆寫、不同來源)。 |
--json | 在標準輸出輸出機器可讀 JSON(隱含嚴格模式)。 |
plugin-browse
唯讀列出來源市集中的外掛。不寫入任何內容。
cc2codex plugin-browse --source <url-or-path> [--ref <ref>] [--json]
非互動模式:需要 --source。
plugin-sync
核心安裝指令。流程:
- 解析來源(將 Git clone 到
/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(第 1 行為
# x-cc-bridge: {…}註解)。 - 移除過時代理(存在於舊標記但不在新清單中)。
- 更新
marketplace.json條目(policy.installation = INSTALLED_BY_DEFAULT)。
- 預先轉換所有
cc2codex plugin-sync \
--source <url-or-path> [--ref <ref>] \
--scope {global|project} \
{--plugin <name> [--plugin <name>] … | --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-<name> | --all] \
[--scope {global|project|all}] \
[--force] [--yes] [--non-interactive] [--json]
- 位置引數是橋接名稱(含
cc-前綴)。 --all更新目標範圍內的所有橋接。- 在嚴格模式中,缺少名稱 /
--all會觸發錯誤,並列出已安裝的橋接。
plugin-uninstall
以 x-cc-bridge.agents 驅動的清理操作。只會移除帶有標記的檔案;
使用者自製的外掛與代理永遠安全。
cc2codex plugin-uninstall [cc-<name> | --all] \
[--scope {global|project|all}] \
[--yes] [--non-interactive] [--json]
刪除順序:
x-cc-bridge.agents下列出的每個代理 TOML。scope.plugins_dir/cc-<name>/目錄本身。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-<name>/.codex-plugin/plugin.json 的頂層:
{
"x-cc-bridge": {
"sourcePlugin": "<source name without cc- prefix>",
"source": "<url or absolute path>",
"sourceKind": "git|local",
"ref": "<branch/tag/sha or null>",
"commit": "<sha or 'local'>",
"marketplace": "<name from source marketplace.json>",
"syncedAt": "<ISO-8601 UTC>",
"tool": "cc-plugin-to-codex/<version>",
"agents": ["cc_<plugin>_<agent>", "..."]
}
}
每個橋接代理 TOML 的第一行註解:
# x-cc-bridge: {"sourcePlugin":"<name>","sourceAgent":"<original-name>","bridgePlugin":"cc-<name>","syncedAt":"..."}
name = "cc_<plugin>_<agent>"
description = "..."
developer_instructions = """..."""
偵測規則:
- 若
plugin.json有頂層x-cc-bridge字典,則為橋接。 - 若代理 TOML 的第一行符合正則表達式
^# x-cc-bridge: (\{.*\})$, JSON 載入成功,且四個必要鍵都存在,則為橋接。
不符合上述條件的任何內容都視為使用者自製;工具不會處理。
只有 --force 能夠覆寫此規則。