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 dialogsmulti-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 slashCommands trong joinSession().
  • 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-sdk tự 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:

CapabilityClaude Code HooksCopilot CLI Extensions
RuntimeShell commandsFull Node.js process
StateStatelessPersistent in-memory
Register new toolsKhôngUnlimited
PermissionExit code 0/1allow / deny / modifiedArgs
Modify tool resultKhôngmodifiedResult
Event streamingKhông10+ events
Error recovery hookKhôngonErrorOccurred
Hot reloadRestart/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: onErrorOccurred retry test fail, agent tự fix rồi rerun.
  • Onboarding: /learn-auth, /learn-deployments dắ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

  • stdout reserved cho JSON-RPC — dùng session.log(), KHÔNG console.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 trong onUserPromptSubmitted = infinite loop. Wrap setTimeout(..., 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.