บทความ B — สอนวิธีใช้ Cursor Agent Mode + Codex ให้คุ้มค่าที่สุด
📚 ngaicode Knowledge Base · Published 2026-08-16
บทความ B — สอนวิธีใช้ Cursor Agent Mode + Codex ให้คุ้มค่าที่สุด
Slug: cursor-agent-mode-codex-tutorial-2026Meta Title: สอนวิธีใช้ Cursor Agent Mode + Codex ให้คุ้มค่าที่สุด | ngaicode Meta Description: วิธีใช้ Cursor Agent Mode กับ OpenAI Codex ด้วยกันแบบ step-by-step พร้อม MCP setup, prompt ตัวอย่าง, เทคนิค pin model, และ workflow ที่ใช้ได้จริงใน 2026 Target Keywords: Cursor Agent Mode, Codex, MCP, Composer, AI coding Thailand Target Persona: Dev ที่อยากใช้ Cursor + Codex ให้คุ้ม ไม่เผา quota เปล่าๆ Published: 2026-08-16 · Author: ngaicode Thailand
สรุปย่อ (TL;DR)
Cursor Agent Mode + OpenAI Codex ใช้ด้วยกันผ่าน MCP (Model Context Protocol) จะได้ workflow ที่ทรงพลังที่สุดในปี 2026 — Cursor ทำหน้าที่เป็น IDE + Agent orchestration, Codex เป็น reasoning model สำหรับงานยาก เริ่มต้นด้วย 3 ขั้นตอน: (1) ติดตั้ง MCP server (2) pin Codex เป็น fallback model (3) เขียน prompt ที่มี structure ชัดเจน
Cursor Agent Mode คืออะไร? ต่างจาก Copilot/Cmd+K ยังไง?
| โหมด | ขอบเขต | Token ใช้ | เหมาะกับ |
|---|---|---|---|
| Auto-Complete (Tab) | บรรทัดเดียว | 1 credit | เติมโค้ดเร็วๆ |
| Cmd+K (Inline Edit) | ไฟล์เดียว | 1 credit | แก้เฉพาะจุด |
| Chat (Ctrl+L) | ถาม/อธิบาย | 1 credit | ถาม syntax, ดู context |
| Agent Mode (Ctrl+I → Agent) | หลายไฟล์ + run command | 1–3 credits | refactor, feature ใหม่, fix bug |
| Composer | multi-file edit structured | bundled | สร้าง feature ทั้งก้อน |
| Cloud Agent | run บน cloud | usage-based | long-running task |
OpenAI Codex คืออะไร? ใช้ทำอะไรใน Cursor?
Codex คือ reasoning/agent model ของ OpenAI ที่ออกแบบมาสำหรับ coding tasks โดยเฉพาะ:
- Codex = เก่ง multi-step reasoning, สร้าง test, debug ลึก
- GPT-4o = เก่ง autocomplete / general code
- o1 / o3 = reasoning model สำหรับ algorithm ซับซ้อน
ใน Cursor คุณสามารถเปิด Codex ผ่าน MCP แล้วใช้เป็น model หนึ่งในตัวเลือก โดยไม่ต้องออกจาก IDE
Step-by-Step: ติดตั้ง MCP เพื่อใช้ Codex ใน Cursor
Step 1: เปิด MCP Settings
- เปิด Cursor → Settings (Cmd+, / Ctrl+,)
- ไปที่ Features → Model Context Protocol
- คลิก “+ Add new global MCP server”
Step 2: เพิ่ม OpenAI Codex MCP
วาง config ด้านล่างในไฟล์ ~/.cursor/mcp.json:
{
"mcpServers": {
"openai-codex": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-openai-codex"],
"env": {
"OPENAI_API_KEY": "sk-xxxxxxxxxxxxxxxxxxxx"
}
}
}
}Step 3: รีสตาร์ท Cursor
- ปิด Cursor แล้วเปิดใหม่
- กด Ctrl+I (เปิด Composer/Agent)
- ที่มุมขวาบน เลือก model → จะเห็น Codex เพิ่มเข้ามา
Step 4: ทดสอบด้วย prompt ง่ายๆ
@Codex review this file and suggest 3 performance improvements:
@File: src/api/users.tsถ้า Codex ตอบกลับมา = ติดตั้งสำเร็จ
5 Prompt Patterns ที่ใช้ Codex + Agent Mode ได้คุ้มสุด
Pattern 1 — Multi-file Refactor
@Codex using Agent Mode, refactor the following:
- Move all auth logic from src/middleware/* to src/auth/*
- Update all imports
- Run `npm test` after each change
- Don't break existing testsPattern 2 — Bug Investigation
@Codex this test is failing: `npm test -- user.test.ts`
@File: src/services/user.ts
@File: src/services/user.test.ts
Find the root cause and fix it. Add a regression test.Pattern 3 — Generate Test Suite
@Codex generate unit tests for @Files in src/utils/
Target coverage: 90%. Use vitest. Mock all external APIs.Pattern 4 — Document Legacy Code
@Codex for each @File in src/legacy/, write a JSDoc comment
explaining what the function does, inputs, outputs, side effects.
Use Thai language for comments (โปรเจกต์นี้ dev ไทย).Pattern 5 — Add Feature End-to-End
@Codex using Agent Mode, implement the "Reset Password" feature:
- Add /api/auth/reset endpoint
- Send email via SendGrid
- Add React component on /forgot-password page
- Write tests
- Update README6 เทคนิคใช้ Agent Mode ให้คุ้ม (ไม่เผา quota เปล่า)
- Scope ด้วย @Files ไม่ใช่ @Codebase — ลด token 50–70%
- Pin model = Codex สำหรับ reasoning, Sonnet 3.5 สำหรับ refactor
- แบ่งงานเป็นชิ้นเล็ก — 1 Agent task ต่อ 1 feature ไม่เกิน 5 ไฟล์
- ใช้ Cloud Agent สำหรับงาน long-running (build, migration)
- ตั้ง Spend Limit $5–10/เดือน — ป้องกัน auto-charge shock
- Subscribe Pro+ ($60/เดือน) ถ้าใช้เกิน 500 ครั้ง/เดือน — ได้ 3x quota
Workflow ตัวอย่าง: Cursor + Codex + Claude Code ใช้ด้วยกัน
┌─────────────────────────────────────────────┐
│ Cursor (IDE หลัก) │
│ ├── Sonnet 3.5: autocomplete + Cmd+K │
│ ├── Codex (MCP): reasoning + multi-file │
│ └── Claude Code (CLI): long-context refactor│
└─────────────────────────────────────────────┘ตัวอย่าง:
- Cursor + Sonnet = เขียนโค้ดตามปกติ (เร็ว ถูก)
- Cursor + Codex = สั่ง refactor / debug ที่ต้อง reasoning ลึก
- Claude Code CLI = สั่งงาน multi-file ที่ context ยาวมาก (เช่น migrate ทั้ง repo)
ดูบทความ C สำหรับการเปรียบเทียบ 3 ตัวนี้แบบละเอียด
🔗 Related Resources (แหล่งข้อมูลที่เกี่ยวข้อง)
ngaicode ขาย Cursor Pro ในราคาคนไทย จ่ายผ่าน PromptPay ได้ — ราคาเริ่มต้น 49 ฿ ทดลอง 1 วัน พร้อม Line OA ซัพพอร์ต ตอบจริง
📚 แหล่งอ้างอิง (References)
- Cursor Docs — Model Context Protocol
- OpenAI Platform — Codex API Reference
- Anthropic — Claude Code Documentation

