October 23, 2026

如何安裝與設定 Codex CLI

Codex CLI 是 OpenAI 推出的開源終端機程式碼代理。本指南涵蓋在 macOS、Linux 和 Windows 上安裝 Codex CLI 的所有方式,以及如何登入、執行第一個工作階段、進行設定和更新。最後說明如何在 Chief 中讓 Codex 與 Claude Code 並肩執行。

快速安裝

平台指令
macOS 與 Linuxcurl -fsSL https://chatgpt.com/codex/install.sh | sh
Windows(PowerShell)powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
npm(任何平台)npm install -g @openai/codex
Homebrewbrew install --cask codex

接著在你的專案資料夾中執行 codex,並選擇 使用 ChatGPT 登入。

以上指令取自 OpenAI 的 Codex README 與說明文件,於 2026 年 10 月核對。最新資訊請參閱 OpenAI 的 Codex 說明文件。


步驟 1:安裝 Codex CLI

macOS 與 Linux

在 macOS 和 Linux 上,建議使用 OpenAI 的獨立安裝程式安裝 Codex CLI:

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

Codex CLI 支援 Apple Silicon 與 Intel 的 macOS,以及 x86_64 與 arm64 的 Linux。

偏好使用套件管理工具?可以用 Homebrew:

brew install --cask codex

或 npm:

npm install -g @openai/codex

你也可以從 Codex GitHub releases 頁面下載適用於你平台的執行檔,並將它重新命名為 codex。

Windows

Codex CLI 可在 Windows 上原生執行。要在 Windows 上安裝 Codex CLI,請在 PowerShell 中執行:

powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"

在 Windows 上,Codex 預設使用原生 Windows 沙箱,因此你不需要 WSL 或虛擬機器。如果你需要 Linux 原生工具,或你的工作流程本來就在 WSL2 上執行,OpenAI 建議使用 WSL2;這種情況下,請在 WSL 中使用上方的 macOS 與 Linux 指令安裝 Codex。

確認安裝

codex --version

如果有任何異狀,codex doctor 會檢查你的安裝、設定、登入狀態與執行環境的健康狀況。

步驟 2:登入

在任一資料夾中執行 codex。第一次執行時,它會請你選擇登入方式:

  • 使用 ChatGPT 登入會使用你的 ChatGPT 方案,Codex 用量包含在你的訂閱中。這是 Plus、Pro、Business、Edu 和 Enterprise 方案的建議選項。
  • 使用 API 金鑰登入會將用量計費到你的 OpenAI API 帳戶。

你也可以從命令列登入:

codex login                                            # browser sign-in
printenv OPENAI_API_KEY | codex login --with-api-key   # API key from stdin
codex login --device-auth                              # device code, for remote or headless machines
codex login status                                     # show the active sign-in
codex logout                                           # clear stored credentials

在伺服器或沒有瀏覽器的機器上,OpenAI 建議使用裝置代碼登入。Codex 會將憑證儲存在 ~/.codex/auth.json 或作業系統的憑證儲存區中。

步驟 3:執行第一個工作階段

開啟你的專案並啟動 Codex:

cd my-project
codex

用一般語言輸入任務,例如「為註冊表單加上輸入驗證,並為它寫一個測試」。第一天就值得認識的幾個斜線指令:

指令用途
/init建立 AGENTS.md 檔案,存放給 Codex 的指示
/model選擇模型與推理強度
/permissions選擇 Codex 不必詢問就能做的事
/status顯示目前的工作階段設定
/review審查你的變更並找出問題

AGENTS.md 是你告訴 Codex 專案如何運作的地方:如何執行測試、要遵循哪些慣例,以及要避免什麼。執行一次 /init,再編輯產生的結果。

步驟 4:設定權限與預設值

Codex 在編輯檔案或執行超出你所設限制的指令前會先詢問。你可以用 /permissions 針對每個工作階段變更,或用旗標啟動 Codex:

codex --sandbox workspace-write --ask-for-approval on-request

沙箱模式有 read-only、workspace-write 和 danger-full-access。若要設定持久的預設值,請在 ~/.codex/config.toml 中設定相同選項:

model = "gpt-6.1-sol"
approval_policy = "on-request"
sandbox_mode = "workspace-write"

使用 codex --profile <name> 可在基本設定之上疊加一個具名設定檔,例如一個用於謹慎的工作,另一個用於快速實驗。

步驟 5:更新 Codex CLI

Codex 更新頻繁。最簡單的更新方式是:

codex update

或使用你當初安裝它的工具更新:

curl -fsSL https://chatgpt.com/codex/install.sh | sh   # standalone installer: rerun it
npm install -g @openai/codex@latest                    # npm
brew upgrade --cask codex                              # Homebrew

完成後執行 codex --version,確認已是新版本。

實用的 Codex CLI 指令

指令用途
codex啟動互動式工作階段
codex exec "<task>"以非互動方式執行任務,適用於腳本與 CI
codex review以非互動方式執行程式碼審查
codex resume繼續先前的工作階段(--last 為最近一次)
codex --worktree在新的 git worktree 中執行工作階段
codex mcp管理 MCP 伺服器
codex app啟動 Codex 桌面應用程式

在 Chief 中讓 Codex 與 Claude Code 並肩執行

Codex CLI 安裝並登入後,就能搭配 Chief 使用。Chief 是 AI 代理管理工具:你設定目標,Chief 將它規劃成多個里程碑,並用你選擇的代理執行每一個里程碑。

  • Codex 與 Claude Code 在同一份計畫中。 為每個專案設定預設代理,並為任一里程碑選擇 Codex 或 Claude Code。各自的強項請參閱 Claude Code 與 Codex 比較。
  • 執行你剛安裝的 Codex。 Chief 中繼可在 macOS、Linux 和 Windows 上執行,並啟動你機器上的 codex,以你自己的 ChatGPT 帳戶登入。你的程式碼留在原處。
  • 獨立的工作平行執行。 Chief 會同時執行所有相依項目已完成的里程碑,並依照各自的完成標準檢查每個結果。
  • 從 Codex 與 Chief 對話。 使用 codex mcp 加入 Chief 的 MCP 伺服器,不必離開工作階段就能詢問有哪些事在等你處理。

用 Chief 執行 Codex。免費開始 →

深入了解兩者的搭配:Chief + Codex。


常見問題

如何安裝 Codex CLI?

在 macOS 和 Linux 上,執行 curl -fsSL https://chatgpt.com/codex/install.sh | sh。在 Windows 上,執行 PowerShell 安裝程式。你也可以使用 npm install -g @openai/codex 或 brew install --cask codex。接著執行 codex 並登入。

Codex CLI 能在 Windows 上使用嗎?

可以。Codex CLI 搭配 Windows 沙箱在 Windows 上原生執行,因此不需要 WSL。如果你的工具是 Linux 原生的,仍然可以使用 WSL2。

如何更新 Codex CLI?

執行 codex update,或使用你當初安裝它的工具更新:重新執行安裝腳本、npm install -g @openai/codex@latest 或 brew upgrade --cask codex。

Codex CLI 是免費的嗎?

Codex CLI 採用 Apache-2.0 授權開源。使用它需要包含 Codex 的 ChatGPT 方案,或依 token 計費的 OpenAI API 金鑰。目前的方案請參閱 OpenAI 的定價頁面。

安裝 Codex CLI 需要 Node.js 嗎?

不需要。獨立安裝程式和 Homebrew 都不需要 Node.js。只有選擇用 npm 安裝時才需要 Node.js。

可以同時使用 Codex CLI 和 Claude Code 嗎?

可以。為它們各自分配一個分支或 git worktree,避免編輯相同的檔案;或讓 Chief 規劃工作,並將每個里程碑交給你選擇的代理。

More articles

AI Agent Orchestration Guide

What AI agent orchestration is, how multi-agent orchestration works for Claude Code and Codex, and a comparison of orchestration approaches. Free guide.

What Is Agentic Engineering?

Agentic engineering means directing AI coding agents that write and test code while you set goals and review results. How it differs from agentic coding.

AI Code Review at Scale

What AI code review is, the main types of AI code review tools, and five workflows for reviewing AI-generated code from several coding agents at once.

Claude Code and Codex Pricing

Claude Code pricing from $20/mo (Pro) to $200/mo (Max 20x), Codex pricing from ChatGPT Free to Pro, usage limits and a comparison table, checked Oct 2026.

From Single Agent to Multi-Agent

Already using one AI coding agent? Here's how to scale to multiple instances running in parallel — the concurrency patterns, worktree isolation, and task decomposition strategies that make it work.

Vibe Coding at Scale

Vibe coding with one agent is fun. Vibe coding with five is chaos — unless you have orchestration. Here's how to scale the vibe without losing the quality.

Why AI Agents Need an Orchestration Layer

Running AI coding agents in terminal tabs works for two. Five signs you've outgrown it, tabs vs an orchestration layer, and what to look for in one.

Multi-Provider AI Orchestration

Claude Code, Codex, Cursor, Aider — each excels at different work. Here's how to combine providers into one coordinated workflow and why cross-provider review catches bugs single-provider setups miss.

Use Chief From Your AI Assistant

Add Chief's remote MCP server to Claude, Claude Code or Codex. Ask what's waiting on you, catch up on what shipped and propose milestones from chat.

Claude Code vs Codex: When to Use Each

Codex vs Claude Code: when each fits, a comparison table and FAQ. Claude Code vs Codex isn't either-or; Chief runs both on your projects.

Claude Code vs Cursor: When to Use Each

Cursor vs Claude Code: when each fits, a comparison table and FAQ. Claude Code vs Cursor isn't either-or; keep Cursor and let Chief run Claude Code.

How to Run Multiple Claude Code Agents in Parallel

Run multiple Claude Code agents in parallel, step by step: worktrees, background agents, subagents and review. Then let Chief orchestrate them for you.

Git Worktrees for AI Coding Agents

How to use git worktrees with Claude Code and Codex: one per agent, parallel runs, .env files, merging and cleanup. Every command, step by step.

How to Run Claude Code From Your Phone

Run Claude Code from your phone: Remote Control, cloud sessions in the Claude mobile app, or SSH and tmux, step by step. Plus approving agents in Discord.

The Best AI Coding Agents in 2026

The best AI coding agents of 2026: Claude Code, Codex, Cursor, Copilot and more agentic AI coding tools compared, and how to run several with Chief.

Subagents vs Parallel Agents

What is a subagent? How Claude Code subagents and Codex subagents work, how they differ from parallel agents, and when to use each one.

Ready to manage your agents?

_Codex 是 OpenAI 的商標。Claude Code 是 Anthropic 的商標。Chief 是獨立產品,與上述兩家公司均無關聯,亦未獲其贊助或背書。_