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 vi | Token dùng | Phù hợp |
|---|---|---|---|
| Auto-Complete (Tab) | Một dòng | 1 credit | Điền code nhanh |
| Cmd+K (Inline Edit) | Một file | 1 credit | Sửa chỗ cụ thể |
| Chat (Ctrl+L) | Hỏi/giải thích | 1 credit | Hỏi syntax, xem context |
| Agent Mode (Ctrl+I → Agent) | Nhiều file + run command | 1–3 credits | refactor, feature mới, fix bug |
| Composer | multi-file edit structured | bundled | Tạo feature cả cục |
| Cloud Agent | chạy trên cloud | usage-based | long-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:
- Codex = giỏi multi-step reasoning, tạo test, debug sâu
- GPT-4o = giỏi autocomplete / general code
- 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
- Mở Cursor → Settings (Cmd+, / Ctrl+,)
- Vào Features → Model Context Protocol
- 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
- Đóng Cursor rồi mở lại
- Nhấn Ctrl+I (mở Composer/Agent)
- Ở 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.tsNế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 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 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 README6 kỹ thuật dùng Agent Mode tiết kiệm (không đốt quota vô ích)
- Scope bằng @Files không phải @Codebase — giảm token 50–70%
- Pin model = Codex cho reasoning, Sonnet 3.5 cho refactor
- Chia việc thành phần nhỏ — 1 Agent task / 1 feature không quá 5 file
- Dùng Cloud Agent cho việc long-running (build, migration)
- Đặt Spend Limit $5–10/tháng — chống auto-charge shock
- 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ụ:
- Cursor + Sonnet = viết code thường (nhanh, rẻ)
- Cursor + Codex = lệnh refactor / debug cần reasoning sâu
- 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)
- Cursor Docs — Model Context Protocol
- OpenAI Platform — Codex API Reference
- Anthropic — Claude Code Documentation

