diff --git a/website/src/content/learning-hub/automating-with-hooks.md b/website/src/content/learning-hub/automating-with-hooks.md index 1a688226b..823219fa2 100644 --- a/website/src/content/learning-hub/automating-with-hooks.md +++ b/website/src/content/learning-hub/automating-with-hooks.md @@ -3,7 +3,7 @@ title: 'Automating with Hooks' description: 'Learn how to use hooks to automate lifecycle events like formatting, linting, and governance checks during Copilot agent sessions.' authors: - GitHub Copilot Learning Hub Team -lastUpdated: 2026-02-26 +lastUpdated: 2026-03-18 estimatedReadingTime: '8 minutes' tags: - hooks @@ -93,6 +93,7 @@ Hooks can trigger on several lifecycle events: | `preToolUse` | Before the agent uses any tool (e.g., `bash`, `edit`) | **Approve or deny** tool executions, block dangerous commands, enforce security policies | | `postToolUse` | After a tool completes execution | Log results, track usage, format code after edits, send failure alerts | | `agentStop` | Main agent finishes responding to a prompt | Run final linters/formatters, validate complete changes | +| `subagentStart` | A subagent is spawned | Inject additional context into subagent prompts, log subagent spawning, enforce subagent governance | | `subagentStop` | A subagent completes before returning results | Audit subagent outputs, log subagent activity | | `errorOccurred` | An error occurs during agent execution | Log errors for debugging, send notifications, track error patterns | @@ -150,6 +151,28 @@ automatically before the agent commits changes. 3. Adjust the formatter command for your project ``` +## Cross-Client Compatibility + +Hook configuration files work across GitHub Copilot CLI, VS Code, and Claude Code **without modification**. The CLI accepts both camelCase and PascalCase event names (e.g., `postToolUse` and `PostToolUse` are equivalent), and supports Claude Code's nested `matcher/hooks` structure alongside the standard flat format. + +```json +{ + "hooks": [ + { + "matcher": { "event": "PostToolUse" }, + "hooks": [ + { + "type": "command", + "bash": "npx prettier --write ." + } + ] + } + ] +} +``` + +This means a single `hooks.json` file can be committed to your repository and used by team members regardless of which Copilot-compatible client they use. + ## Practical Examples ### Auto-Format After Edits @@ -216,6 +239,28 @@ Block dangerous commands before they execute: The `preToolUse` hook receives JSON input with details about the tool being called. Your script can inspect this input and exit with a non-zero code to **deny** the tool execution, or exit with zero to **approve** it. +### Injecting Context into Subagents with subagentStart + +When your agent spawns subagents (for example via the `task` tool), the `subagentStart` hook fires for each one. You can use it to inject additional context into the subagent's prompt — such as environment information or project-specific constraints — or to log and govern subagent activity: + +```json +{ + "version": 1, + "hooks": { + "subagentStart": [ + { + "type": "command", + "bash": "./scripts/inject-subagent-context.sh", + "cwd": ".", + "timeoutSec": 5 + } + ] + } +} +``` + +The hook receives context about the spawned subagent, allowing your script to output additional instructions that are injected into the subagent's starting prompt. + ### Governance Audit Scan user prompts for potential security threats and log session activity: diff --git a/website/src/content/learning-hub/installing-and-using-plugins.md b/website/src/content/learning-hub/installing-and-using-plugins.md index 28bc87955..901d23ba1 100644 --- a/website/src/content/learning-hub/installing-and-using-plugins.md +++ b/website/src/content/learning-hub/installing-and-using-plugins.md @@ -3,7 +3,7 @@ title: 'Installing and Using Plugins' description: 'Learn how to find, install, and manage plugins that extend GitHub Copilot CLI with reusable agents, skills, hooks, and integrations.' authors: - GitHub Copilot Learning Hub Team -lastUpdated: 2026-02-26 +lastUpdated: 2026-03-18 estimatedReadingTime: '8 minutes' tags: - plugins @@ -219,6 +219,23 @@ If you only need a single agent or skill (rather than a full plugin), you can st See [Using the Copilot Coding Agent](../using-copilot-coding-agent/) for details on this approach. +## Open Plugin Spec Compatibility + +GitHub Copilot CLI is compatible with the [Open Plugin Specification](https://openpluginsspec.org/), meaning plugins authored for other AI tools can often be loaded directly. The CLI discovers plugin manifests from several locations: + +| Location | Description | +|----------|-------------| +| `.github/plugin/plugin.json` | Standard Awesome Copilot format | +| `.claude-plugin/plugin.json` | Claude Code plugin format | +| `.lsp.json` or `.github/lsp.json` | LSP server configuration | + +When using `--plugin-dir`, the CLI automatically scans for these manifest locations. This means a plugin built for Claude Code (using `.claude-plugin/plugin.json`) can be loaded in Copilot CLI without any modifications. + +**Additional compatibility notes**: +- Both camelCase and PascalCase hook event names are accepted (e.g., `postToolUse` and `PostToolUse`) +- The `:` namespace separator is supported in tool names +- `exclusive` path mode is supported for more precise resource scoping + ## Best Practices - **Start with a marketplace plugin** before building your own — there may already be one that fits your needs