jvinhit//lab

Search posts

Type to search across journal entries.

navigate open esc close

AI Coding Agent — Master Mindset Guide (2026)

A bilingual master guide to AI coding agents in 2026 — the 5 layers of control (rules, permissions, commands, skills, sub-agents), local vs cloud, single-to-multi-agent progression, prompting, and cost/context management.

Prompts · Rules · Skills · Sub-agents · Agent Teams · Local vs Cloud. Prompts · Rules · Skills · Sub-agents · Agent Teams · Local vs Cloud.

VN


Mục lục

  1. Mental model cốt lõi]
  2. 5 lớp điều khiển agent]
  3. Khi nào dùng cái nào]
  4. Agent local vs cloud]
  5. Tiến trình từ single đến multi-agent]
  6. Nguyên tắc viết prompt]
  7. Workflow hàng ngày]
  8. Quản lý chi phí và context]
  9. Bảng tham chiếu nhanh]

1. Mental model cốt lõi

AI agent không phải autocomplete. Nó là một junior engineer mà bạn delegate cho.

Công việc của bạn không phải viết prompt. Công việc của bạn là thiết kế môi trường để agent hoạt động:

  • Nó biết gì (Rules, docs)
  • Nó được làm gì (Permissions, tools)
  • Nó theo pattern nào (Skills, sub-agents)
  • Nó produce gì (Output formats, validation)

Agent chỉ tốt bằng môi trường bạn xây. Developer giỏi với môi trường tệ vẫn ship code tệ. Agent cũng vậy.

Thay đổi tư duy:

Trước:  "Làm sao viết prompt tốt hơn?"
Bây giờ: "Làm sao xây hệ thống xung quanh agent tốt hơn?"

Mỗi khi agent sai, câu hỏi không phải “tôi rephrase thế nào?” mà là “môi trường thiếu gì khiến sai lầm này xảy ra?“


2. 5 lớp điều khiển agent

Một agent setup hoàn chỉnh có 5 lớp. Mỗi lớp giải quyết vấn đề khác nhau. Đừng skip lớp.

┌─────────────────────────────────────────────────────────────┐
│ Lớp 5: Multi-agent orchestration                            │
│   Sub-agents, Agent Teams                                   │
│   "Delegate công việc cô lập"                               │
├─────────────────────────────────────────────────────────────┤
│ Lớp 4: Skills                                               │
│   .claude/skills/*/SKILL.md                                 │
│   "Kiến thức quy trình + scripts, auto-discover"            │
├─────────────────────────────────────────────────────────────┤
│ Lớp 3: Commands                                             │
│   .claude/commands/*.md                                     │
│   "Prompt template nhanh, gọi thủ công"                     │
├─────────────────────────────────────────────────────────────┤
│ Lớp 2: Permissions + Hooks                                  │
│   .claude/settings.json                                     │
│   "Safety + automation"                                     │
├─────────────────────────────────────────────────────────────┤
│ Lớp 1: Rules (nền tảng)                                     │
│   CLAUDE.md, .cursor/rules/*.mdc                            │
│   "Always-on behavior, conventions, constraints"           │
└─────────────────────────────────────────────────────────────┘

Insight quan trọng: 5 lớp này KHÔNG phải alternatives. Chúng bổ sung cho nhau.


Lớp 1 — Rules

EN

  • What: Behavioral guidelines that load into EVERY session/request
  • Format: CLAUDE.md (Claude Code) or .cursor/rules/*.mdc (Cursor)
  • Cost: Always in context — keep lean (<400 tokens)
  • Use for: Naming conventions, stack constraints, “never do X” rules, code style
  • Don’t use for: Procedural workflows, multi-step processes, scripts

Example rule that works:

Components: PascalCase filename → UserCard.tsx (NOT user-card.tsx)
Named exports only (except files in src/pages/)
NEVER store API data in Zustand → use React Query

Example rule that doesn’t work:

Write clean code      ← too vague
Follow best practices ← unmeasurable
Be careful with types ← AI can't act on this

VN

  • Là gì: Behavioral guidelines load vào MỌI session/request
  • Format: CLAUDE.md (Claude Code) hoặc .cursor/rules/*.mdc (Cursor)
  • Chi phí: Luôn trong context — giữ lean (<400 tokens)
  • Dùng cho: Naming conventions, stack constraints, “never do X” rules, code style
  • Đừng dùng cho: Procedural workflows, multi-step processes, scripts

Rule hoạt động:

Components: PascalCase filename → UserCard.tsx (KHÔNG user-card.tsx)
Named exports only (trừ files trong src/pages/)
NEVER store API data in Zustand → dùng React Query

Rule KHÔNG hoạt động:

Write clean code      ← quá mơ hồ
Follow best practices ← không đo được
Be careful with types ← AI không action được

Lớp 2 — Permissions + Hooks

EN

  • What: Safety boundaries + automatic actions
  • Format: .claude/settings.json
  • Cost: Zero token cost (system-level enforcement)
  • Use for: Restricting dangerous commands, auto-running TypeScript check after edits, denying access to secrets

Example settings.json:

{
  "permissions": {
    "allow": [
      "Bash(pnpm run *)",
      "Bash(npx tsc --noEmit)",
      "Read(./src/**)"
    ],
    "deny": [
      "Bash(git push *)",
      "Bash(rm -rf *)",
      "Read(./.env*)"
    ]
  },
  "hooks": {
    "PostToolUse": [{
      "matcher": "Write(./src/**/*.tsx)",
      "hooks": [{
        "type": "command",
        "command": "npx tsc --noEmit 2>&1 | head -20"
      }]
    }]
  }
}

VN

  • Là gì: Safety boundaries + automatic actions
  • Format: .claude/settings.json
  • Chi phí: Zero token (system-level enforcement)
  • Dùng cho: Restrict dangerous commands, auto-run TypeScript check sau edits, deny access secrets

The settings.json example above applies as-is. Ví dụ settings.json ở trên dùng nguyên xi.


Lớp 3 — Commands

EN

  • What: Reusable prompt templates triggered manually with /command
  • Format: .claude/commands/*.md
  • Cost: Loads when called (~200-500 tokens depending on template)
  • Use for: Workflows you type the same prompt for repeatedly
  • Don’t use for: Behavior that should auto-trigger (use Skills) or workflows needing isolated context (use Sub-agents)

Example /new-component:

Create React component: $ARGUMENTS

Steps:
1. Create folder src/components/$ARGUMENTS/
2. Create $ARGUMENTS.tsx with TypeScript, named export
3. Create $ARGUMENTS.module.scss
4. Create $ARGUMENTS.test.tsx
5. Create index.ts barrel export

Use AntD v4 components. Props interface: ${ARGUMENTS}Props in same file.

Usage: /new-component ProductCard

VN

  • Là gì: Reusable prompt templates trigger thủ công bằng /command
  • Format: .claude/commands/*.md
  • Chi phí: Load khi gọi (~200-500 tokens tùy template)
  • Dùng cho: Workflows bạn gõ cùng prompt lặp lại
  • Đừng dùng cho: Behavior cần auto-trigger (dùng Skills) hoặc workflows cần isolated context (dùng Sub-agents)

Template /new-component ở trên giống nhau ở cả hai ngôn ngữ.


Lớp 4 — Skills

EN

  • What: Procedural knowledge with optional scripts, auto-discovered by description
  • Format: .claude/skills/<name>/SKILL.md (with optional files)
  • Cost: ~100 tokens (metadata) until triggered, then loads body on-demand
  • Key feature: Progressive disclosure — skill can have 50 files but Claude only loads what’s needed
  • Use for: Multi-step workflows, knowledge with reference docs, scripts to execute
  • Don’t use for: Simple style rules (use Rules), one-off prompts (just type them)

Example folder structure:

.claude/skills/handoff/
├── SKILL.md              ← Entry point, YAML frontmatter
├── templates/
│   └── handoff-template.md
└── scripts/
    ├── collect-changes.sh
    └── check-status.sh

SKILL.md anatomy:

---
name: handoff
description: |
  Create HANDOFF.md when context > 60% or ending session.
  Use when: save progress, wrap up, context full.
  Triggers: handoff, save progress, end session.
---

# System prompt body
[Workflow instructions, templates, constraints]

Critical pattern: Use “MUST BE USED for X” in description — this significantly lifts auto-routing priority per Anthropic docs.

VN

  • Là gì: Kiến thức quy trình với optional scripts, auto-discover bằng description
  • Format: .claude/skills/<name>/SKILL.md (với optional files)
  • Chi phí: ~100 tokens (metadata) đến khi trigger, sau đó load body on-demand
  • Tính năng quan trọng: Progressive disclosure — skill có 50 files nhưng Claude chỉ load những gì cần
  • Dùng cho: Multi-step workflows, knowledge với reference docs, scripts để execute
  • Đừng dùng cho: Style rules đơn giản (dùng Rules), one-off prompts (cứ gõ trực tiếp)

Cấu trúc folder và anatomy SKILL.md ở trên áp dụng cho cả hai.

Pattern quan trọng: Dùng “MUST BE USED for X” trong description — pattern này lift auto-routing priority đáng kể theo Anthropic docs.


Lớp 5 — Sub-agents + Agent Teams

EN

Sub-agents are specialized AI instances that handle specific tasks in isolated context windows.

  • Format: .claude/agents/<name>.md (YAML frontmatter + system prompt)
  • Cost: ~7x normal (each has own context) but worth it for context isolation
  • Key insight: Exploration tasks pollute main context with 50K tokens of file reads. Run in sub-agent → main session only sees 500-token summary.
  • Use for: Code review, research, parallel analysis, specialist work
  • Don’t use for: Tasks under 3 files, one-off jobs

Sub-agent example:

---
name: code-reviewer
description: |
  Expert code reviewer. MUST BE USED after code changes.
  Use when: PR ready, before merge, quality check.
tools: Read, Grep, Glob, Bash
model: sonnet
---

You are a senior code reviewer.
[Workflow + output format]

Agent Teams (experimental, requires CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1):

  • Multiple sub-agents that can communicate with each other
  • Used for: agents that need to debate/collaborate in real-time
  • Most use cases don’t need this — sub-agents are sufficient

3 Built-in sub-agents Claude provides:

  1. Explore (Haiku, read-only) — search/analyze codebase
  2. Plan (read-only) — research during plan mode
  3. General-purpose (full tools) — complex multi-step tasks

“If your work fits one of the built-ins, use it. Custom sub-agents are for when it doesn’t.” — Anthropic docs

VN

Sub-agents là specialized AI instances handle tasks cụ thể trong isolated context windows.

  • Format: .claude/agents/<name>.md (YAML frontmatter + system prompt)
  • Chi phí: ~7x bình thường (mỗi agent có context riêng) nhưng đáng giá vì context isolation
  • Insight quan trọng: Exploration tasks pollute main context với 50K tokens. Chạy trong sub-agent → main session chỉ thấy 500-token summary.
  • Dùng cho: Code review, research, parallel analysis, specialist work
  • Đừng dùng cho: Tasks dưới 3 files, one-off jobs

Ví dụ code-reviewer ở trên áp dụng cho cả hai.

Agent Teams (experimental): Multiple sub-agents giao tiếp với nhau real-time. Hầu hết use cases không cần — sub-agents đủ rồi.

3 Built-in sub-agents Claude có sẵn:

  1. Explore (Haiku, read-only) — search/analyze codebase
  2. Plan (read-only) — research trong plan mode
  3. General-purpose (full tools) — complex multi-step tasks

“Nếu công việc của bạn fit một trong built-in, dùng nó. Custom sub-agents chỉ cho khi không fit.” — Anthropic docs


3. Khi nào dùng cái nào

Decision Tree

Bạn có AI coding task. Dùng cái nào?

Q1: Đây là one-time task chắc không lặp lại?
├── CÓ → Chỉ cần viết prompt trực tiếp. Đừng build infrastructure.
└── KHÔNG ↓

Q2: Sẽ pollute context với nhiều file reads/exploration?
├── CÓ → Sub-agent (isolated context)
└── KHÔNG ↓

Q3: Chủ yếu là "behave thế nào" (style, naming, conventions)?
├── CÓ → Rule trong CLAUDE.md
└── KHÔNG ↓

Q4: Cần scripts, executables, hoặc multi-file references?
├── CÓ → Skill (.claude/skills/)
└── KHÔNG ↓

Q5: Prompt bạn gõ cùng kiểu 3+ lần/tuần?
├── CÓ → Command (/cmd)
└── KHÔNG → Chỉ cần viết prompt

Bảng so sánh nhanh

Bảng trên mang tính phổ quát — các khái niệm ánh xạ 1:1 giữa hai ngôn ngữ.


4. Agent local vs cloud

4 cơ chế để AI agents làm việc mà không cần bạn nhìn:

┌─────────────────────────────────────────────────────────────┐
│ 1. Local interactive (mặc định)                             │
│    claude — phiên terminal bạn theo dõi                     │
│    "Feedback loop chặt, bạn duyệt từng bước"                │
├─────────────────────────────────────────────────────────────┤
│ 2. Agent View (local background)                            │
│    claude agents — dashboard các phiên chạy nền             │
│    "Nhiều agent local song song, bạn giám sát"              │
├─────────────────────────────────────────────────────────────┤
│ 3. Headless (CI/CD)                                         │
│    claude -p — chạy một phát, không tương tác               │
│    "Scripts, automation, GitHub Actions"                    │
├─────────────────────────────────────────────────────────────┤
│ 4. Cloud agents                                             │
│    Cursor Background Agents, Routines (claude.ai)           │
│    "Chạy trên cloud VM, bạn quay lại check sau"             │
└─────────────────────────────────────────────────────────────┘

Local Agents — Khi nào và tại sao

EN

Local = runs on your machine, accesses your local filesystem

Use local when:

  • Tight feedback loop needed (refactor, debug, exploration)
  • Work with sensitive code that shouldn’t leave your machine
  • You want to watch and intervene immediately
  • Project requires local-only tools (specific DB, internal services)
  • Cost-sensitive (uses your existing subscription, no extra cloud fees)

Don’t use local when:

  • You want to close laptop and have agent continue
  • Need parallel browser-based UI testing
  • Long-running task (hours) that you can’t supervise

Tools:

  • Claude Code — terminal-native, local-first
  • Cursor (editor mode) — IDE-integrated, local

VN

Local = chạy trên máy bạn, access local filesystem của bạn

Dùng local khi:

  • Cần tight feedback loop (refactor, debug, exploration)
  • Làm việc với sensitive code không nên rời máy
  • Muốn watch và intervene ngay
  • Project cần local-only tools (DB cụ thể, internal services)
  • Cost-sensitive (dùng subscription hiện có, không extra cloud fees)

Đừng dùng local khi:

  • Muốn đóng laptop và agent vẫn chạy tiếp
  • Cần parallel browser-based UI testing
  • Long-running task (hàng giờ) bạn không thể supervise

Tools:

  • Claude Code — terminal-native, local-first
  • Cursor (editor mode) — IDE-integrated, local

Cloud Agents — Khi nào và tại sao

EN

Cloud = runs on remote VM, fire-and-forget, check back later

Use cloud when:

  • Task takes hours and you want to do other work
  • Need parallel agents (8+) without local resource constraints
  • Browser-based testing (Cursor BG agents have full desktop env)
  • Recurring scheduled tasks (Anthropic Routines)
  • Async delegation (PRs from agent, you review later)

Don’t use cloud when:

  • Quick tasks (overhead of context handoff > benefit)
  • Sensitive code that shouldn’t leave your infrastructure
  • Need to intervene mid-task constantly
  • Cost-sensitive (cloud agents add separate billing)

Tools:

  • Cursor Background Agents — up to 8 parallel cloud VMs with desktop env
  • Anthropic Routines (claude.ai) — recurring scheduled or trigger-based
  • GitHub Copilot Cloud Agents — Claude/Codex agents in cloud, integrated with PR workflow

Pricing caveat: Starting June 2026, claude -p (headless) on subscription plans draws from a separate Agent SDK credit pool. Plan CI usage carefully.

VN

Cloud = chạy trên remote VM, fire-and-forget, quay lại check sau

Dùng cloud khi:

  • Task mất hàng giờ và bạn muốn làm việc khác
  • Cần parallel agents (8+) không bị giới hạn local resource
  • Browser-based testing (Cursor BG agents có full desktop env)
  • Recurring scheduled tasks (Anthropic Routines)
  • Async delegation (PRs từ agent, bạn review sau)

Đừng dùng cloud khi:

  • Quick tasks (overhead context handoff > benefit)
  • Sensitive code không nên rời infrastructure
  • Cần intervene giữa task liên tục
  • Cost-sensitive (cloud agents add separate billing)

Tools:

  • Cursor Background Agents — đến 8 parallel cloud VMs với desktop env
  • Anthropic Routines (claude.ai) — recurring scheduled hoặc trigger-based
  • GitHub Copilot Cloud Agents — Claude/Codex agents trên cloud, integrate với PR workflow

Pricing caveat: Từ tháng 6/2026, claude -p (headless) trên subscription plans dùng separate Agent SDK credit pool. Plan CI usage cẩn thận.


Production Stack 2026

Hầu hết teams ship nhanh năm 2026 không pick một — họ compose:

Claude Code (local)        → craftsmanship, refactor, debug, sensitive work
Cursor Background (cloud)  → parallelism, UI testing, async tasks
Claude Routines (cloud)    → recurring jobs (security scans, doc audits)
Headless claude -p (CI)    → automation pipelines

Một API key, nhiều execution surfaces.


5. Single → Multi-agent

Đừng jump thẳng vào multi-agent setup ngày 1. Progress qua từng level:

Level 1 — Single agent + Rules
  - CLAUDE.md với 10-15 rules
  - Permissions trong settings.json
  - Bạn viết prompts trực tiếp
  Đầu tư: 1-2 giờ setup
  Thu lại: Code style nhất quán, không drift convention

Level 2 — Thêm Commands
  - 3-5 commands cho workflows lặp lại (/new-component, /handoff)
  - Hooks cho auto-TypeScript check
  Đầu tư: +2-3 giờ
  Thu lại: Task 5 phút còn 30 giây

Level 3 — Thêm Skills
  - 2-3 skills cho procedural workflows (handoff, codebase-auditor)
  - Skill đầu tiên có scripts (nâng capability)
  Đầu tư: +4-6 giờ
  Thu lại: Workflow phức tạp thành single-command

Level 4 — Thêm Sub-agents
  - Code reviewer (read-only)
  - Test writer (Haiku, tối ưu chi phí)
  - 2-3 specialists (frontend, state, API)
  Đầu tư: +6-8 giờ
  Thu lại: Context isolation, parallel work, chất lượng chuyên biệt

Level 5 — Multi-agent orchestration
  - Builder + validator chains
  - Cost pyramid (Opus orchestrate, Sonnet implement, Haiku search)
  - Cloud agents cho parallel work
  Đầu tư: +10-15 giờ
  Thu lại: Ship features nhanh 3-5x, workflow gần như tự động

Đừng skip levels. Mỗi level build trên những gì bạn học từ level trước. Jump thẳng Level 5 mà không có Level 1 = chaotic agent behavior.


6. Nguyên tắc viết prompt

Even với 5 layers đầy đủ, prompts vẫn quan trọng. Framework CARET:

C — Context     Tình huống là gì? Agent cần biết gì?
A — Action      Cụ thể làm gì?
R — Result      Output trông như thế nào?
E — Examples    Show good examples. Show NOT to do (negative examples mạnh hơn).
T — Test        Làm sao biết đúng?

Ví dụ prompt Tệ vs Tốt và danh sách DON’T/DO ở trên áp dụng cho cả hai ngôn ngữ.

Negative examples bị underrated. Nói cho agent biết KHÔNG làm gì thường effective hơn nói làm gì.


7. Workflow hàng ngày

Bắt đầu một phiên

1. Mở project: cd my-project && claude
2. Context nhanh: /status (xem context %)
3. Nếu resume: "Đọc .claude/HANDOFF.md và tiếp tục từ Next steps"
4. Nếu task mới: paste spec hoặc mô tả task bằng framework CARET

Trong lúc làm

- Theo dõi context %: chuyển session mới ở mức 60-70%
- Dùng sub-agents cho exploration (đừng pollute main context)
- Chạy /agents để xem sub-agents nào có sẵn
- Sau mỗi task lớn: verify (tsc --noEmit, tests pass)

Kết thúc phiên

1. Chạy handoff skill: "create handoff"
2. Skill ghi .claude/HANDOFF.md gồm:
   - Tasks đã xong
   - Việc đang làm + điểm resume chính xác
   - Quyết định quan trọng + lý do
   - Files đã đổi
   - Next steps cho phiên mới
3. Commit code nếu phù hợp
4. Đóng session

Khi agent mắc lỗi

Bước 1: Đừng chỉ fix output. Hỏi: "Tại sao môi trường cho phép điều này?"
Bước 2: Xác định layer nào fail:
   - Sai convention? → Update Rule
   - Sai workflow? → Update Skill hoặc Command
   - Gọi nhầm agent? → Siết lại description
   - Code sai dù rule tốt? → Thêm example/negative example
Bước 3: Update layer đó. Test rằng fix hoạt động.
Bước 4: Đi tiếp.

8. Quản lý chi phí và context

Context window là resource quý nhất. Quản lý nó như RAM.

Chiến lược:

1. Dùng cost pyramid để chọn model:

Haiku (~25x rẻ hơn Opus)
  ↑ search, summarize, read tasks đơn giản

Sonnet (cân bằng)
  ↑ implementation, code review

Opus (đắt nhất)
  ↑ orchestration, quyết định architecture

2. Sub-agents cho task nặng context:

  • Search qua 50 files? → Sub-agent (Haiku, read-only)
  • Code review PR lớn? → Sub-agent (Sonnet, read-only)
  • Kết quả trả về dạng summary, không phải 50.000 tokens nội dung file

3. Skills không load đến khi cần:

  • Skill metadata: ~100 tokens
  • Body chỉ load khi trigger
  • Linked files chỉ load khi SKILL.md reference tới
  • Skill 50 files có thể “installed” mà không tốn context

4. /clear giữa các task không liên quan:

  • Session dài tích lũy lịch sử exploration ngõ cụt
  • Mỗi lượt gửi lại toàn bộ
  • /clear cắt 30-50% chi phí mỗi message

5. Stop idle agents:

  • Background agents/sub-agents idle = vẫn tốn quota
  • /stop khi task xong
  • Một phiên Opus idle không miễn phí

6. Handoff trước khi context đầy:

  • Chất lượng giảm sau 70% context
  • Auto-compact mất thông tin
  • Chạy handoff skill ở 60% → bắt đầu session mới

9. Bảng tham chiếu nhanh

Bố cục file, cheatsheet lệnh, và bảng rule-of-thumb ở trên trung lập ngôn ngữ — dùng nguyên xi.


Suy nghĩ cuối

Sự thay đổi mindset khó nhất năm 2026 không phải học tools mới. Đó là học rằng:

  1. Công việc của bạn là environment design, không phải prompt writing
  2. Mistakes là signals về environment, không phải về agent
  3. Layers compound — Rules + Commands + Skills + Sub-agents > tổng các phần
  4. Đừng over-engineer — Skip layers chưa cần
  5. Iterate — Setup không bao giờ “xong”, nó evolve theo codebase

Teams ship nhanh nhất năm 2026 đầu tư 20-40 giờ vào agent infrastructure. Đó là 1 tuần làm việc để có permanent multiplier cho mọi task tương lai.

Mindset: Treat agent setup như product code. Version control, review, refactor, test.


Sources: Anthropic Engineering blog · code.claude.com/docs · Cursor changelog · verified May 2026.