OpenAI Codex CLI 的安装和使用指南

Codex CLI 是 OpenAI 推出的一款在本地终端运行的 AI 编程助手。

方法一:官方安装脚本(推荐)

macOS / Linux:

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

Windows(PowerShell):

powershell

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

方法二:通过 npm 安装

需要 Node.js 18+

bash

npm install -g @openai/codex

方法三:Homebrew(macOS)

bash

brew install codex

验证安装:

bash

codex --version

认证登录

首次运行 codex 命令后,选择 Sign in with ChatGPT 用 ChatGPT 账号登录(推荐),使用量包含在你的 ChatGPT 套餐中。也可以使用 OpenAI API Key 登录。

平台支持

Codex CLI 支持 macOS、Windows 和 Linux。在 Windows 上可以在 PowerShell 中原生运行(带 Windows 沙箱),或使用 WSL2 获得 Linux 原生环境。

基本使用

运行 codex 启动交互式终端 UI(TUI)会话。可以用 /model 切换 GPT-5.4、GPT-5.3-Codex 等不同模型,也可以附上截图或设计稿让 Codex 一起分析。

常用命令:

命令 说明
codex 启动交互式会话
codex "修复这个 bug" 直接传入任务描述
codex --model gpt-5 指定模型
codex archive 归档会话

安全沙箱模式

对于无人值守的本地工作,推荐使用 --sandbox workspace-write,限制在工作区内操作;除非在专用沙箱 VM 中,否则避免使用 --dangerously-bypass-approvals-and-sandbox。如需授权 Codex 写入更多目录,优先用 --add-dir 而非强制开放全盘访问。

其他接入方式

如果想在代码编辑器(VS Code、Cursor、Windsurf)中使用,可以安装对应的 IDE 插件;如果想要桌面 App 体验,运行 codex app 或访问 Codex App 页面;云端版本可以访问 chatgpt.com/codex

Copyright © https://yan-jian.com 2023 - 2026 All Right Reserved all right reserved,powered by Gitbook更新时间: 2026-06-02 17:03:45

results matching ""

    No results matching ""