
Claude Code 2.1.76: MCP Elicitation & Hooks Cho Agent Workflows Tương Tác Hơn
Claude Code 2.1.76 thêm MCP elicitation — MCP servers giờ có thể request structured input mid-task qua dialog tương tác. Phân tích tính năng mới: Elicitation hooks, worktree.sparsePaths, PostCompact hook, /effort command, và cách chúng giúp agent workflows ít brittle hơn và an toàn hơn.
Release Notes vs Thực Tế
Release notes của Claude Code 2.1.76 (từ official CHANGELOG.md) listed 30+ improvements. Bài này không walkthrough toàn bộ — tập trung vào những gì thực sự thay đổi cách bạn build agent workflows.
Tính năng quan trọng nhất trong 2.1.76: MCP Elicitation.
MCP Elicitation Là Gì?
Trước 2.1.76, nếu MCP server (hoặc tool-using agent) cần additional information giữa chừng task, nó phải:
- Dừng và thông báo lỗi ("không đủ thông tin")
- Hoặc prompt-engineer một string phức tạp để extract info
- Hoặc finish với kết quả incomplete/wrong
Elicitation giải quyết vấn đề này: MCP server giờ có thể pause task và request structured input từ user hoặc calling system, qua interactive dialog — form fields hoặc browser URL.
Từ official changelog:
"MCP servers can now request structured input mid-task via an interactive dialog (form fields or browser URL)"
Cách Hoạt Động (Conceptual)
Agent bắt đầu task → "Tạo PR cho feature X"
Agent nhận ra cần thêm context:
- Repo path?
- Test scope (unit only, integration, full)?
- CI config (fast / full pipeline)?
→ Agent PAUSE
→ MCP Elicitation dialog hiện ra (structured form)
→ User/system điền inputs
→ Agent RESUME với context đầy đủ
Trước elicitation:
Prompt: "Deploy code to production, repo at /workspace/myapp, run integration tests only, use fast CI"
↑ Brittle. Parsing sai → wrong deployment scope. Human error prone.
Sau elicitation:
{
"repo_path": "/workspace/myapp",
"test_scope": "integration",
"ci_config": "fast"
}
Structured, validated, unambiguous.
Elicitation & ElicitationResult Hooks
Tính năng đi kèm: Elicitation và ElicitationResult hooks — cho phép bạn intercept và override responses trước khi gửi về MCP server.
Khi nào hooks hữu ích:
-
Auto-fill context — Nếu bạn chạy trong CI/CD environment, hooks có thể auto-populate fields như repo path hoặc branch name từ environment variables, thay vì hỏi user mỗi lần.
-
Validation layer — Trước khi gửi elicitation response về, validate format hoặc reject invalid values.
-
Audit trail — Log mọi elicitation inputs cho compliance hoặc debugging.
-
A/B testing workflows — Test hai different input schemas cho cùng một tool để xem cái nào reduce errors hơn.
Other Notable Changes in 2.1.76
worktree.sparsePaths — Cho Large Monorepos
Khi dùng claude --worktree trong large monorepos, bạn giờ có thể specify chỉ checkout những directories cần thiết qua git sparse-checkout:
// settings.json
{
"worktree": {
"sparsePaths": ["src/api", "packages/shared", "tests/integration"]
}
}
Tại sao quan trọng: Monorepo với 50,000 files checkout toàn bộ mỗi lần agent runs worktree → chậm và tốn disk. Sparse checkout → chỉ relevant directories → 10x faster in large repos.
PostCompact Hook
Fires sau khi conversation compaction hoàn thành. Trước đây, không có cách reliable để biết khi nào compaction done. Giờ bạn có thể:
- Trigger post-compaction analysis
- Save compaction stats
- Reset conversation-level state sau khi context được trimmed
/effort Command
Set model "effort level" theo demand:
/effort low → faster, cheaper (good for simple tasks)
/effort medium → balanced (default)
/effort high → maximum reasoning (for complex problems)
Khi nào hữu ích: Code review routine changes → /effort low. Debugging architectural issue → /effort high. Saves tokens và latency cho tasks không cần full reasoning.
Implementation Tips
Giữ Elicitation Fields Tối Thiểu
Mỗi elicitation dialog là friction. Nguyên tắc:
- Tối đa 3-4 fields per dialog
- Chỉ hỏi những gì không thể infer từ context
- Provide sensible defaults cho optional fields
// ✅ Good — minimal, clear
{
"title": "Configure deployment",
"fields": [
{"name": "environment", "type": "select", "options": ["staging", "production"], "default": "staging"},
{"name": "run_tests", "type": "boolean", "default": true}
]
}
// ❌ Bad — too many fields
{
"fields": [...20 configuration options...]
}
Dùng Standardized Schemas
Không invent custom formats mỗi tool một kiểu. Define shared types:
// Shared elicitation types
type DeploymentInput = {
environment: "staging" | "production"
branch: string
run_tests: boolean
}
type PRInput = {
repo_path: string
base_branch: string
test_scope: "unit" | "integration" | "full"
}
Khi teams share schemas, agents có thể interoperate và testing dễ hơn.
Guardrails Cho Unattended Workflows
Nếu agent workflow chạy unattended (CI/CD, scheduled tasks), elicitation dialogs sẽ block indefinitely nếu không có response. Cần:
- Timeout handler cho elicitation requests
- Fallback defaults nếu timeout
- Alert nếu workflow bị blocked vì waiting for input
# Pattern: timeout + fallback
response = await wait_for_elicitation(timeout=30)
if response is None:
# Use safe defaults, send alert
response = SAFE_DEFAULTS
await notify_team("Elicitation timed out, using defaults")
Pitfalls & Best Practices
| Pitfall | Better approach |
|---|---|
| Quá nhiều elicitation dialogs per task | Batch questions vào 1 dialog ở đầu task |
| Free-text fields thay vì structured | Dùng select/checkbox/number inputs |
| Không validate elicitation responses | Add validation trong ElicitationResult hook |
| Block production workflow khi no response | Implement timeout + fallback defaults |
| Khác nhau schema cho cùng loại input | Define shared input types |
Bugs Fixed Đáng Chú Ý
Từ 2.1.76 changelog — những fixes thực sự ảnh hưởng đến daily use:
- Auto-compaction infinite retry fixed — Circuit breaker sau 3 attempts. Trước đây agent có thể bị stuck trong compaction retry loop.
- Plan mode re-approval fixed — Không còn hỏi re-approve plan đã accept.
- ToolSearch schema loss fixed — Deferred tools không còn mất input schemas sau compaction (array/number params bị reject với type errors).
- Background agent improvement — Kill background agent giờ preserve partial results thay vì mất toàn bộ.
Takeaway
MCP elicitation thay đổi cách agent workflows handle ambiguity: thay vì guess, guess wrong, và fail — agents có thể pause và ask precisely. Đây là bước nhỏ nhưng meaningful về agent workflow UX.
Action item: Identify một workflow hiện tại đang fail vì input ambiguity. Thêm 1 elicitation step. So sánh error rate trước/sau.
Nguồn: Claude Code CHANGELOG.md — Anthropic, phiên bản 2.1.76