OpenCode.io.vn
Quay lại Blog
1 tháng 2, 2026OpenCode Vietnam15 phút đọc

10 Mẹo Sử Dụng Claude Code Từ Người Tạo Ra Nó - Boris Cherny

Boris Cherny - creator của Claude Code - chia sẻ 10 mẹo sử dụng từ chính team của ông. Chi tiết từ Worktrees, Plan Mode, CLAUDE.md đến Skills và Subagents.

#claude-code#tips#productivity#workflow#ai-coding#best-practices

10 Mẹo Sử Dụng Claude Code Từ Người Tạo Ra Nó - Boris Cherny

Bạn có biết Boris Cherny là ai không? Ông là người tạo ra Claude Code - công cụ AI coding assistant đang được hàng triệu developer trên thế giới sử dụng. Gần đây, Boris đã chia sẻ 10 mẹo sử dụng Claude Code mà chính team của ông áp dụng hàng ngày.

Tin vui cho người dùng OpenCode: Vì OpenCode được xây dựng trên nền tảng Claude Code, tất cả các mẹo này đều áp dụng được 100% trong OpenCode! Bài viết này sẽ giải thích chi tiết từng mẹo, kèm theo hướng dẫn cụ thể cách áp dụng trong OpenCode.


1. Làm Nhiều Việc Song Song (Do More in Parallel)

Vấn Đề Với Cách Làm Truyền Thống

Khi bạn chỉ làm việc trên một branch duy nhất, mọi thứ phải được thực hiện tuần tự:

Bạn đang code feature A → Boss gọi fix bug urgent
→ Phải git stash, checkout branch mới, fix bug
→ Quay lại feature A → git stash pop
→ Context bị gián đoạn, code dở dang bị quên

Đây là vấn đề context switching - mỗi lần chuyển đổi giữa các task, bạn mất thời gian để "nhớ lại" mình đang làm gì.

Giải Pháp: Git Worktrees

Git Worktree cho phép bạn có nhiều thư mục làm việc cùng lúc từ một repository:

# Repo chính - đang làm feature login
~/myapp (branch main)

# Worktree 1 - feature payment
~/myapp/worktree-payment (branch feature-payment)

# Worktree 2 - fix bug
~/myapp/worktree-fixbug (branch hotfix)

# Worktree 3 - chỉ để phân tích logs
~/myapp/worktree-analysis

Cách tạo worktree:

# Tạo worktree mới từ branch
git worktree add ~/myapp/worktree-login feature-login

# Tạo worktree từ commit cụ thể
git worktree add ~/myapp/worktree-hotfix 3a4b2c1

# Xem danh sách worktrees
git worktree list

# Xóa worktree khi dùng xong
git worktree remove ~/myapp/worktree-login

Cách Team Claude Code Sử Dụng

Boris chia sẻ: "Spin up 3-5 git worktrees at once, each running its own Claude session in parallel. It's the single biggest productivity unlock."

┌──────────────────┐  ┌──────────────────┐  ┌──────────────────┐
│ Terminal 1       │  │ Terminal 2       │  │ Terminal 3       │
│ ~/myapp          │  │ ~/myapp/wt-pay   │  │ ~/myapp/wt-fix   │
│ Claude Session A │  │ Claude Session B │  │ Claude Session C │
│ Feature A ✅     │  │ Feature B ✅     │  │ Bug Fix ✅       │
└──────────────────┘  └──────────────────┘  └──────────────────┘

Tips từ team:

  • Đặt shell aliases để nhảy nhanh giữa các worktrees
  • Có một worktree riêng chỉ để đọc logs và chạy query (analysis worktree)
  • Claude Desktop có native support cho worktrees

Áp dụng trong OpenCode:

# Mở 3 terminal, mỗi terminal một worktree
# Terminal 1
cd ~/myapp && opencode

# Terminal 2
cd ~/myapp/worktree-payment && opencode

# Terminal 3
cd ~/myapp/worktree-hotfix && opencode

Mỗi session OpenCode hoạt động độc lập, bạn có thể làm 3 features cùng lúc!


2. Bắt Đầu Mọi Task Phức Tạp Ở Chế Độ Plan Mode

Plan Mode Là Gì?

Plan mode là chế độ Claude chỉ phân tích và lập kế hoạch, không viết code ngay. Đây là bước chuẩn bị quan trọng nhất.

Tại Sao Plan Mode Quan Trọng?

CÁCH SAI (Không dùng plan mode):
User: "Thêm tính năng thanh toán"
Claude: "OK tôi viết đây" → Code lung tung → Sai → Sửa → Sai → Sửa...
Thời gian: 2 giờ, 5 lần review, 10 lần edit

CÁCH ĐÚNG (Dùng plan mode):
User: "Thêm tính năng thanh toán Stripe"
Claude (plan mode):
1. Tạo Stripe service wrapper
2. Thêm API endpoint /api/checkout
3. Implement webhook handler
4. Viết unit tests
5. Update database schema

→ User review và approve plan
→ Claude implement theo plan → Đúng ngay lần đầu
Thời gian: 30 phút, 0 lần sửa

Chiến Lược Review Plan

Một số thành viên trong team Claude Code làm như sau:

  1. Session 1: Claude viết plan
  2. Session 2 (Claude khác): Review plan như một "staff engineer"
  3. Session 1: Update plan dựa trên feedback
  4. Thực hiện: Khi plan hoàn hảo mới implement

Quy Tắc Vàng

"Moment something goes sideways, switch back to plan mode and re-plan. Don't keep pushing."

Khi thấy code không đúng hướng:

❌ Tiếp tục code hy vọng sẽ đúng
✅ Dừng lại → Quay về plan mode → Nghĩ lại từ đầu

Yêu cầu Claude vào plan mode ngay cả khi verification:

"Trước khi merge, hãy vào plan mode và verify lại implementation này có đáp ứng requirements không."

Áp dụng trong OpenCode: Nhấn Shift+Tab để toggle Plan Mode, hoặc gõ trực tiếp:

/plan Thêm tính năng thanh toán Stripe

OpenCode sẽ đưa ra kế hoạch chi tiết trước khi code. Bạn review, approve rồi mới bắt đầu implement.


3. Đầu Tư Vào CLAUDE.md

CLAUDE.md Là Gì?

CLAUDE.md là một file markdown đặt ở root của project, chứa các quy tắc riêng cho dự án của bạn. Mỗi khi Claude đọc project, nó sẽ đọc file này trước.

Ví Dụ CLAUDE.md Hiệu Quả

# Project Rules cho E-commerce Platform

## Code Style
- Sử dụng TypeScript, không bao giờ dùng `any`
- Functional components trong React
- Dùng Tailwind CSS cho styling
- Import order: React → Third-party → Internal → Styles

## Testing
- Viết tests cho tất cả functions mới
- Coverage tối thiểu 80% cho business logic
- Mock API calls trong unit tests

## Git
- Commit message format: "type(scope): description"
- Squash commits trước khi merge PR
- Mỗi PR không quá 500 dòng code

## Security
- KHÔNG BAO GIỜ log passwords hoặc secrets
- Validate tất cả inputs từ client
- Sử dụng prepared statements cho SQL queries

## Error Handling
- Always use try-catch cho async operations
- Log errors với context đầy đủ
- Never swallow exceptions silently

Cách Sử Dụng Hiệu Quả

Sau mỗi lần Claude mắc lỗi:

Claude: "Tôi đã fix bug xong"
User: "Update your CLAUDE.md so you don't make that mistake again"
Claude: [Tự viết rule vào CLAUDE.md]

Ví dụ:
# Trước đây Claude hay quên validate input
→ Claude thêm: "ALWAYS validate and sanitize all user inputs"

# Trước đây Claude hay dùng `var`
→ Claude thêm: "Use `const` by default, `let` only when reassigning"

Mở Rộng: Notes Directory

Một số người chỉ CLAUDE.md đến thư mục notes riêng:

# CLAUDE.md
Xem thêm tài liệu tại @docs/
docs/
├── architecture.md      # Thiết kế hệ thống
├── api-endpoints.md     # API documentation
├── common-bugs.md       # Các bug thường gặp
└── coding-standards.md  # Tiêu chuẩn code

Kết quả sau vài tuần: Claude gần như không mắc lỗi cũ nữa vì đã có rules rõ ràng.

Áp dụng trong OpenCode: OpenCode đọc CLAUDE.md theo thứ tự ưu tiên:

  1. ~/.claude/CLAUDE.md - Rules global cho tất cả projects
  2. ./CLAUDE.md - Rules riêng cho project hiện tại
  3. ./subfolder/CLAUDE.md - Rules cho subfolder cụ thể
# Tạo CLAUDE.md cho project
touch CLAUDE.md

# Hoặc dùng lệnh init của OpenCode
opencode init

Pro tip: Sau khi OpenCode mắc lỗi, nói:

Thêm rule này vào CLAUDE.md để lần sau không mắc lại

4. Tạo Skills Riêng Và Commit Vào Git

Skills Là Gì?

Skills là tập hợp instructions, prompts, và code để thực hiện một task cụ thể. Có thể reuse trên mọi project.

Nguyên Tắc Vàng

"If you do something more than once a day, turn it into a skill or command."

Ví Dụ Skill: /techdebt

# skills/techdebt.yaml
name: techdebt
description: "Tìm và fix technical debt trong project"
instructions: |
  1. Sử dụng grep để tìm duplicated code blocks
  2. Tìm functions dài hơn 50 dòng
  3. Tìm files có TODO comments cũ hơn 1 tuần
  4. Báo cáo findings và đề xuất fixes
  5. Tạo kế hoạch fix các issues nghiêm trọng nhất

Cách dùng:

$ claude
/techdebt
→ Claude tự phân tích và báo cáo technical debt

Ví Dụ Skill: /sync-context

# skills/sync-context.yaml
name: sync-context
description: "Sync Slack, GDrive, Asana, GitHub vào một context dump"
instructions: |
  1. Pull 7 ngày messages từ Slack #engineering
  2. Fetch recent documents từ GDrive
  3. Get open tasks từ Asana
  4. List recent PRs và issues từ GitHub
  5. Tổng hợp thành một summary

Analytics Engineer Agent

Một skill phổ biến trong team:

name: analytics-engineer
description: "Phân tích dữ liệu và viết SQL"
instructions: |
  1. Phân tích requirements từ user
  2. Viết và tối ưu SQL queries
  3. Tạo dbt models
  4. Review data quality
  5. Test changes trong dev environment

Áp dụng trong OpenCode: OpenCode hỗ trợ Skills natively! Tạo file .opencode/skills/techdebt.md:

# Skill: Tech Debt Hunter

## Trigger
Khi user gõ "/techdebt" hoặc hỏi về technical debt

## Instructions
1. Tìm duplicated code blocks
2. Tìm functions dài hơn 50 dòng  
3. Tìm TODO comments cũ
4. Báo cáo và đề xuất fixes

Sau đó chỉ cần gõ /techdebt trong OpenCode!

Xem thêm: Hướng dẫn tạo Skills trong OpenCode


5. Claude Fix Hầu Hết Bugs Một Mình

Cách 1: Dùng Slack MCP

# Bật Slack MCP trong config
# Paste bug thread từ Slack vào Claude
# Nói đơn giản: "fix"

User: "API trả về 500 error khi tạo order"
[Claude đọc bug description, tìm code liên quan, reproduce, fix, test]

Cách 2: Fix CI Failures

User: "Go fix the failing CI tests"

→ Claude:
   - Chạy tests để xem lỗi gì
   - Đọc error logs
   - Tìm root cause
   - Fix code
   - Verify tests pass

Cách 3: Debug Distributed Systems

# API bị lỗi, xem docker logs
$ claude
"Đây là docker logs của service bị lỗi 500:"
[paste 200 lines logs]

Claude: "Tôi thấy lỗi ở line 45: 'null reference trong inventoryService.update()'
Nguyên nhân: Race condition giữa inventory check và update
Tôi sẽ thêm mutex lock và retry logic"

Tại sao Claude giỏi debug:

  • Đọc được toàn bộ stack trace
  • Trace request qua nhiều services
  • Pattern matching trong logs
  • Tự động search related code

Áp dụng trong OpenCode: Paste logs trực tiếp hoặc dùng pipe:

# Paste docker logs
cat docker-logs.txt | opencode "Tìm lỗi và fix"

# Hoặc trong session
opencode
> Đây là error logs: [paste logs]
> fix

6. Nâng Cao Prompting

a) Challenge Claude - "Grill Me"

User: "Grill me on these changes and don't make a PR until I pass your test"

→ Claude đóng vai reviewer:
   - Đặt câu hỏi về edge cases
   - Chỉ ra security concerns
   - Yêu cầu giải thích logic
   - Chỉ khi user trả lời đúng → mới được merge

Hoặc:

User: "Prove to me this works"
→ Claude so sánh behavior giữa main branch và feature branch

b) Scrapp Và Implement Lại

// Khi fix không tốt
User: "Knowing everything you know now, scrap this and implement the elegant solution"

→ Claude:
   - Xóa code cũ
   - Nghĩ lại từ đầu
   - Đưa ra solution tối ưu hơn

c) Viết Specs Chi Tiết

THAY VÌ:
"Thêm tính năng login"

VIẾT CHI TIẾT:
"Thêm tính năng login với:
- Email/password + Google OAuth
- Rate limiting: 5 attempts/5 phút
- Session timeout: 24 giờ
- Password requirements: 8+ chars, 1 uppercase, 1 number
- Redirect về trang trước sau khi login
- Xử lý cases: wrong password, account locked, etc."

So sánh:

Prompt mơ hồ → Claude đoán → Sai → Sửa → Sai → Sửa...
Prompt chi tiết → Claude hiểu đúng → Đúng ngay lần đầu

7. Terminal & Environment Setup

Terminal Yêu Thích Của Team: Ghostty

Ghostty là terminal mới, được team Claude Code yêu thích vì:

✅ Synchronized rendering - Input/output hiển thị đồng bộ
✅ 24-bit color - Màu sắc chính xác, đẹp
✅ Unicode support - Hiển thị emoji, ký tự đặc biệt tốt
✅ Performance - Nhanh, ít lag

Custom Statusline

/statusline → customize để hiển thị:
- Current context usage (ví dụ: "64K/200K tokens")
- Current git branch (ví dụ: "feat/payment")
- Working directory
- Temperature, model name

Voice Dictation (QUAN TRỌNG!)

macOS: Nhấn fn 2 lần để bắt đầu nói

// Tốc độ so sánh:
// Gõ: ~40 từ/phút
// Nói: ~120 từ/phút (nhanh gấp 3x)

// Prompt gõ:
// "fix the login bug"

// Prompt nói:
// "The login is failing when users enter valid credentials but the system 
// returns a 401 error. Looking at the logs, I see the JWT token validation 
// is failing because the expiry check is using UTC time but the token was 
// created in a different timezone. Can you fix this?"

Lợi ích voice dictation:

  • Prompts dài hơn, chi tiết hơn
  • Không mệt tay
  • Đầu óc thoải mái suy nghĩ hơn là tập trung gõ

Áp dụng trong OpenCode: OpenCode có TUI (Terminal UI) đẹp với các phím tắt hữu ích:

  • Ctrl+P - Mở command palette
  • Shift+Tab - Toggle Plan Mode
  • Ctrl+R - Xem lịch sử commands
  • Esc - Cancel operation

Xem thêm: OpenCode Keyboard Shortcuts


8. Sử Dụng Subagents

Subagents Là Gì?

Subagents là các Claude instances nhỏ hơn, được tạo ra để xử lý các task con song song.

User: "Write integration tests for the entire payment module, use subagents"

→ Claude spawn 3-4 subagents:
   Subagent 1: Write tests cho checkout flow
   Subagent 2: Write tests cho refund flow
   Subagent 3: Write tests cho webhook handling
   Subagent 4: Review và merge tất cả tests

Lợi Ích

Context chính:
✅ Không bị overwhelmed bởi quá nhiều code
✅ Giữ được focus vào mục tiêu lớn

Subagents:
✅ Mỗi subagent tập trung vào 1 task nhỏ
✅ Có thể chạy song song
✅ Tốn thêm token nhưng nhanh hơn nhiều

Security Hook Với Opus 4.5

# Hook để auto-approve safe permissions
def permission_hook(request):
    if is_safe_operation(request):
        return auto_approve()
    else:
        return require_user_approval()

Áp dụng trong OpenCode: OpenCode có Task tool tương tự subagents! Khi bạn yêu cầu task lớn, OpenCode tự động spawn agents:

User: "Viết integration tests cho toàn bộ payment module"

OpenCode tự động:
→ Spawn Task agent 1: Tests cho checkout
→ Spawn Task agent 2: Tests cho refund  
→ Spawn Task agent 3: Tests cho webhooks
→ Tổng hợp kết quả

Bạn cũng có thể chỉ định rõ:

Sử dụng subagents để viết tests song song cho 3 modules

9. Dùng Claude Cho Data & Analytics

BigQuery Skill

$ claude
"Show me the daily active users for the last 7 days"

→ Claude dùng bq CLI:
   bq query --use_legacy_sql=false \
   "SELECT date, COUNT(DISTINCT user_id) as dau 
    FROM events.daily_active 
    WHERE date >= DATE_SUB(CURRENT_DATE(), INTERVAL 7 DAY)
    GROUP BY date"
→ Trả về kết quả và visualization

Boris nói:

"I haven't written a line of SQL in 6+ months"

Áp Dụng Cho Mọi Database

PostgreSQL → psql CLI
MySQL → mysql CLI
MongoDB → mongosh
Snowflake → snowsql
Redis → redis-cli

Workflow Ví Dụ

$ claude
"Check performance của 1000 orders gần đây nhất"
→ Claude query PostgreSQL

"Find users with failed payments trong last hour"
→ Claude query Stripe qua MCP

"Compare conversion rate giữa mobile và desktop"
→ Claude query Mixpanel

Áp dụng trong OpenCode: Cài MCP Server cho database của bạn:

// .opencode/mcp.json
{
  "servers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@anthropic/mcp-server-postgres"],
      "env": {
        "DATABASE_URL": "postgresql://..."
      }
    }
  }
}

Sau đó chỉ cần hỏi bằng tiếng Việt:

Cho tôi xem 10 đơn hàng mới nhất có giá trị > 1 triệu

10. Học Với Claude

a) Explanatory/Learning Mode

/config → Set output style = "Explanatory" hoặc "Learning"

Claude sẽ giải thích:
- Tại sao chọn cách này
- Có những alternatives nào
- Trade-offs là gì
- Edge cases cần lưu ý

THAY VÌ chỉ show code → show code + GIẢI THÍCH

b) HTML Presentation

User: "Tôi không hiểu cách hoạt động của Redux"
→ Claude generates HTML presentation:
   - Slides giải thích từng khái niệm
   - Animation showing data flow
   - Interactive examples

→ User mở browser → xem như học online course

Áp dụng trong OpenCode: Yêu cầu OpenCode giải thích khi làm:

Giải thích từng bước khi implement authentication

Hoặc sau khi xong:

Giải thích code vừa viết, tôi muốn hiểu sâu hơn

c) ASCII Diagrams

User: "Draw me the architecture of this microservices system"
→ Claude vẽ:

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│   API GW    │────▶│  Auth Svc   │◀───▶│   User DB   │
└─────────────┘     └─────────────┘     └─────────────┘
       │                   │
       ▼                   ▼
┌─────────────┐     ┌─────────────┐
│  Order Svc  │────▶│  Order DB   │
└─────────────┘     └─────────────┘
       │
       ▼
┌─────────────┐     ┌─────────────┐
│ Payment Svc │────▶│ Payment DB  │
└─────────────┘     └─────────────┘

Lưu Ý Quan Trọng Từ Tim Krest

"This is convenient, but the token consumption is brutal. You're basically paying for zero context switching with a massive context window."

Trade-off:

✅ Không phải context switching (chuyển đổi giữa các công việc)
✅ Focus tốt hơn
✅ Code đúng ngay từ đầu

❌ Tốn token nhiều hơn
❌ Cần RAM để chạy nhiều Claude sessions
❌ Setup phức tạp hơn

Cân nhắc: Cách này phù hợp cho những task lớn, phức tạp. Với task nhỏ, đừng over-engineer.


Tổng Kết

TipMục đíchKhó khăn ban đầu
1. Parallel worktreesLàm nhiều việc cùng lúcTốn RAM
2. Plan modeCode đúng ngay từ đầuCần kiên nhẫn
3. CLAUDE.mdGiảm lặp lại lỗi cũCần update thường xuyên
4. SkillsTự động hóa task lặp đi lặp lạiCần thời gian setup
5. Claude fix bugsDebug nhanhCần context đầy đủ
6. Better promptingClaude hiểu đúngCần học cách viết prompt
7. Tools & voiceTăng tốc workflowHọc công cụ mới
8. SubagentsXử lý task lớnTốn token
9. Data & AnalyticsKhông cần viết SQLCần MCP setup
10. Learning modeHiểu sâu hơnChậm hơn một chút

Bước Tiếp Theo Cho Người Dùng OpenCode

Bạn đã sẵn sàng áp dụng những mẹo này chưa? Hãy bắt đầu với:

  1. Dùng ngay Plan mode - Nhấn Shift+Tab trước khi bắt đầu task
  2. Tạo CLAUDE.md - Chạy opencode init hoặc tự tạo file
  3. Thử worktree - Mở nhiều terminal, mỗi cái một worktree
  4. Tạo Skill đầu tiên - Xem hướng dẫn tạo Skills

Tài nguyên học thêm:

Và nhớ rằng: "There is no one right way to use Claude Code -- everyone's setup is different. You should experiment to see what works for you!"


Bài viết được tổng hợp từ chia sẻ của Boris Cherny (creator của Claude Code) trên X/Twitter, với hướng dẫn áp dụng cụ thể cho người dùng OpenCode.