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
官方文件:
Codex CLI Docs
安裝:
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 |
model router |
| OpenRouter |
cheap models |
| Claude Code |
planning |
| OpenCode |
terminal agents |
| Mem0 |
memory |
| OpenHands |
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。