01
PreToolUse hook
Cưỡng chếEnforcement
Một chương trình bên ngoài, chạy trước mỗi lần Claude gọi tool, nhận mô tả lời gọi qua stdin và có quyền huỷ lời gọi đó.An external program that runs before every tool call, receives the call description on stdin, and can cancel it.
Read(file_path="Service.java")
│
▼ stdin: {"tool_name":"Read", ...}
┌─────────────┐
│ hook │
└──┬───────┬──┘
exit 0│ │exit 2 + stderr
▼ ▼
tool chạy huỷ lời gọi, stderr → Claude
tool runs call cancelled, stderr → Claude
Dùng choGood for
- Chặn đọc nguyên file lớnBlocking whole-file reads
- Chặn
cat file khổng lồBlocking cat on huge files
- Chặn đọc
.env, khoá riêngBlocking .env and key reads
ĐượcGains
- Hiệu lực không phụ thuộc model có chịu đọc hướng dẫnForce that doesn't depend on the model reading instructions
- Bản thân hook tiêu 0 tokenThe hook itself costs zero tokens
MấtCosts
- Sai exit code là hỏng cả luật, không có dấu hiệu nàoA wrong exit code kills the rule silently
- Không kích hoạt với file tham chiếu bằng
@Doesn't fire for files referenced with @
Đánh đổi.Trade-off. Chọn hook là đổi khả năng model tự xử lý ngoại lệ lấy sự chắc chắn rằng luật luôn được thi hành.A hook trades the model's ability to handle exceptions for the certainty that the rule is always enforced.
Dấu hiệu: nếu câu trả lời cho “model phớt lờ luật này thì sao?” là “hỏng”, luật đó thuộc về hook, không thuộc về prompt.Cue: if the answer to “what if the model ignores this?” is “something breaks”, the rule belongs in a hook, not a prompt.
02
Ngưỡng định tuyếnRouting threshold
Cưỡng chếEnforcement
Một số nguyên phân đôi thế giới: dưới ngưỡng đọc thẳng, trên ngưỡng uỷ thác. Mặc định 350 dòng, đổi qua SHUNT_MIN_LINES.One integer that splits the world: below it read directly, above it delegate. Default 350 lines, set via SHUNT_MIN_LINES.
5.000 dòng, đọc nguyên → CHẶN
5,000 lines, whole file → BLOCKED
5.000 dòng, offset+limit → cho qua / passes
120 dòng / 120 lines → cho qua / passes
cat huge.json → CHẶN / BLOCKED
cat huge.json | jq '.name' → cho qua / passes
Dùng choGood for
- Repo Java/Kotlin file dài: ngưỡng thấp có lợiLong-file Java/Kotlin repos: low pays off
- Repo JS/TS file nhỏ: nâng ngưỡng lênSmall-file JS/TS repos: raise it
ĐượcGains
- Một con số chỉnh toàn bộ hành vi, không đụng logicOne number tunes everything, no logic change
- Giữ nguyên đường đọc chính xác cho việc sửa codeKeeps the exact-read path for editing
MấtCosts
- Số dòng là proxy tồi cho số tokenLine count is a poor proxy for tokens
- Quá thấp: mọi thao tác nhỏ thành một lần chờ 10–30 giâyToo low: every small read becomes a 10–30s wait
Đánh đổi.Trade-off. Hạ ngưỡng là đổi độ trễ tương tác lấy token tiết kiệm được; nâng ngưỡng là đổi ngược lại.Lowering the threshold trades interactive latency for saved tokens; raising it trades the other way.
Dấu hiệu: nếu thời gian bạn ngồi chờ uỷ thác lớn hơn thời gian tiết kiệm được, ngưỡng đang quá thấp.Cue: if the wait for a delegation exceeds the time it saves, the threshold is too low.
03
bulk-read
Uỷ thácDelegation
Bọc mỗi file trong thẻ XML, gửi cả cụm kèm câu hỏi sang worker model, chỉ mang về câu trả lời dạng bullet.Wraps each file in XML tags, sends the set plus a question to the worker model, and brings back only bullets.
bulk-read --question "..." --paths A.java B.java
gửi / sent → 1500 lines of code + question
→ worker (temp 0.2)
nhận / back → • A.java:41 — handles signup webhook
• B.java:23 — retries 3x, backoff
1500 dòng không bao giờ chạm phiên đắt tiền.
1500 lines never touch the expensive session.
Dùng choGood for
- “Luồng xác thực đi qua file nào?”“Which files does the auth flow touch?”
- “Chỗ nào gọi xuống database?”“Where do we call the database?”
- Khảo sát thư mục lạ trước khi đọc kỹSurveying an unfamiliar directory
ĐượcGains
- ~90% token trên kịch bản bulk-read (monorepo Java, 4 kịch bản)~90% of tokens on bulk-read scenarios (Java monorepo, 4 tests)
- Hỏi tiếp trên cùng bộ file gần như miễn phíFollow-ups over the same files are near-free
MấtCosts
- Tóm tắt không có số dòng đáng tin → không sửa code đượcNo reliable line numbers → you cannot edit from it
- Worker bỏ lọt lỗi tinh vi (một lỗi thread-safety trong thử nghiệm)The worker misses subtle bugs (a thread-safety bug in testing)
Đánh đổi.Trade-off. Chọn bulk-read là đổi độ phân giải chi tiết và số dòng chính xác lấy khoảng 90% token đầu vào.bulk-read trades fine detail and exact line numbers for roughly 90% of the input tokens.
Dấu hiệu: bạn sắp nạp nhiều file chỉ để rút ra vài câu, và sẽ không sửa phần lớn số file đó.Cue: you're loading many files to extract a few sentences, and you won't edit most of them.
04
code-write
Uỷ thácDelegation
Nhận spec và một file tham chiếu bắt buộc, gửi sang worker, cắt bỏ markdown fence, ghi thẳng ra đĩa. Claude không đọc lại.Takes a spec and a required reference file, sends both to the worker, strips markdown fences, writes straight to disk. Claude never reads it back.
code-write --spec "tests for UserService" \
--reference tests/OrderTest.java \
--target tests/UserTest.java
Claude thấy / sees : "wrote tests/UserTest.java"
Claude KHÔNG thấy / not : 340 dòng test vừa sinh
the 340 generated lines
Dùng choGood for
- File test thứ 21 giống 20 file bên cạnhThe 21st test file beside twenty others
- Stub cấu hình, DTO, type định nghĩaConfig stubs, DTOs, type definitions
- Sinh i18n cho ngôn ngữ mới từ file gốci18n files for a new locale
ĐượcGains
- Cắt cả token vào lẫn token ra — loại đắt nhấtCuts input and output tokens — the expensive kind
- Bám quy ước sẵn có vì luôn có mẫu đi kèmFollows existing conventions via the pattern
MấtCosts
- Claude không biết nội dung vừa sinh; sửa sau là phải đọc lạiClaude doesn't know what it made; editing later means reading it
- Không ai đọc trước khi file nằm trên đĩa — test là lưới duy nhấtNobody reviews before it lands — tests are the only net
Đánh đổi.Trade-off. Chọn code-write là đổi việc Claude nắm được nội dung vừa tạo lấy phần token output đắt nhất trong phiên.code-write trades Claude's awareness of what it just created for the most expensive output tokens in the session.
Dấu hiệu: bạn chỉ được vào một file và nói “giống cái này, nhưng cho X” — và câu đó đủ cho người mới làm đúng.Cue: you can point at a file and say “like this, but for X” — and a new hire would get it right from that.
05
Mode — worker khai báoMode — a declared worker
Uỷ thácDelegation
Agent khai báo: instructions, model, temperature, MCP tool. Chạy trên runtime tạm thời, gọi từ CLI hoặc API. Không server, không API key rải rác.A declarative agent: instructions, model, temperature, MCP tools. Runs on an ephemeral runtime, callable from CLI or API. No servers, no scattered API keys.
name: bulk-reader
model: gemini-2.5-flash
resourceLimits:
temperature: 0.2
instructions: |
Chỉ xuất bullet có cấu trúc. Không chào hỏi,
không văn xuôi. Mỗi bullet bắt đầu bằng tên,
kiểu, hoặc số dòng chính xác.
Output structured bullets only. No greetings,
no prose. Lead every bullet with the exact
name, type, or line number.
Dùng choGood for
- bulk-reader, code-writer
- reviewer: đọc diff, trả rủi ro, không sửareviewer: read a diff, return risks, change nothing
- doc-writer, translatordoc-writer, translator
ĐượcGains
- Định tuyến model thành việc cấu hình, không phải dựng hạ tầngRouting becomes configuration, not infrastructure
- Đổi worker chỉ là sửa một dòng; plugin không đổiSwapping the worker is one line; the plugin is untouched
MấtCosts
- Gắn vào một nền tảng cụ thể (Portal, AiKA)Ties you to one platform (Portal, AiKA)
- Hợp đồng đầu ra viết lỏng thì kết quả không dùng lại được bằng máyA loose output contract leaves output nothing can parse
Đánh đổi.Trade-off. Chọn mode là đổi sự độc lập nền tảng lấy việc không phải vận hành hạ tầng cho worker model.Modes trade platform independence for not having to operate worker infrastructure.
Dấu hiệu: dán cùng một đoạn hướng dẫn vào chat lần thứ ba thì nó nên là một mode.Cue: pasting the same instruction block a third time means it should be a mode.
06
Ba lớpThree layers
Chỉ dẫn → luậtAdvice → law
Ba cơ chế có mức hiệu lực khác nhau, xếp chồng để hệ thống suy giảm êm thay vì hỏng hoàn toàn.Three mechanisms with different levels of force, stacked so the system degrades gracefully instead of failing outright.
HOOK chạy trước tool, có quyền từ chối ← LUẬT
runs before the tool, can refuse ← LAW
SCRIPT gọi CLI, báo token đã dùng ← ĐƯỜNG
calls the CLI, reports tokens ← PATH
SKILL markdown: khi nào, gọi thế nào ← KHUYÊN
markdown: when and how to call ← ADVICE
v1: cùng luật đó nằm trong CLAUDE.md → bị bỏ qua
v1: the same rule in CLAUDE.md → ignored
Dùng choGood for
- Luật bạn cần được tuân thủ, không chỉ mongRules you need obeyed, not merely hoped for
- Quy ước cho cả team, chính sách bảo mậtTeam-wide conventions, security policy
ĐượcGains
- Hỏng một lớp không làm sập cả hệ thốngOne layer failing doesn't take the system down
- Cài một lần cho mọi repoInstalled once for every repo
MấtCosts
- Ba thứ phải bảo trì và gỡ lỗiThree things to maintain and debug
- Lệch giữa các lớp: hook chặn một luật, skill dạy luật khácDrift: the hook enforces one rule, the skill teaches another
Đánh đổi.Trade-off. Chọn ba lớp là đổi sự đơn giản của một file hướng dẫn lấy khả năng hệ thống vẫn đúng khi model không hợp tác.Three layers trade the simplicity of one instruction file for a system that holds when the model doesn't cooperate.
Dấu hiệu: viết luật vào markdown rồi thấy nó vẫn bị vi phạm — đó là lúc luật cần rơi xuống lớp dưới.Cue: the rule is in markdown and still gets violated — that's the rule asking to move down a layer.