สารบัญ
· ngaicode · Cursor · 4 min read

บทความ 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 command1–3 creditsrefactor, feature ใหม่, fix bug
Composermulti-file edit structuredbundledสร้าง feature ทั้งก้อน
Cloud Agentrun บน cloudusage-basedlong-running task

OpenAI Codex คืออะไร? ใช้ทำอะไรใน Cursor?

Codex คือ reasoning/agent model ของ OpenAI ที่ออกแบบมาสำหรับ coding tasks โดยเฉพาะ:

  1. Codex = เก่ง multi-step reasoning, สร้าง test, debug ลึก
  2. GPT-4o = เก่ง autocomplete / general code
  3. o1 / o3 = reasoning model สำหรับ algorithm ซับซ้อน

ใน Cursor คุณสามารถเปิด Codex ผ่าน MCP แล้วใช้เป็น model หนึ่งในตัวเลือก โดยไม่ต้องออกจาก IDE


Step-by-Step: ติดตั้ง MCP เพื่อใช้ Codex ใน Cursor

Step 1: เปิด MCP Settings

  1. เปิด Cursor → Settings (Cmd+, / Ctrl+,)
  2. ไปที่ Features → Model Context Protocol
  3. คลิก “+ 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

  1. ปิด Cursor แล้วเปิดใหม่
  2. กด Ctrl+I (เปิด Composer/Agent)
  3. ที่มุมขวาบน เลือก 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 tests

Pattern 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 README

6 เทคนิคใช้ Agent Mode ให้คุ้ม (ไม่เผา quota เปล่า)

  1. Scope ด้วย @Files ไม่ใช่ @Codebase — ลด token 50–70%
  2. Pin model = Codex สำหรับ reasoning, Sonnet 3.5 สำหรับ refactor
  3. แบ่งงานเป็นชิ้นเล็ก — 1 Agent task ต่อ 1 feature ไม่เกิน 5 ไฟล์
  4. ใช้ Cloud Agent สำหรับงาน long-running (build, migration)
  5. ตั้ง Spend Limit $5–10/เดือน — ป้องกัน auto-charge shock
  6. 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│
└─────────────────────────────────────────────┘

ตัวอย่าง:

  1. Cursor + Sonnet = เขียนโค้ดตามปกติ (เร็ว ถูก)
  2. Cursor + Codex = สั่ง refactor / debug ที่ต้อง reasoning ลึก
  3. Claude Code CLI = สั่งงาน multi-file ที่ context ยาวมาก (เช่น migrate ทั้ง repo)

ดูบทความ C สำหรับการเปรียบเทียบ 3 ตัวนี้แบบละเอียด


ngaicode ขาย Cursor Pro ในราคาคนไทย จ่ายผ่าน PromptPay ได้ — ราคาเริ่มต้น 49 ฿ ทดลอง 1 วัน พร้อม Line OA ซัพพอร์ต ตอบจริง


📚 แหล่งอ้างอิง (References)

  1. Cursor Docs — Model Context Protocol
  2. OpenAI Platform — Codex API Reference
  3. Anthropic — Claude Code Documentation
กลับสู่บล็อก

บทความที่เกี่ยวข้อง

ดูทั้งหมด »
Line OA