Bỏ qua để đến nội dung

Tối ưu Task

Thời gian ước tính: ~30 phút

Yêu cầu trước: Phase 6 (Thinking & Planning)

Kết quả: Sau module này, bạn sẽ biết structure task tối ưu, hiểu task granularity, và tránh task-framing mistake.


Bạn yêu cầu Claude “build complete authentication system.” Ba mươi phút sau, bạn có một mớ hỗn độn không match architecture. Hoặc Claude stuck, loop, và produce nothing useful.

Cùng mục tiêu, cách tiếp cận khác: “Đầu tiên, design auth architecture. Sau đó implement login. Rồi registration. Rồi password reset.” Mỗi step clear, checkable, và build on previous.

Task optimization không phải về Claude — mà về cách BẠN structure work.


Too Large Optimal Zone Too Small
─────────────────────────────────────────────────────────
"Build cả app" "Implement login" "Add semicolon"
↓ ↓ ↓
Overwhelm Clear scope Micromanagement
Stuck Checkable Không hiệu quả
Poor quality Builds momentum Context overhead
Đặc điểmTask TốtTask Xấu
ScopeSingle feature/function”Build everything”
Time5-20 phút Claude timeHàng giờ work
OutputVerifiable deliverableVague “progress”
DependenciesClear inputUnclear requirement
SuccessTestableSubjective
Pattern 1: Vertical Slice
Big Feature → [Design] → [Core Logic] → [UI] → [Tests]
Pattern 2: Component-Based
System → [Component A] → [Component B] → [Integration]
Pattern 3: Iterative Refinement
V1 (Basic) → V2 (+ Feature) → V3 (+ Polish)

Mỗi task phải end với something bạn có thể verify. Nếu Claude đi sai, bạn catch sớm. Small correction tốt hơn major rewrite.

Large task làm context bị polluted. Fresh context per task cho cleaner result. Dùng /clear hoặc new session cho task mới.


Scenario: Build user authentication system.

Bạn: Build complete user authentication system với login,
registration, password reset, email verification, OAuth,
session management, và role-based access control.
Claude: [Bắt đầu build... 30 phút sau]
Kết quả:
- 2000 dòng code tangled
- Mixed pattern (lúc JWT, lúc session)
- Thiếu error handling
- Không test được từng phần
- Không match existing architecture

Task 1: Design (5 min)

Bạn: Design authentication system architecture cho Express app.
Requirements: JWT-based, PostgreSQL storage, refresh tokens.
Output: Architecture diagram và file structure.
Claude: [Produces clear design]

✓ Checkpoint: Review design trước khi implement

Task 2: Core Auth (10 min)

Bạn: Dựa trên design, implement core auth module:
- JWT token generation và verification
- Password hashing với bcrypt
Create: src/auth/tokens.ts và src/auth/passwords.ts
Claude: [Implement focused module]

✓ Checkpoint: Test JWT function hoạt động

Task 3: Login Endpoint (10 min)

Bạn: Implement POST /api/auth/login endpoint dùng auth module
vừa tạo. Include validation và error handling.
Claude: [Implement clean endpoint]

✓ Checkpoint: Test login với curl

Task 4: Registration (10 min)

Bạn: Implement POST /api/auth/register theo pattern giống login.
Thêm email uniqueness check.
Claude: [Consistent implementation]

✓ Checkpoint: Test registration

Giant TaskOptimized Task
30 min, poor quality35 min total, high quality
Code tangledModular, consistent
Khó debugMỗi phần được test
Cần refactor lớnSẵn sàng production
1 checkpoint4 checkpoint

Mục tiêu: Break large feature thành optimal task.

Hướng dẫn:

  1. Lấy một large feature bạn cần build
  2. Break thành 4-6 task theo pattern
  3. Cho mỗi task, define: scope, output, success criteria
  4. Estimate Claude time (aim 5-15 min)
💡 Gợi ý

Bắt đầu với design, rồi core logic, rồi integration point. Mỗi task phải produce something testable.

✅ Giải pháp

Ví dụ cho “Build REST API cho blog posts”:

  1. Design API endpoint và data model (10 min)
  2. Implement Post model và database schema (10 min)
  3. Implement CRUD endpoint (15 min)
  4. Add validation và error handling (10 min)
  5. Write integration test (15 min)

Mỗi task có clear output và verify được trước khi tiếp.

Mục tiêu: Tạo verification point cho task.

Hướng dẫn:

  1. Cho các task đã decompose, identify cần verify gì
  2. Define: Test/check gì sau mỗi task?
  3. “Wrong” trông như thế nào ở mỗi checkpoint?
💡 Gợi ý

Good checkpoint: “Build pass không?”, “Test pass không?”, “curl return expected response không?”

✅ Giải pháp

Cho blog API task:

  • Sau design: Review và approve architecture
  • Sau model: Run migration, thấy table trong DB
  • Sau endpoint: curl mỗi endpoint thành công
  • Sau validation: Invalid input return proper error
  • Sau test: Tất cả test pass

Mục tiêu: Trải nghiệm impact của task size.

Hướng dẫn:

  1. Pick một small feature (ví dụ: “add search to list”)
  2. Thử 3 approach: one giant, optimal chunk, micro-step
  3. Compare: time, quality, mental load của bạn
💡 Gợi ý

Micro-step: “Add import”, “Add function signature”, “Add dòng đầu tiên”…

✅ Giải pháp

Bạn sẽ thấy: Giant = quality unpredictable. Micro = tedious, mất momentum. Optimal (2-3 focused task) = best balance.


  • 5-20 phút Claude time
  • Single clear deliverable
  • Testable output
  • Fresh context
PatternFlow
VerticalDesign → Core → UI → Tests
ComponentPart A → Part B → Integrate
IterativeV1 → V2 → V3
Goal: [Đạt được gì]
Context: [Code/decision liên quan]
Output: [Deliverable cụ thể]
Constraints: [Pattern follow, thing avoid]
  • Có thể verify nó hoạt động không?
  • Có match design không?
  • Có consistent với task trước không?
  • Claude hỏi nhiều clarifying question
  • Output mix different approach
  • Tốn > 20 phút
  • Không dễ test result

❌ Sai✅ Đúng
”Build everything at once”Decompose thành task 5-15 min
Vague success criteriaDefine testable output
Không có checkpointVerify sau mỗi task
Skip design phaseDesign trước, implement sau
Tiếp tục khi lostStop, /clear, restart với smaller task
Cùng context cho nhiều taskFresh context per major task
Micro-manage từng dòngTrust Claude với reasonable scope

Scenario: Startup Việt Nam cần build payment integration (VNPay + MoMo). Lần đầu: one giant task.

Lần 1 (Thất bại):

"Implement payment integration supporting VNPay và MoMo
với webhook, refund, và transaction logging."
Kết quả: 3 giờ, code không dùng được, mixed pattern, bug khắp nơi.

Lần 2 (Optimized):

TaskTimeStatus
Design payment architecture15 min
Payment interface/abstract class10 min
VNPay implementation20 min
VNPay webhook handler15 min
MoMo implementation20 min
Transaction logging15 min
Integration test25 min

Total: 2 giờ → Production-ready, consistent pattern, tested từng step.

So sánh:

  • Giant task: 3 giờ → không dùng được
  • Optimized: 2 giờ → production-ready

Quote: “Approach ‘chậm’ làm task nhỏ actually nhanh gấp đôi và quality gấp 10 lần.”


Tiếp theo: Module 14.2: Tối ưu Tốc độ