QuotaCheap Playbook

Claude Code Hooks: deterministic controls để format, block command và gửi notification

Tìm hiểu claude code hooks: deterministic controls để format, block command và gửi notification theo Claude Code docs: permissions, hooks, MCP, CLI, guardr…

Hooks docs mô tả hooks là user-defined shell commands chạy tại các điểm lifecycle của Claude Code. Hooks giúp format files sau edit, block commands trước khi execute, gửi notification khi Claude cần input, inject context và audit configuration changes.

Bài Claude Code Playbook: Hooks docs mô tả hooks là user-defined shell commands chạy tại các điểm lifecycle của Claude Code. Hooks giúp format files sau edit, block commands trước khi execute, gửi notification khi Claude cần input, inject context và audit configuration changes. Bài viết bám Claude Code documentation, tập trung control thật, review, guardrails và workflow developer.

Claude Code Hooks: deterministic controls để format, block command và gửi notification Hooks docs mô tả hooks là user defined shell commands chạy tại các điểm lifecycle của Claude Code.

Hooks giúp format files sau edit, block commands trước khi execute, gửi notification khi Claude cần input, inject context và audit configuration changes.

Điều docs xác nhận Hooks docs mô tả hooks là user defined shell commands chạy tại các điểm lifecycle của Claude Code.

Hooks giúp format files sau edit, block commands trước khi execute, gửi notification khi Claude cần input, inject context và audit configuration changes.

Bài này không cố biến Claude Code thành một khái niệm chung chung.

Documentation có tên file, lệnh, setting và warning cụ thể; vì vậy playbook phải bám vào đúng cơ chế được mô tả.

Nếu một control là instruction, gọi nó là instruction.

Nếu một control được enforced bởi Claude Code, gọi nó là permission hoặc hook.

Trộn hai lớp này là cách nhanh nhất để tạo cảm giác an toàn giả.

Cách dùng trong repo thật Một repo production cần tách ba lớp: context, quyền và kiểm chứng.

Context nằm ở prompt, CLAUDE.md, rules, command output và file mà Claude đọc.

Quyền nằm ở permissions, settings, mode, hooks hoặc policy.

Kiểm chứng nằm ở test, build, lint, typecheck, review diff và audit log.

Nếu một task thiếu một trong ba lớp này, đừng để agent chạy quá xa.

Với task đơn giản như docs, copy hoặc test nhỏ, bạn có thể cho Claude Code chạy nhanh hơn.

Với task sửa auth, billing, permissions, migration hoặc deploy, hãy yêu cầu plan trước, giới hạn tool, và review thủ công.

Đây không phải vì không tin agent; đây là vì agent không sở hữu risk của production.

Prompt mẫu Prompt này đặc biệt hữu ích khi làm việc với permissions, hooks, MCP hoặc CLI flags.

Nó buộc agent phân biệt giữa “muốn nó làm” và “hệ thống thật sự chặn/cho phép”.

Runbook triển khai Bước một: viết policy ngắn cho team.

Tool nào được đọc tự do?

Command nào cần approval?

File nào không được sửa?

MCP server nào được tin?