taw·lmsĐăng nhập
Claude Code thực chiến — best practices từ Anthropic

Bài 2 · Best practices từ Anthropic Engineering

Auto mode — Claude tự quyết, ít hỏi hơn (an toàn)

Bài học này chưa có video. Cứ đọc nội dung phía dưới nhé.

Vấn đề: approval fatigue

Default Claude Code hỏi permission mỗi action — file write, bash, MCP tool. Sau lần thứ 10 bạn không review thực sự, chỉ click "yes" mù quáng. Thống kê: 93% prompt được approve.

Trước đây có cờ --dangerously-skip-permissions — tắt hết safeguard. Nguy hiểm.

Auto mode — middle ground

Auto mode dùng model classifier riêng để duyệt action. Chặn nguy hiểm, cho qua an toàn.

claude --permission-mode auto -p "fix all lint errors"

Kiến trúc 2 tầng

Stage 1 — Fast filter

  • Single-token yes/no
  • Tuned nghiêng về chặn
  • False positive rate 8.5%

Stage 2 — Full review (chỉ chạy khi Stage 1 flag)

  • Chain-of-thought reasoning
  • Giảm false positive xuống 0.4%

Classifier chỉ thấy user message + tool command payload — KHÔNG thấy reasoning của agent, KHÔNG thấy tool output. Tránh bị prompt injection.

3 tier permission

TierLoại actionCách xử lý
1Read file, search, code navigationTự động OK
2Edit file in-projectTự OK (revertable qua git)
3Shell command, external API, out-of-projectQua classifier

Block rules mặc định

20+ rule cover:

  • Destruction (rm -rf, drop table, force push)
  • Credential exposure (cat ~/.ssh, echo $TOKEN)
  • Boundary crossing (đụng vào folder ngoài project)
  • Infrastructure bypass (sudo, modify systemd)

Tùy biến

3 slot bạn có thể edit không cần build lại template:

  • Trusted domains/services — vd cdn.taw.group
  • Environment-specific exceptions — staging vs prod khác nhau
  • Custom block rules — vd "không deploy lúc 22h-6h"

Xem default: claude auto-mode defaults

Khi nào dùng?

✅ Nên dùng:

  • Task dài, approve overhead không xứng
  • Tin general direction của agent
  • Long-running operation (refactor lớn, migration)

❌ Không nên:

  • High-stake infrastructure change
  • Production deploy
  • Task cần human judgment cẩn thận

Cơ chế "Deny-and-continue"

Khi classifier chặn → agent không bị crash. Agent nhận feedback "action bị chặn" → thử cách khác.

Session escalate lên human sau 3 deny liên tiếp hoặc 20 deny tổng.

Honest limit (do Anthropic tự nói)

"The 17% false-negative rate on real overeager actions is the honest number."

Tức là auto mode bỏ sót ~17% action thực sự nguy hiểm. Vẫn yếu hơn human review cẩn thận cho task nhạy.

→ Dùng auto mode cho task daily, KHÔNG cho task critical.

Nguồn chính thống: anthropic.com/engineering/claude-code-auto-mode

Bạn đang xem ở chế độ preview công khai. Để nộp bài tập, hỏi AI tutor, và làm quiz — đăng nhập.
Best practices Claude Code — chính thống từ AnthropicContext engineering — quản context như tài nguyên hữu hạn→