TL;DR
GitHub Copilot CLI (GA từ 25/02/2026) ship kèm một extension harness ít người để ý: mỗi extension là một Node.js child process nói chuyện với CLI qua JSON-RPC, có toàn quyền vào agent lifecycle. Bản revamp giữa tháng 3/2026 đã thêm custom slash commands, UI elicitation dialogs và multi-language SDK (Node, Python, Go, .NET). Kết quả: bạn có thể nhét bất kỳ UI hay workflow team-specific nào ngay vào terminal — không restart, không config, hot-reload trên /clear.
What's new
Trước revamp, extensions là một tính năng gần như không có docs — phải đọc .d.ts trong SDK để dùng. Trong vòng 9 ngày sau bài viết khui ra của htek.dev, GitHub đẩy thẳng lên thành first-class citizen:
- Custom slash commands qua field
slashCommandstrongjoinSession(). - UI elicitation dialogs: render form có field, type, validate qua JSON Schema bằng
session.rpc.ui.elicitation(). - /extensions command quản lý mọi extension ngay trong session.
- Copilot SDK đa ngôn ngữ: Node.js, Python, Go, .NET — cùng giao thức JSON-RPC.
- BYOR MCP allowlist (16/04/2026): admin enterprise enforce registry MCP riêng.
Why it matters
Custom slash commands làm được điều mà hooks và tools không làm được: cho extension một predictable, user-triggered interface. Hooks tự fire trên lifecycle. Tools chỉ chạy khi agent quyết định gọi. Slash command thì bạn quyết định khi nào fire. Ví dụ /deploy-staging, /review-security, /load-runbook — chuẩn hoá multi-step workflow toàn team mà không phụ thuộc vào việc agent có đoán đúng intent hay không.
UI elicitation đánh sập failure mode kinh điển kiểu "agent đoán nhầm message và deploy thẳng prod". Form có dropdown env, field bắt buộc, audit-friendly — perfect cho governance gate.
Technical facts
Architecture nhỏ gọn nhưng đủ sâu:
- CLI scan
.github/extensions/(project-scoped) và~/.copilot/extensions/(user-scoped) tìm thư mục cóextension.mjs. - Mỗi extension fork thành child process. Package
@github/copilot-sdktự resolve — không cần install. - Extension gọi
joinSession()để gắn vào session hiện tại qua JSON-RPC. - Reload trên
/clear, dừng trên CLI exit (SIGTERM rồi SIGKILL sau 5 giây).
Sáu hooks điều khiển toàn bộ agent loop: onSessionStart, onUserPromptSubmitted, onPreToolUse, onPostToolUse, onErrorOccurred, onSessionEnd. Mỗi hook nhận structured input, trả structured output — không còn parse exit code hay stdout.
Hơn 10 session events có thể subscribe qua session.on(): assistant.message, assistant.turn_start, tool.execution_start, tool.execution_complete, permission.requested, session.idle, session.error, session.shutdown...
Code mẫu UI elicitation (rút gọn từ docs htek.dev):
import { joinSession } from '@github/copilot-sdk/extension';
joinSession({
slashCommands: [{
name: 'deploy',
description: 'Gated deployment',
action: async (session) => {
const r = await session.rpc.ui.elicitation({
title: 'Deploy to Production?',
requestedSchema: {
type: 'object',
properties: {
env: { type: 'string', enum: ['staging','prod'] },
reason: { type: 'string' }
},
required: ['env','reason']
}
});
if (r.action === 'accept') {
await session.send(`Deploying ${r.content.env}: ${r.content.reason}`);
}
}
}]
});Comparison vs Claude Code hooks
Nhiều người tưởng đây là Claude Code hooks phiên bản GitHub. Không phải. Claude hooks là shell command trong file JSON config; Copilot extensions là Node.js process tham gia thẳng vào agent loop:
| Capability | Claude Code Hooks | Copilot CLI Extensions |
|---|---|---|
| Runtime | Shell commands | Full Node.js process |
| State | Stateless | Persistent in-memory |
| Register new tools | Không | Unlimited |
| Permission | Exit code 0/1 | allow / deny / modifiedArgs |
| Modify tool result | Không | modifiedResult |
| Event streaming | Không | 10+ events |
| Error recovery hook | Không | onErrorOccurred |
| Hot reload | Restart | /clear |
Use cases
- Governance gate: chặn write vào prod config, bật dialog xin reason + audit log.
- Secure input: nhập API key qua form thay vì paste vào chat.
- Team slash commands:
/review-security,/review-arch,/start-task LIN-1234. - Self-healing:
onErrorOccurredretry test fail, agent tự fix rồi rerun. - Onboarding:
/learn-auth,/learn-deploymentsdắt new hire qua codebase. - Test enforcer: track file modified, block git commit nếu test file tương ứng chưa đụng tới.
Limitations & gotchas
stdoutreserved cho JSON-RPC — dùngsession.log(), KHÔNGconsole.log()(sẽ corrupt protocol).- Tool name collision là fatal & silent — đặt prefix kiểu
myext_*. - Hook overwrite bug: nhiều extension đăng ký cùng hook → chỉ extension load cuối fire (tracking #2076, fix một phần ở CLI v1.0.11).
- Extension load order undefined.
- State reset trên
/clear— thiết kế stateless hoặc persist xuống disk. - Gọi
session.send()sync trongonUserPromptSubmitted= infinite loop. WrapsetTimeout(..., 0). - Chỉ ES module
.mjs, chưa có TypeScript native.
What's next
Roadmap signals: fix hook chaining để nhiều extension cùng register cùng lúc, TypeScript first-class cho extension.mjs, mở rộng plugin marketplace, BYOR MCP allowlist ra GA. Plugin distribution đã có sẵn (copilot plugin install owner/repo) và tự đóng gói được agents, skills, hooks, commands, MCP server trong một unit duy nhất — nên hệ sinh thái có thể bùng nhanh trong vài tháng tới. Nếu bạn từng đụng Claude Code hooks và thấy thiếu state, thiếu khả năng đăng ký tool mới, thiếu UI dialog — đây chính là phiên bản "hooks done right" mà bất kỳ ai làm agentic DevOps đều nên thử trong tuần này.
Nguồn: GitHub Changelog (GA), htek.dev — Copilot CLI Extensions Guide, DEV — Extensions Revamp, GitHub Docs, BYOR MCP allowlist.