October 23, 2026

วิธีติดตั้งและตั้งค่า Codex CLI

Codex CLI คือเอเจนต์เขียนโค้ดแบบโอเพนซอร์สของ OpenAI ที่ทำงานในเทอร์มินัล คู่มือนี้ครอบคลุมทุกวิธีติดตั้ง Codex CLI บน macOS, Linux และ Windows วิธีเข้าสู่ระบบ เซสชันแรกของคุณ การกำหนดค่า และวิธีอัปเดต จากนั้นจะแสดงวิธีรัน Codex ควบคู่กับ Claude Code ใน Chief

ติดตั้งแบบด่วน

แพลตฟอร์มคำสั่ง
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 ในโฟลเดอร์โปรเจกต์ แล้วเลือก Sign in with ChatGPT

คำสั่งเหล่านี้นำมาจาก README และเอกสารของ Codex โดย OpenAI ตรวจสอบเมื่อเดือนตุลาคม 2026 ดูข้อมูลล่าสุดได้ที่เอกสาร Codex ของ OpenAI


ขั้นตอนที่ 1: ติดตั้ง Codex CLI

macOS และ Linux

ตัวติดตั้งแบบสแตนด์อโลนของ OpenAI เป็นวิธีที่แนะนำสำหรับการติดตั้ง Codex CLI บน macOS และ Linux:

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

Codex CLI รองรับ macOS บน Apple Silicon และ Intel รวมถึง Linux บน x86_64 และ arm64

ถนัดใช้ตัวจัดการแพ็กเกจมากกว่าหรือไม่ ใช้ Homebrew:

brew install --cask codex

หรือ npm:

npm install -g @openai/codex

คุณยังดาวน์โหลดไบนารีสำหรับแพลตฟอร์มของคุณได้จากหน้า Codex GitHub releases แล้วเปลี่ยนชื่อไฟล์เป็น codex

Windows

Codex CLI ทำงานแบบเนทีฟบน Windows หากต้องการติดตั้ง Codex CLI บน Windows ให้รันคำสั่งนี้ใน PowerShell:

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

บน Windows นั้น Codex ใช้แซนด์บ็อกซ์แบบเนทีฟของ Windows เป็นค่าเริ่มต้น คุณจึงไม่ต้องใช้ WSL หรือเครื่องเสมือน OpenAI แนะนำ WSL2 เมื่อคุณต้องใช้เครื่องมือที่เป็นเนทีฟของ Linux หรือเวิร์กโฟลว์ของคุณทำงานบนนั้นอยู่แล้ว ในกรณีนี้ให้ติดตั้ง Codex ภายใน WSL ด้วยคำสั่งสำหรับ macOS และ Linux ด้านบน

ตรวจสอบการติดตั้ง

codex --version

หากมีอะไรผิดปกติ codex doctor จะตรวจสอบการติดตั้ง การกำหนดค่า การเข้าสู่ระบบ และสถานะการทำงานของรันไทม์

ขั้นตอนที่ 2: เข้าสู่ระบบ

รัน codex ในโฟลเดอร์ใดก็ได้ ในครั้งแรกระบบจะให้คุณเลือกวิธีเข้าสู่ระบบ:

  • Sign in with ChatGPT ใช้แพ็กเกจ ChatGPT ของคุณ การใช้งาน Codex จึงรวมอยู่ในการสมัครสมาชิกของคุณ เป็นตัวเลือกที่แนะนำสำหรับแพ็กเกจ Plus, Pro, Business, Edu และ Enterprise
  • Sign in with an API key เรียกเก็บค่าใช้งานจากบัญชี 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

พิมพ์งานเป็นภาษาธรรมดา เช่น "add input validation to the signup form and a test for it" คำสั่งสแลชที่ควรรู้จักตั้งแต่วันแรกมีดังนี้:

คำสั่งหน้าที่
/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

รัน Codex ควบคู่กับ Claude Code ใน Chief

เมื่อติดตั้งและเข้าสู่ระบบ Codex CLI แล้ว ก็พร้อมใช้งานกับ Chief ได้ทันที Chief คือเครื่องมือจัดการเอเจนต์ AI คุณตั้งเป้าหมาย Chief จะวางแผนออกมาเป็นหมุดหมาย และรันแต่ละหมุดหมายด้วยเอเจนต์ที่คุณเลือก

  • Codex และ Claude Code ในแผนเดียว ตั้งเอเจนต์เริ่มต้นของแต่ละโปรเจกต์ และเลือก Codex หรือ Claude Code สำหรับหมุดหมายใดก็ได้ ดู Claude Code vs Codex ว่าแต่ละตัวโดดเด่นด้านใด
  • รัน Codex ที่คุณเพิ่งติดตั้ง relay ของ Chief ทำงานบน macOS, Linux และ Windows และเริ่ม codex บนเครื่องของคุณ ซึ่งเข้าสู่ระบบด้วยบัญชี ChatGPT ของคุณเอง โค้ดของคุณจะอยู่ที่เดิม
  • งานที่เป็นอิสระต่อกันทำงานแบบขนาน Chief รันทุกหมุดหมายที่งานซึ่งต้องพึ่งพาเสร็จแล้วพร้อมกัน และตรวจสอบผลลัพธ์แต่ละรายการเทียบกับเกณฑ์งานเสร็จ
  • คุยกับ Chief จาก Codex เพิ่มเซิร์ฟเวอร์ MCP ของ Chief ด้วย codex mcp แล้วถามว่ามีอะไรที่รอให้คุณดำเนินการอยู่บ้างโดยไม่ต้องออกจากเซสชัน

รัน Codex ด้วย Chief เริ่มใช้งานฟรี →

อ่านเพิ่มเติมเกี่ยวกับการใช้งานร่วมกัน: 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 แต่คุณยังใช้ WSL2 ได้หากเครื่องมือของคุณเป็นเนทีฟของ Linux

จะอัปเดต Codex CLI ได้อย่างไร

รัน codex update หรืออัปเดตด้วยเครื่องมือที่คุณใช้ติดตั้ง ได้แก่ รันสคริปต์ติดตั้งอีกครั้ง npm install -g @openai/codex@latest หรือ brew upgrade --cask codex

Codex CLI ใช้งานฟรีหรือไม่

Codex CLI เป็นโอเพนซอร์สภายใต้สัญญาอนุญาต Apache-2.0 การใช้งานต้องมีแพ็กเกจ ChatGPT ที่รวม Codex หรือคีย์ OpenAI API ที่คิดค่าบริการตามโทเค็น ดูแพ็กเกจปัจจุบันได้ที่หน้าราคาของ OpenAI

ต้องมี Node.js เพื่อติดตั้ง Codex CLI หรือไม่

ไม่ต้อง ตัวติดตั้งแบบสแตนด์อโลนและ Homebrew ไม่ต้องใช้ Node.js คุณต้องใช้ Node.js เฉพาะเมื่อเลือกติดตั้งด้วย npm เท่านั้น

ใช้ 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 เป็นผลิตภัณฑ์อิสระ และไม่มีส่วนเกี่ยวข้อง ไม่ได้รับการสนับสนุน หรือการรับรองจากบริษัทใดบริษัทหนึ่งข้างต้น_