Đọc bằng ngôn ngữ:
Mục lục
· ngaicode · Cursor · 5 min read

Hướng dẫn dùng Cursor Agent Mode + Codex tiết kiệm nhất

📚 ngaicode Knowledge Base · Published 2026-08-16

Hướng dẫn dùng Cursor Agent Mode + Codex tiết kiệm nhất

Slug: cursor-agent-mode-codex-tutorial-2026Meta Title: Hướng dẫn dùng Cursor Agent Mode + Codex tiết kiệm nhất | ngaicode Meta Description: Cách dùng Cursor Agent Mode với OpenAI Codex với nhau step-by-step kèm MCP setup, prompt ví dụ, kỹ thuật pin model, và workflow dùng được thật trong 2026 Target Keywords: Cursor Agent Mode, Codex, MCP, Composer, AI coding Vietnam Target Persona: Dev muốn dùng Cursor + Codex cho tiết kiệm, không đốt quota vô ích Published: 2026-08-16 · Author: ngaicode Vietnam


Tóm tắt (TL;DR)

Cursor Agent Mode + OpenAI Codex dùng với nhau qua MCP (Model Context Protocol) sẽ được workflow mạnh nhất trong năm 2026 — Cursor đóng vai trò IDE + Agent orchestration, Codex là reasoning model cho việc khó. Bắt đầu bằng 3 bước: (1) cài MCP server (2) pin Codex làm fallback model (3) viết prompt có cấu trúc rõ ràng.


Cursor Agent Mode là gì? Khác Copilot/Cmd+K thế nào?

Chế độPhạm viToken dùngPhù hợp
Auto-Complete (Tab)Một dòng1 creditĐiền code nhanh
Cmd+K (Inline Edit)Một file1 creditSửa chỗ cụ thể
Chat (Ctrl+L)Hỏi/giải thích1 creditHỏi syntax, xem context
Agent Mode (Ctrl+I → Agent)Nhiều file + run command1–3 creditsrefactor, feature mới, fix bug
Composermulti-file edit structuredbundledTạo feature cả cục
Cloud Agentchạy trên cloudusage-basedlong-running task

OpenAI Codex là gì? Dùng để làm gì trong Cursor?

Codex là reasoning/agent model của OpenAI được thiết kế riêng cho coding tasks:

  1. Codex = giỏi multi-step reasoning, tạo test, debug sâu
  2. GPT-4o = giỏi autocomplete / general code
  3. o1 / o3 = reasoning model cho thuật toán phức tạp

Trong Cursor bạn có thể bật Codex qua MCP rồi dùng làm một trong các model lựa chọn, không cần rời IDE


Step-by-Step: Cài MCP để dùng Codex trong Cursor

Step 1: Mở MCP Settings

  1. Mở Cursor → Settings (Cmd+, / Ctrl+,)
  2. Vào Features → Model Context Protocol
  3. Click ”+ Add new global MCP server”

Step 2: Thêm OpenAI Codex MCP

Dán config bên dưới vào file ~/.cursor/mcp.json:

{
  "mcpServers": {
    "openai-codex": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-openai-codex"],
      "env": {
        "OPENAI_API_KEY": "sk-xxxxxxxxxxxxxxxxxxxx"
      }
    }
  }
}

Step 3: Khởi động lại Cursor

  1. Đóng Cursor rồi mở lại
  2. Nhấn Ctrl+I (mở Composer/Agent)
  3. Ở góc trên bên phải chọn model → sẽ thấy Codex xuất hiện

Step 4: Test bằng prompt đơn giản

@Codex review this file and suggest 3 performance improvements:
@File: src/api/users.ts

Nếu Codex trả lời = cài thành công


5 Prompt Patterns dùng Codex + Agent Mode tiết kiệm nhất

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 Vietnamese language for comments (dự án này dev Việt).

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 kỹ thuật dùng Agent Mode tiết kiệm (không đốt quota vô ích)

  1. Scope bằng @Files không phải @Codebase — giảm token 50–70%
  2. Pin model = Codex cho reasoning, Sonnet 3.5 cho refactor
  3. Chia việc thành phần nhỏ — 1 Agent task / 1 feature không quá 5 file
  4. Dùng Cloud Agent cho việc long-running (build, migration)
  5. Đặt Spend Limit $5–10/tháng — chống auto-charge shock
  6. Subscribe Pro+ ($60/tháng) nếu dùng quá 500 lần/tháng — được 3x quota

Workflow ví dụ: Cursor + Codex + Claude Code dùng với nhau

┌─────────────────────────────────────────────┐
│  Cursor (IDE chính)                         │
│  ├── Sonnet 3.5: autocomplete + Cmd+K       │
│  ├── Codex (MCP): reasoning + multi-file    │
│  └── Claude Code (CLI): long-context refactor│
└─────────────────────────────────────────────┘

Ví dụ:

  1. Cursor + Sonnet = viết code thường (nhanh, rẻ)
  2. Cursor + Codex = lệnh refactor / debug cần reasoning sâu
  3. Claude Code CLI = lệnh multi-file context dài (ví dụ migrate cả repo)

Xem bài viết C để so sánh chi tiết 3 công cụ này


🔗 Tài nguyên liên quan

ngaicode bán Cursor Pro với giá người Việt, thanh toán qua PayPal hoặc USDT-TRC20 được — giá bắt đầu ₫39,000 thử 1 ngày, kèm Zalo hỗ trợ, trả lời thật


📚 Tham khảo (References)

  1. Cursor Docs — Model Context Protocol
  2. OpenAI Platform — Codex API Reference
  3. Anthropic — Claude Code Documentation
Quay lại Blog

Bài viết liên quan

Xem tất cả »
Zalo / WhatsApp