OpenAI Codex CLI「一鍵安裝 script」。

可以。

這是 OpenAI 最近開始推的「一鍵安裝 script」。

curl -fsSL https://chatgpt.com/codex/install.sh | sh

作用:

  • 自動檢查環境
  • 自動安裝 Codex CLI
  • 幫你處理 PATH
  • 減少 npm / node setup 麻煩

本質類似:

brew install ...

只是變成 shell installer。

官方 repo 目前主要文件仍然以:

npm install -g @openai/codex

為主。


你這台:

MacBook Pro M5 Max 128GB

目前最穩定做法其實是:

brew install node@22
npm install -g @openai/codex

原因:

方法 優點 缺點
install.sh 黑箱
npm install 可控 多一步
brew cask 最乾淨 更新稍慢

真正高階玩家通常避免:

curl xxx | sh

因為:

你直接把遠端 script pipe 到 shell 執行

安全性較差。

比較安全:

curl -fsSL https://chatgpt.com/codex/install.sh -o install.sh
cat install.sh
sh install.sh

先看內容再執行。


安裝後驗證:

codex --version

啟動:

codex

登入:

  • ChatGPT OAuth
  • 或 OPENAI_API_KEY

如果你未來要:

Claude Code
↓
Codex
↓
LiteLLM
↓
OpenRouter
↓
local models

那建議:

npm install -g @openai/codex

不要用 install.sh。

因為之後你一定會:

  • 改 PATH
  • 改 config
  • 包 proxy
  • 接 LiteLLM
  • override model
  • hack auth
  • 接 MCP

install.sh 幫助有限。

1. 安裝 Node.js 22+

Codex CLI 目前要求 Node.js 22+。

Mac(推薦用 Homebrew)

brew install node@22

確認版本:

node -v
npm -v

Node 必須 ≥ 22。


2. 安裝 Codex CLI

官方 GitHub:

openai/codex GitHub![Attachment.tiff](file:///Attachment.tiff)

官方文件:

Codex CLI Docs![Attachment.tiff](file:///Attachment.tiff)

安裝:

npm install -g @openai/codex

或:

brew install --cask codex

3. 啟動 Codex

codex

第一次啟動會要求登入。


4. 認證方式(重要)

方法 A — ChatGPT 帳號登入(推薦)

適合:

  • ChatGPT Plus
  • Pro
  • Team
  • Enterprise

直接:

codex

它會開 browser OAuth 登入。


方法 B — API Key

適合:

  • Agent automation
  • CI/CD
  • Claude Code bridge
  • OpenRouter / LiteLLM proxy

設定:

export OPENAI_API_KEY="sk-xxxx"

永久化:

nano ~/.zshrc

加入:

export OPENAI_API_KEY="sk-xxxx"

重新載入:

source ~/.zshrc

5. 最重要的使用模式

在專案內啟動

cd your-project
codex

Codex 會讀整個 repo context。


6. Approval Mode(非常重要)

Codex 有三種模式:

模式 用途
Read-only 只能分析
Confirm 每次操作詢問
Full Auto 自動改檔 + 執行 command

推薦:

初期:

codex --approval-mode confirm

熟悉後:

codex --approval-mode auto

7. 常用指令

Resume Session

codex resume --last

Review Diff

/review

Attach image

codex screenshot.png

8. 最強實戰架構(你目前適合)

你現在最適合:

Claude Code
    ↓
Codex CLI
    ↓
Local repo
    ↓
Terminal tools

原因:

工具 強項
Claude Code 長 context / planning
Codex CLI repo editing / command execution
OpenCode 多 agent orchestration
LiteLLM model routing
MCP external tools

9. 最推薦實戰 Workflow

Web 專案

cd web-project
codex

Prompt:

Analyze this repo and explain architecture first.
Then generate improvement plan.
Do not modify files yet.

第二步:

Implement phase 1 only.
Run tests after changes.

10. 和 Claude Code 一起用

很多 advanced user:

Claude Code → strategist
Codex CLI → executor

實際流程:

Claude:
- planning
- architecture
- decomposition

Codex:
- edit files
- run command
- fix lint
- execute tests

這是目前 Reddit / HackerNews / GitHub 最常見玩法。


11. Mac M 系列最佳化

你是 M5 Max 128GB。

推薦:

export CODEX_MAX_FILE_SIZE=4MB

避免巨大 context 爆 token。


12. 推薦搭配工具

工具 用途
LiteLLM![Attachment.tiff](file:///Attachment.tiff) model router
OpenRouter![Attachment.tiff](file:///Attachment.tiff) cheap models
Claude Code![Attachment.tiff](file:///Attachment.tiff) planning
OpenCode![Attachment.tiff](file:///Attachment.tiff) terminal agents
Mem0![Attachment.tiff](file:///Attachment.tiff) memory
OpenHands![Attachment.tiff](file:///Attachment.tiff) autonomous agent

13. 最重要觀念

Codex CLI 本質不是 chat。

它是:

terminal-native coding agent

它會:

  • 讀 repo
  • 修改檔案
  • 執行 shell
  • 修 bug
  • 跑 test
  • iterative retry

所以:

Prompt engineering < task decomposition

真正差異:

  • repo structure
  • command permission
  • verification loop
  • context management

14. 真正高階玩家做法

現在社群主流:

Local:
- Codex CLI
- Claude Code
- OpenCode

Cloud:
- OpenRouter
- LiteLLM

Memory:
- Mem0
- Graphiti
- GBrain

Automation:
- MCP
- Playwright
- Browser Use

已經開始取代:

  • Cursor-only workflow
  • Copilot-only workflow

因為 CLI agent 更容易 automation。