前言¶
在 DeepSeek Harness 裏使用 Codex 模型時,一個具體問題是:既要接入 openai-codex 模型路由,又不希望把完整 OAuth 憑據放到普通文件裏。dsh-codex-keychain 是一個非官方、獨立的 DSH 插件,用來處理這個場景:它爲 DSH 添加 openai-codex 模型路由,並將完整 OAuth 憑據保留在操作系統的原生憑據存儲中。
這是什麼¶
dsh-codex-keychain 由 CpfPatrick 維護,許可證爲 MIT。當前 0.1.0-alpha.1 是 developer preview,面向 DeepSeek Harness 0.1.0-rc.6 和 @earendil-works/pi-ai 0.82.1。
它不使用 OpenAI Platform API key,不使用 fallback 明文憑證文件,也不復用 ~/.codex/auth.json。該包只連接面向有資格 ChatGPT 賬戶開放的 Codex backend,並且與 OpenAI、DeepSeek 無隸屬或背書關係。
核心功能¶
下面介紹已覈實的能力:
- 添加
openai-codex模型路由。 - 將完整 OAuth 憑據保存在操作系統原生憑據存儲中:
- macOS Keychain
- Windows Credential Manager
- Linux Secret Service
- 支持 browser ChatGPT OAuth 和 device-code ChatGPT OAuth。
- 支持 automatic locked token refresh。
- 提供 Codex model catalog 和 DSH model-picker 集成。
- 支持 DSH-native streaming、reasoning、tool calls、replay,以及已有 DSH image attachments/model vision。
- 提供專屬 Web settings page 和 headless CLI。
status --json只包含 sign-in state、provider、platform、backend;失敗時包含 stable code 和 safe message,不包含 tokens、account IDs 或 token timestamps。
安裝與啓用¶
先安裝到指定 DSH profile:
dsh plugin --profile web add dsh-codex-keychain@next
啓動 Web 端:
dsh web
接着在 Web 設置中完成登錄:
1、打開 Settings → OpenAI Codex。
2、選擇 Sign in with browser。
3、點擊 Open authorization page,並完成 OpenAI 授權。
4、登錄完成後,在 DSH 的 model picker 裏選擇 openai-codex 模型。
該插件不會修改默認模型;需要手動選擇對應模型。
典型用法¶
瀏覽器不可用、需要 headless 主機、或 localhost callback 無法綁定時,可以用 CLI 登錄:
dsh plugin --profile web exec dsh-codex-keychain login
dsh plugin --profile web exec dsh-codex-keychain login --device-code
查看狀態:
dsh plugin --profile web exec dsh-codex-keychain status
dsh plugin --profile web exec dsh-codex-keychain status --json
退出登錄:
dsh plugin --profile web exec dsh-codex-keychain logout
卸載前如需移除原生憑據,可先執行 logout,再移除插件:
dsh plugin --profile web exec dsh-codex-keychain logout
dsh plugin --profile web remove dsh-codex-keychain
安全與邊界¶
這個插件的邊界比較明確:
- 它面向 ChatGPT OAuth,不面向 OpenAI Platform API key。ChatGPT subscription access 與 OpenAI Platform API access 是不同產品。
- 它只連接面向有資格 ChatGPT 賬戶開放的 Codex backend。
- 如果原生憑據存儲缺失、locked 或 unavailable,插件會報告
KEYCHAIN_UNAVAILABLE並拒絕登錄,不做普通文件 fallback。 - Web authentication RPC 是 loopback-only;remote browsers 不能調用 authentication RPC。
- OAuth URLs 和 device codes 是 transient 的,插件不會寫入 application logs 或 persistent storage。
- 瀏覽器回調使用
localhost端口1455。 - 刷新失敗或不完整登錄不會替換之前保存的憑據。
- 它不包含 quota displays、web search、standalone image-viewing UI 或 image generation。
已知 alpha limitation:當前請求不能取消因網絡停滯導致的 token refresh。
適用場景與注意¶
適合以下情況:
- 希望在 DSH 中使用
openai-codex模型路由。 - 希望通過 ChatGPT OAuth 登錄,而不是 OpenAI Platform API key。
- 希望憑據保存在操作系統原生憑據存儲中,而不是明文文件。
- 需要 Web settings page 或 headless CLI 登錄。
使用注意:
- 當前 alpha 固定面向 DSH
0.1.0-rc.6;升級 DSH 前需要注意兼容性。 - 運行要求 Node.js
^22.19 || >=24和 pnpm11.7.0。 - 插件以當前 dsh 進程權限運行;安裝前應檢查源碼、許可證和依賴。
- CLI 登錄時可能顯示 OAuth URL 或 device code,這類輸出屬於臨時憑據信息,不應分享或截屏傳播。
鏈接¶
GitHub:https://github.com/CpfPatrick/dsh-codex-keychain