Skip to content

Commit da88426

Browse files
hubwritersubatoi
andauthored
Copilot CLI: Add docs for user-level hooks and improve existing hooks docs (#61024)
Co-authored-by: Ben Ahmady <32935794+subatoi@users.noreply.github.com>
1 parent 6b0477b commit da88426

24 files changed

Lines changed: 360 additions & 684 deletions

File tree

content/copilot/concepts/agents/cloud-agent/about-cloud-agent.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ contentType: concepts
2020
category:
2121
- Learn about Copilot
2222
---
23-
<!-- expires 2026-04-21 -->
24-
<!-- When this expires, search all references to {% data variables.copilot.copilot_cloud_agent_tmp %} in docs-internal and replace with {% data variables.copilot.copilot_cloud_agent %} -->
25-
## Overview of {% data variables.copilot.copilot_cloud_agent_tmp %}
26-
<!-- end expires 2026-04-21 -->
23+
24+
## Overview of {% data variables.copilot.copilot_cloud_agent %}
25+
2726
With {% data variables.copilot.copilot_cloud_agent %}, {% data variables.product.prodname_copilot %} can work independently in the background to complete tasks, just like a human developer.
2827

2928
{% data variables.copilot.copilot_cloud_agent %} can:
@@ -137,7 +136,7 @@ You can customize {% data variables.copilot.copilot_cloud_agent %} in a number o
137136
* **Custom instructions**: Custom instructions allow you to give {% data variables.product.prodname_copilot_short %} additional context on your project and how to build, test and validate its changes. For more information, see [AUTOTITLE](/copilot/how-tos/configure-custom-instructions/add-repository-instructions).
138137
* **Model Context Protocol (MCP) servers**: MCP servers allow you to give {% data variables.product.prodname_copilot_short %} access to different data sources and tools. For more information, see [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/extend-cloud-agent-with-mcp).
139138
* **{% data variables.copilot.custom_agents_caps_short %}**: {% data variables.copilot.custom_agents_caps_short %} allow you to create different specialized versions of {% data variables.product.prodname_copilot_short %} for different tasks. For example, you could customize {% data variables.product.prodname_copilot_short %} to be an expert frontend engineer following your team's guidelines. For more information, see [AUTOTITLE](/copilot/concepts/agents/cloud-agent/about-custom-agents).
140-
* **Hooks**: Hooks allow you to execute custom shell commands at key points during agent execution, enabling you to add validation, logging, security scanning, or workflow automation. For more information, see [AUTOTITLE](/copilot/concepts/agents/cloud-agent/about-hooks).
139+
* **Hooks**: Hooks allow you to execute custom shell commands at key points during agent execution, enabling you to add validation, logging, security scanning, or workflow automation. For more information, see [AUTOTITLE](/copilot/concepts/agents/hooks).
141140
* **Skills**: Skills allow you to enhance the ability of {% data variables.product.prodname_copilot_short %} to perform specialized tasks with instructions, scripts, and resources. For more information, see [AUTOTITLE](/copilot/concepts/agents/about-agent-skills).
142141

143142
## Limitations of {% data variables.copilot.copilot_cloud_agent %}

content/copilot/concepts/agents/cloud-agent/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ children:
99
- /about-cloud-agent
1010
- /agent-management
1111
- /about-custom-agents
12-
- /about-hooks
1312
- /access-management
1413
- /mcp-and-cloud-agent
1514
- /risks-and-mitigations

content/copilot/concepts/agents/copilot-cli/about-copilot-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ You can customize {% data variables.copilot.copilot_cli %} in a number of ways:
174174
* **Custom instructions**: Custom instructions allow you to give {% data variables.product.prodname_copilot_short %} additional context on your project and how to build, test and validate its changes. All custom instruction files now combine instead of using priority-based fallbacks. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-cli/customize-copilot/add-custom-instructions).
175175
* **Model Context Protocol (MCP) servers**: MCP servers allow you to give {% data variables.product.prodname_copilot_short %} access to different data sources and tools. For more information, see [AUTOTITLE](/copilot/how-tos/use-copilot-agents/use-copilot-cli#add-an-mcp-server).
176176
* **{% data variables.copilot.custom_agents_caps_short %}**: {% data variables.copilot.custom_agents_caps_short %} allow you to create different specialized versions of {% data variables.product.prodname_copilot_short %} for different tasks. For example, you could customize {% data variables.product.prodname_copilot_short %} to be an expert frontend engineer following your team's guidelines. {% data variables.copilot.copilot_cli %} includes specialized {% data variables.copilot.custom_agents_short %} that it automatically delegates common tasks to. For more information, see [AUTOTITLE](/copilot/how-tos/use-copilot-agents/use-copilot-cli#use-custom-agents).
177-
* **Hooks**: Hooks allow you to execute custom shell commands at key points during agent execution, enabling you to add validation, logging, security scanning, or workflow automation. See [AUTOTITLE](/copilot/concepts/agents/cloud-agent/about-hooks).
177+
* **Hooks**: Hooks allow you to execute custom shell commands at key points during agent execution, enabling you to add validation, logging, security scanning, or workflow automation. See [AUTOTITLE](/copilot/concepts/agents/hooks).
178178
* **Skills**: Skills allow you to enhance the ability of {% data variables.product.prodname_copilot_short %} to perform specialized tasks with instructions, scripts, and resources. For more information, see [AUTOTITLE](/copilot/concepts/agents/about-agent-skills).
179179
* **{% data variables.copilot.copilot_memory %}**: {% data variables.copilot.copilot_memory %} allows {% data variables.product.prodname_copilot_short %} to build a persistent understanding of your repository by storing "memories", which are pieces of information about coding conventions, patterns, and preferences that {% data variables.product.prodname_copilot_short %} deduces as it works. This reduces the need to repeatedly explain context in your prompts and makes future sessions more productive. For more information, see [AUTOTITLE](/copilot/concepts/agents/copilot-memory).
180180

content/copilot/concepts/agents/copilot-cli/comparing-cli-features.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ Avoid hooks when:
271271

272272
See:
273273
* [AUTOTITLE](/copilot/how-tos/copilot-cli/use-hooks)
274-
* [AUTOTITLE](/copilot/reference/hooks-configuration)
275-
* [AUTOTITLE](/copilot/reference/copilot-cli-reference/cli-hooks-reference)
274+
* [AUTOTITLE](/copilot/reference/hooks-reference)
276275

277276
## Subagents
278277

content/copilot/concepts/agents/cloud-agent/about-hooks.md renamed to content/copilot/concepts/agents/hooks.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
---
2-
title: About hooks
2+
title: About hooks for {% data variables.product.prodname_copilot %}
33
shortTitle: Hooks
44
intro: 'Extend and customize {% data variables.product.prodname_copilot %} agent behavior by executing custom shell commands at key points during agent execution.'
5-
product: '{% data reusables.gated-features.copilot-cloud-agent %}<br><a href="https://github.com/features/copilot/plans?ref_product=copilot&ref_type=purchase&ref_style=button" target="_blank" class="btn btn-primary mt-3 mr-3 no-underline"><span>Sign up for {% data variables.product.prodname_copilot_short %}</span> {% octicon "link-external" height:16 %}</a>'
65
versions:
76
feature: copilot
87
contentType: concepts
98
category:
109
- Configure Copilot
1110
redirect_from:
1211
- /copilot/concepts/agents/coding-agent/about-hooks
12+
- /copilot/concepts/agents/cloud-agent/about-hooks
13+
- /copilot/concepts/agents/about-hooks
1314
---
1415

15-
## About hooks
16+
## What are hooks?
1617

17-
Hooks enable you to execute custom shell commands at strategic points in an agent's workflow, such as when an agent session starts or ends, or before and after a prompt is entered or a tool is called.
18+
Hooks are a way of executing custom shell commands at strategic points in an agent's workflow, such as when an agent session starts or ends, when you enter a prompt, or when a tool is called.
1819

1920
Hooks receive detailed information about agent actions via JSON input, enabling context-aware automation. For example, you can use hooks to:
2021

2122
* Programmatically approve or deny tool executions.
22-
* Utilize built-in security features like secret scanning to prevent credential leaks.
23+
* Use built-in security features like secret scanning to prevent credential leaks.
2324
* Implement custom validation rules and audit logging for compliance.
2425

25-
{% data variables.product.prodname_copilot_short %} agents support hooks stored in JSON files in your repository at `.github/hooks/*.json`.
26-
2726
Hooks are available for use with:
2827

29-
* {% data variables.copilot.copilot_cloud_agent %} on {% data variables.product.github %}
30-
* {% data variables.copilot.copilot_cli %} in the terminal
28+
* **{% data variables.copilot.copilot_cloud_agent %}** on {% data variables.product.github %}.
29+
* **{% data variables.copilot.copilot_cli %}** in your terminal.
30+
31+
You define hooks in JSON files, stored in your repository at `.github/hooks/*.json`. These apply whenever {% data variables.product.prodname_copilot_short %} agents are used in the repository. {% data variables.copilot.copilot_cli_short %} also supports personal hooks that you store in your home directory at `~/.copilot/hooks/*.json`. These apply whenever you use {% data variables.copilot.copilot_cli_short %}.
3132

3233
## Types of hooks
3334

@@ -42,7 +43,7 @@ The following types of hooks are available:
4243
* **subagentStop**: Executed when a subagent completes, before returning results to the parent agent.
4344
* **errorOccurred**: Executed when an error occurs during agent execution. Can be used to log errors for debugging, send notifications, track error patterns, and generate reports.
4445

45-
To see a complete reference of hook types with example use cases, best practices, and advanced patterns, see [AUTOTITLE](/copilot/reference/hooks-configuration).
46+
To see a complete reference of hook types with example use cases, best practices, and advanced patterns, see [AUTOTITLE](/copilot/reference/hooks-reference).
4647

4748
## Hook configuration format
4849

@@ -162,4 +163,6 @@ To ensure security is maintained when using hooks, keep the following considerat
162163

163164
## Next steps
164165

165-
To start creating hooks, see [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/use-hooks).
166+
To start creating hooks, see:
167+
* [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/use-hooks) for {% data variables.copilot.copilot_cloud_agent %}
168+
* [AUTOTITLE](/copilot/how-tos/copilot-cli/customize-copilot/use-hooks) for {% data variables.copilot.copilot_cli %}

content/copilot/concepts/agents/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ children:
1010
- /copilot-cli
1111
- /code-review
1212
- /copilot-memory
13+
- /hooks
1314
- /about-third-party-agents
1415
- /openai-codex
1516
- /anthropic-claude

content/copilot/get-started/features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ These features can work autonomously without direct human supervision. However,
4545

4646
A command line interface that lets you use {% data variables.product.prodname_copilot_short %} in your terminal. Use the CLI to add features or fix bugs, then create a pull request. Start {% data variables.product.prodname_copilot_short %} working on a task in your terminal, then continue working in the same session on {% data variables.product.prodname_dotcom_the_website %}, or on your mobile. See [AUTOTITLE](/copilot/concepts/agents/about-copilot-cli).
4747

48-
### {% data variables.copilot.copilot_cloud_agent_tmp %}
48+
### {% data variables.copilot.copilot_cloud_agent %}
4949

5050
An autonomous AI agent that can research a repository, create an implementation plan, and make code changes on a branch. You can review the diff, iterate, and create a pull request when you're ready. You can also assign a {% data variables.product.github %} issue to {% data variables.product.prodname_copilot_short %} or ask it to open a pull request directly to complete a task. See [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent).
5151

content/copilot/how-tos/copilot-cli/customize-copilot/use-hooks.md

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,95 @@ docsTeamMetrics:
1616

1717
{% data reusables.copilot.cloud-agent.hooks-intro %}
1818

19-
## Creating a hook in a repository on {% data variables.product.github %}
19+
## Prerequisite
20+
21+
**For Windows only:** The examples in this article use PowerShell. If you're using Windows, you must have PowerShell 7.0 or later installed and in your PATH. You can check your PowerShell version by running `pwsh --version` in a terminal. To install PowerShell, run `winget install Microsoft.PowerShell` then restart your terminal.
22+
23+
## Creating a repository-level hook
24+
25+
1. Create a new `NAME.json` file (where `NAME` describes the purpose of the file) in the `.github/hooks/` folder of your repository.
2026

2127
{% data reusables.copilot.cloud-agent.create-hooks-instructions %}
2228

29+
## Creating a user-level hook
30+
31+
User-level hooks are configured just like repository-level hooks, but the hook files are stored locally, below your home directory.
32+
33+
The following examples for macOS and Windows show how to configure hooks that will play a sound and display a message box when the CLI finishes responding to a prompt, and when you quit {% data variables.copilot.copilot_cli_short %}. Hooks for Linux would be similar to the macOS example, but would use Linux tools for playing sounds and displaying messages.
34+
35+
### User-level example for macOS
36+
37+
1. Create a file called `notification-hooks.json` in `~/.copilot/hooks/`.
38+
39+
> [!NOTE]
40+
> If `COPILOT_HOME` is set, create the file in `$COPILOT_HOME/hooks/`.
41+
42+
1. Copy and paste the following JSON into the file:
43+
44+
```json copy
45+
{
46+
"version": 1,
47+
"hooks": {
48+
"agentStop": [
49+
{
50+
"type": "command",
51+
"bash": "osascript -e 'do shell script \"afplay /System/Library/Sounds/Funk.aiff &> /dev/null &\"' -e 'display dialog \"Agent stopped.\" with title \"Hook-generated message\" buttons {\"OK\"} default button \"OK\"'",
52+
"timeoutSec": 5
53+
}
54+
],
55+
"sessionEnd": [
56+
{
57+
"type": "command",
58+
"bash": "osascript -e 'do shell script \"afplay /System/Library/Sounds/Funk.aiff &> /dev/null &\"' -e 'display dialog \"Session ended.\" with title \"Hook-generated message\" buttons {\"OK\"} default button \"OK\"'",
59+
"timeoutSec": 5
60+
}
61+
]
62+
}
63+
}
64+
```
65+
66+
{% data reusables.copilot.cloud-agent.hooks-example-steps %}
67+
68+
### User-level example for Windows
69+
70+
1. Create a file called `notification-hooks.json` in `%USERPROFILE%\.copilot\hooks\`.
71+
72+
> [!NOTE]
73+
> If `COPILOT_HOME` is set, create the file in `%COPILOT_HOME%\hooks\`.
74+
75+
1. Copy and paste the following JSON into the file:
76+
77+
```json copy
78+
{
79+
"version": 1,
80+
"hooks": {
81+
"agentStop": [
82+
{
83+
"type": "command",
84+
"powershell": "Add-Type -AssemblyName System.Windows.Forms; [System.Media.SystemSounds]::Asterisk.Play(); [System.Windows.Forms.MessageBox]::Show('Agent stopped.', 'Hook-generated message') | Out-Null",
85+
"timeoutSec": 5
86+
}
87+
],
88+
"sessionEnd": [
89+
{
90+
"type": "command",
91+
"powershell": "Add-Type -AssemblyName System.Windows.Forms; [System.Media.SystemSounds]::Asterisk.Play(); [System.Windows.Forms.MessageBox]::Show('Session ended.', 'Hook-generated message') | Out-Null",
92+
"timeoutSec": 5
93+
}
94+
]
95+
}
96+
}
97+
```
98+
99+
{% data reusables.copilot.cloud-agent.hooks-example-steps %}
100+
23101
## Troubleshooting
24102

25103
{% data reusables.copilot.cloud-agent.troubleshoot-hooks %}
26104

27105
## Further reading
28106

29-
* [AUTOTITLE](/copilot/reference/hooks-configuration)
107+
* [AUTOTITLE](/copilot/reference/hooks-reference)
30108
* [AUTOTITLE](/copilot/concepts/agents/cloud-agent/about-cloud-agent)
31109
* [AUTOTITLE](/copilot/concepts/agents/about-copilot-cli)
32110
* [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/customize-the-agent-environment)
33-
* [AUTOTITLE](/copilot/reference/copilot-cli-reference/cli-hooks-reference)

content/copilot/how-tos/copilot-cli/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ children:
4242
- /content/copilot/reference/copilot-cli-reference/cli-command-reference
4343
- /content/copilot/reference/copilot-cli-reference/cli-plugin-reference
4444
- /content/copilot/reference/copilot-cli-reference/cli-programmatic-reference
45-
- /content/copilot/reference/hooks-configuration
45+
- /content/copilot/reference/hooks-reference
4646
- /content/copilot/responsible-use/copilot-cli
4747
- /content/copilot/tutorials/copilot-cli-hooks
4848
- /customize-copilot/add-custom-instructions

content/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/use-hooks.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ intro: 'Run automated checks—like linting, formatting, or security scans—at
55
versions:
66
feature: copilot
77
contentType: how-tos
8-
category:
8+
category:
99
- Configure Copilot
1010
redirect_from:
1111
- /copilot/how-tos/use-copilot-agents/coding-agent/use-hooks
@@ -16,6 +16,11 @@ redirect_from:
1616

1717
## Creating a hook in a repository on {% data variables.product.github %}
1818

19+
1. Create a new `NAME.json` file (where `NAME` describes the purpose of the file) in the `.github/hooks/` folder of your repository.
20+
21+
> [!IMPORTANT]
22+
> The hooks configuration file **must be present** on your repository's default branch to be used by {% data variables.copilot.copilot_cloud_agent %}.
23+
1924
{% data reusables.copilot.cloud-agent.create-hooks-instructions %}
2025

2126
## Troubleshooting
@@ -24,7 +29,7 @@ redirect_from:
2429

2530
## Further reading
2631

27-
* [AUTOTITLE](/copilot/reference/hooks-configuration)
32+
* [AUTOTITLE](/copilot/reference/hooks-reference)
2833
* [AUTOTITLE](/copilot/concepts/agents/cloud-agent/about-cloud-agent)
2934
* [AUTOTITLE](/copilot/concepts/agents/about-copilot-cli)
3035
* [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/customize-the-agent-environment)

0 commit comments

Comments
 (0)