Codex CLI ฟีเจอร์
Codex รองรับ workflow หลากหลายรูปแบบนอกเหนือจากการแชท เพื่อรองรับ use case ที่แตกต่างกัน
การรันในโหมด Interactive
เปิด full-screen terminal UI:
codex
หรือระบุ prompt เริ่มต้น:
codex "Explain this codebase to me"
ความสามารถใน Interactive mode:
- ส่ง prompt, โค้ด, หรือ screenshot เข้า composer
- ดูแผนการทำงานของ Codex ก่อนประมวลผลและอนุมัติ/ปฏิเสธได้ inline
- อ่าน markdown และ diff ที่มี syntax highlighting ใน terminal UI
- ใช้
/clearเพื่อล้าง terminal หรือ Ctrl+L เพื่อล้างโดยไม่เริ่มการสนทนาใหม่ - ใช้
/copyหรือ Ctrl+O เพื่อ copy output ล่าสุดที่เสร็จสมบูรณ์ - กด Tab ระหว่างรันเพื่อ queue follow-up text หรือ shell command
- กด Up/Down arrows เพื่อนำทาง draft history
- กด Ctrl+R เพื่อค้นหา prompt history
- กด Ctrl+C หรือ
/exitเพื่อปิด session
การต่อการสนทนา
Codex เก็บ transcript ในเครื่องเพื่อให้ทำงานต่อจากที่ค้างไว้:
codex resume # เปิด session picker ล่าสุด
codex resume --all # แสดง session นอกเหนือจากไดเรกทอรีปัจจุบัน
codex resume --last # ไปยัง session ล่าสุดทันที
codex resume <SESSION_ID> # เลือก session ที่ระบุ
การ resume แบบ non-interactive automation:
codex exec resume --last "Fix the race conditions you found"
Remote TUI Connection
รัน app server บนเครื่องหนึ่งและใช้ terminal UI จากอีกเครื่อง:
codex app-server --listen ws://127.0.0.1:4500
codex --remote ws://127.0.0.1:4500
WebSocket authentication modes:
- Capability token:
--ws-auth capability-token - Signed bearer token:
--ws-auth signed-bearer-token
Models และ Reasoning
GPT-5.5 แนะนำสำหรับงาน Codex ส่วนใหญ่ สามารถเปลี่ยน model กลางเซสชันด้วย /model หรือระบุตอนเปิด:
codex --model gpt-5.5
Feature Flags
ดูและจัดการ feature flags:
codex features list
codex features enable unified_exec
codex features disable shell_snapshot
Subagents
รันงานขนาดใหญ่แบบคู่ขนานด้วย subagent workflow โดย subagent แต่ละตัวใช้ token เพิ่มเติมสำหรับ model และ tool ของตัวเอง
Image Inputs
แนบ screenshot หรือ design spec ผ่าน command line:
codex -i screenshot.png "Explain this error"
codex --image img1.png,img2.jpg "Summarize these diagrams"
รองรับ PNG และ JPEG
Image Generation
สร้างหรือแก้ไขภาพใน CLI สำหรับ icon, banner, illustration และอื่นๆ:
codex "Generate a banner for my project"
ใช้ gpt-image-2 นับรวมกับ usage limit ทั่วไป และรัน 3-5 เท่าเร็วกว่า turn ปกติที่ไม่มีการสร้างภาพ
Syntax Highlighting และ Themes
ใช้ /theme เพื่อเปิด theme picker, ดูตัวอย่าง theme และบันทึกลง tui.theme ใน ~/.codex/config.toml สามารถเพิ่มไฟล์ .tmTheme เองใน $CODEX_HOME/themes
Local Code Review
พิมพ์ /review เพื่อเปิด review presets:
- Review เทียบกับ base branch
- Review uncommitted changes
- Review specific commit
- Custom review instructions
แต่ละ run จะปรากฏเป็น turn แยกใน transcript
Web Search
Codex มี web search แบบ first-party ที่เปิดใช้งานโดยค่าเริ่มต้นสำหรับงาน local ตั้งค่าผ่าน flags หรือ config.toml:
codex --search # รันครั้งเดียวกับผลลัพธ์แบบ live
web_search = "live" # ตั้งค่าใน config สำหรับ live results
web_search = "disabled" # ปิดการใช้งานทั้งหมด
การรันด้วย Input Prompt
สำหรับคำตอบด่วนโดยไม่ต้องใช้ interactive UI:
codex "explain this codebase"
รวมกับ flags เช่น --path หรือ --model เพื่อปรับพฤติกรรม
Shell Completions
ติดตั้ง completion script สำหรับ bash, zsh หรือ fish:
codex completion bash
codex completion zsh
codex completion fish
เพิ่มในไฟล์ config ของ shell:
# ~/.zshrc
eval "$(codex completion zsh)"
Approval Modes
เปลี่ยน approval mode ผ่าน /permissions ใน interactive session:
- Auto (ค่าเริ่มต้น): อ่านไฟล์, แก้ไข, รันคำสั่งในไดเรกทอรีทำงาน; ถามก่อนเข้าถึง external scope หรือ network
- Read-only: ดูไฟล์โดยไม่แก้ไขหรือรันคำสั่งจนกว่าจะอนุมัติ
- Full Access: ทำงานทั่วเครื่องพร้อม network access โดยไม่ต้องยืนยัน
Scripting Codex
สร้าง automation workflow ด้วย subcommand exec:
codex exec "fix the CI failure"
รัน non-interactively โดย output จะ pipe ไปยัง stdout
การทำงานกับ Codex Cloud
เปิด cloud task จาก terminal:
codex cloud # เปิด interactive picker
codex cloud exec --env ENV_ID "Summarize open bugs"
codex cloud exec --env ENV_ID --attempts 3 "Summarize open bugs"
ใช้ --attempts (1–4) สำหรับ best-of-N runs
Slash Commands
เข้าถึง workflow พิเศษอย่าง /review, /fork, /side หรือสร้าง custom command สำหรับทีม ดูรายละเอียดใน คู่มือ slash commands
Prompt Editor
กด Ctrl+G เพื่อเปิด editor ที่กำหนดโดยตัวแปร environment VISUAL (หรือ EDITOR เป็น fallback) สำหรับเขียน prompt ยาว
Model Context Protocol (MCP)
เชื่อมต่อ tools เพิ่มเติมผ่าน MCP servers ที่ตั้งค่าใน ~/.codex/config.toml หรือจัดการด้วยคำสั่ง codex mcp
Tips และ Shortcuts
- พิมพ์
@ใน composer เพื่อ fuzzy file search - กด Enter ระหว่างรันเพื่อแทรกคำสั่ง; Tab เพื่อ queue follow-up
- นำหน้าบรรทัดด้วย
!เพื่อรัน shell command - กด Esc สองครั้งขณะ composer ว่างเพื่อแก้ไข user message ก่อนหน้า
- ใช้
codex --cd <path>เพื่อเปิดจากไดเรกทอรีใดก็ได้ - ใช้
--add-dirเพื่อเปิด writable root หลายตัวสำหรับการแก้ไขข้ามไดเรกทอรี - ตั้งค่า environment ก่อนเปิด Codex เพื่อประหยัด token ที่ใช้ probe