Skip to main content

Codex CLI Command Reference

เอกสารนี้ครอบคลุม commands และ flags ทั้งหมดของ Codex CLI ประกอบด้วย global options, รายละเอียดคำสั่งแต่ละตัว และคำแนะนำด้านความปลอดภัย

Global Flags

CLI รับค่าเริ่มต้นจาก ~/.codex/config.toml โดย command-line override มีความสำคัญสูงกว่า:

Flagคำอธิบาย
--add-dir PATHเพิ่มสิทธิ์เขียนไดเรกทอรีเพิ่มเติมนอกเหนือจาก workspace
--ask-for-approvalควบคุมจังหวะการขออนุมัติ (untrusted | on-request | never)
--cd PATHกำหนดไดเรกทอรีทำงานก่อนประมวลผล request
--config KEY=VALUEOverride ค่า configuration
--dangerously-bypass-approvals-and-sandboxรันโดยไม่มีการอนุมัติ (ใช้เฉพาะใน hardened environment เท่านั้น)
--image PATHแนบไฟล์ภาพกับ initial prompt
--model STRINGOverride model ที่ตั้งค่าไว้
--sandboxเลือก sandbox policy (read-only | workspace-write | danger-full-access)
--searchเปิดใช้ live web search แทน cached results

Primary Commands

คำสั่งสถานะจุดประสงค์
codexStableเปิด interactive terminal UI
codex execStableรันแบบ non-interactive; alias คือ codex e
codex resumeStableต่อ interactive session ก่อนหน้า
codex forkStableแตก session เป็น thread ใหม่
codex applyStableApply diff จาก Codex Cloud task ในเครื่อง
codex loginStableAuthenticate ผ่าน OAuth, API key, หรือ token
codex doctorStableสร้างรายงาน diagnostics

คำสั่งพิเศษ

codex app-server (Experimental)

เปิด local app server พร้อม options สำหรับ stdio, WebSocket หรือ Unix socket transport รองรับ authentication modes เช่น capability tokens และ signed bearer tokens

codex exec

Non-interactive execution พร้อม options ที่สำคัญ:

  • --output-last-message PATH: เขียน response สุดท้ายลงไฟล์
  • --json: Output แบบ newline-delimited JSON events
  • --ephemeral: ไม่บันทึก session files
  • resume subcommand: ต่อ task ก่อนหน้า

codex cloud (Experimental)

โต้ตอบกับ Codex Cloud tasks มี subcommands คือ exec และ list

codex sandbox

รันคำสั่งภายใต้ internal sandbox policy ของ Codex (macOS Seatbelt, Linux Landlock หรือ Windows native)

codex plugin (Experimental)

จัดการ plugins พร้อม marketplace support มี subcommands คือ add, list และ remove

codex mcp (Experimental)

จัดการ Model Context Protocol servers รองรับ stdio และ streamable HTTP transport

คำแนะนำด้านความปลอดภัย

  • ใช้ --sandbox workspace-write สำหรับงาน local แบบ unattended
  • หลีกเลี่ยง --dangerously-bypass-approvals-and-sandbox ยกเว้นใน sandbox VM ที่แยกออกมาโดยเฉพาะ
  • ใช้ --add-dir แทนการบังคับ full access เมื่อต้องการให้สิทธิ์ไดเรกทอรี
  • รวม --json กับ --output-last-message ใน CI pipeline เพื่อ output ที่มีโครงสร้าง

ลำดับความสำคัญของ Configuration

Command-line overrides มีความสำคัญสูงสุด ตามด้วย profile-specific config แล้วจึงเป็น base user configuration

Flag --strict-config จะ error เมื่อพบ configuration fields ที่ไม่รู้จัก