Skip to content

Commit 3425e6b

Browse files
SiaraMistCopilothubwriter
authored
Create a CLI map topic for rapid publishing (#59413)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: hubwriter <hubwriter@github.com>
1 parent f1971c0 commit 3425e6b

File tree

13 files changed

+198
-147
lines changed

13 files changed

+198
-147
lines changed

content/copilot/how-tos/configure-custom-instructions/add-repository-instructions.md

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -531,58 +531,6 @@ Whitespace between instructions is ignored, so the instructions can be written a
531531

532532
<!-- end of Xcode tab -->
533533

534-
<!-- START COPILOT CLI TAB -->
535-
536-
{% copilotcli %}
537-
538-
This version of this article is for using repository custom instructions with the {% data variables.product.prodname_copilot %} CLI. Click the tabs above for instructions on using custom instructions in other environments.
539-
540-
## Creating custom instructions
541-
542-
{% data variables.product.prodname_copilot %} supports three types of repository custom instructions.
543-
544-
* **Repository-wide custom instructions**, which apply to all requests made in the context of a repository.
545-
546-
These are specified in a `copilot-instructions.md` file in the `.github` directory of the repository. See [Creating repository-wide custom instructions](#creating-repository-wide-custom-instructions).
547-
548-
* **Path-specific custom instructions**, which apply to requests made in the context of files that match a specified path.
549-
550-
These are specified in one or more `NAME.instructions.md` files within or below the `.github/instructions` directory in the repository. See [Creating path-specific custom instructions](#creating-path-specific-custom-instructions).
551-
552-
If the path you specify matches a file that {% data variables.product.prodname_copilot_short %} is working on, and a repository-wide custom instructions file also exists, then the instructions from both files are used. You should avoid potential conflicts between instructions as {% data variables.product.prodname_copilot_short %}'s choice between conflicting instructions is non-deterministic.
553-
554-
* **Agent instructions** are used by AI agents.
555-
556-
{% data reusables.copilot.custom-instructions-agents %}
557-
558-
Alternatively, you can use a single `CLAUDE.md` or `GEMINI.md` file stored in the root of the repository.
559-
560-
## Creating repository-wide custom instructions
561-
562-
1. In the root of your repository, create a file named `.github/copilot-instructions.md`.
563-
564-
Create the `.github` directory if it does not already exist.
565-
566-
1. Add natural language instructions to the file, in Markdown format.
567-
568-
Whitespace between instructions is ignored, so the instructions can be written as a single paragraph, each on a new line, or separated by blank lines for legibility.
569-
570-
## Creating path-specific custom instructions
571-
572-
{% data reusables.copilot.custom-instructions-path %}
573-
574-
{% data reusables.copilot.custom-instructions-note %}
575-
576-
## Further reading
577-
578-
* [AUTOTITLE](/copilot/reference/custom-instructions-support)
579-
* [AUTOTITLE](/copilot/tutorials/customization-library/custom-instructions)—a curated collection of examples
580-
* [AUTOTITLE](/copilot/tutorials/use-custom-instructions)
581-
582-
{% endcopilotcli %}
583-
584-
<!-- end of Copilot CLI tab -->
585-
586534
<!-- START ECLIPSE TAB -->
587535

588536
{% eclipse %}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: Adding repository custom instructions
3+
shortTitle: Add repository instructions
4+
intro: 'Create repository custom instructions files that give {% data variables.product.prodname_copilot_short %} additional context on how to understand your project and how to build, test and validate its changes.'
5+
versions:
6+
feature: copilot
7+
topics:
8+
- Copilot
9+
contentType: how-tos
10+
---
11+
12+
This version of this article is for using repository custom instructions with the {% data variables.product.prodname_copilot %} CLI. Click the tabs above for instructions on using custom instructions in other environments.
13+
14+
## Creating custom instructions
15+
16+
{% data variables.product.prodname_copilot %} supports three types of repository custom instructions.
17+
18+
* **Repository-wide custom instructions**, which apply to all requests made in the context of a repository.
19+
20+
These are specified in a `copilot-instructions.md` file in the `.github` directory of the repository. See [Creating repository-wide custom instructions](#creating-repository-wide-custom-instructions).
21+
22+
* **Path-specific custom instructions**, which apply to requests made in the context of files that match a specified path.
23+
24+
These are specified in one or more `NAME.instructions.md` files within or below the `.github/instructions` directory in the repository. See [Creating path-specific custom instructions](#creating-path-specific-custom-instructions).
25+
26+
If the path you specify matches a file that {% data variables.product.prodname_copilot_short %} is working on, and a repository-wide custom instructions file also exists, then the instructions from both files are used. You should avoid potential conflicts between instructions as {% data variables.product.prodname_copilot_short %}'s choice between conflicting instructions is non-deterministic.
27+
28+
* **Agent instructions** are used by AI agents.
29+
30+
{% data reusables.copilot.custom-instructions-agents %}
31+
32+
Alternatively, you can use a single `CLAUDE.md` or `GEMINI.md` file stored in the root of the repository.
33+
34+
## Creating repository-wide custom instructions
35+
36+
1. In the root of your repository, create a file named `.github/copilot-instructions.md`.
37+
38+
Create the `.github` directory if it does not already exist.
39+
40+
1. Add natural language instructions to the file, in Markdown format.
41+
42+
Whitespace between instructions is ignored, so the instructions can be written as a single paragraph, each on a new line, or separated by blank lines for legibility.
43+
44+
## Creating path-specific custom instructions
45+
46+
{% data reusables.copilot.custom-instructions-path %}
47+
48+
{% data reusables.copilot.custom-instructions-note %}
49+
50+
## Further reading
51+
52+
* [AUTOTITLE](/copilot/reference/custom-instructions-support)
53+
* [AUTOTITLE](/copilot/tutorials/customization-library/custom-instructions)—a curated collection of examples
54+
* [AUTOTITLE](/copilot/tutorials/use-custom-instructions)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: GitHub Copilot CLI
3+
shortTitle: Copilot CLI
4+
intro: Learn how to use {% data variables.product.prodname_copilot %} in your terminal.
5+
versions:
6+
feature: copilot
7+
children:
8+
- /install-copilot-cli
9+
- /add-repository-instructions
10+
- /use-hooks
11+
- /use-copilot-cli
12+
contentType: how-tos
13+
---
14+

content/copilot/how-tos/set-up/install-copilot-cli.md renamed to content/copilot/how-tos/copilot-cli/install-copilot-cli.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Installing GitHub Copilot CLI
33
shortTitle: Install Copilot CLI
4-
intro: 'Learn how to install {% data variables.copilot.copilot_cli_short %} so that you can use {% data variables.product.prodname_copilot_short %} directly from the command line.'
4+
intro: Learn how to install {% data variables.copilot.copilot_cli_short %} so that you can use {% data variables.product.prodname_copilot_short %} directly from the command line.
55
versions:
66
feature: copilot
77
topics:
@@ -15,6 +15,7 @@ redirect_from:
1515
- /copilot/managing-copilot/configure-personal-settings/installing-github-copilot-in-the-cli
1616
- /copilot/how-tos/personal-settings/installing-github-copilot-in-the-cli
1717
- /copilot/how-tos/set-up/installing-github-copilot-in-the-cli
18+
- /copilot/how-tos/set-up/install-copilot-cli
1819
contentType: how-tos
1920
category:
2021
- Configure Copilot

content/copilot/how-tos/use-copilot-agents/use-copilot-cli.md renamed to content/copilot/how-tos/copilot-cli/use-copilot-cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ intro: Learn how to use {% data variables.product.prodname_copilot %} from the c
55
product: '{% data reusables.gated-features.copilot-cli %}'
66
redirect_from:
77
- /copilot/how-tos/use-copilot-cli
8+
- /copilot/how-tos/use-copilot-agents/use-copilot-cli
89
versions:
910
feature: copilot
1011
topics:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Using hooks with GitHub Copilot CLI
3+
shortTitle: Use hooks
4+
intro: "Extend {% data variables.product.prodname_copilot %} agent behavior with custom shell commands at key points during agent execution."
5+
versions:
6+
feature: copilot
7+
topics:
8+
- Copilot
9+
contentType: how-tos
10+
category:
11+
- Configure Copilot
12+
---
13+
14+
{% data reusables.copilot.coding-agent.hooks-intro %}
15+
16+
## Creating a hook in a repository on {% data variables.product.github %}
17+
18+
{% data reusables.copilot.coding-agent.create-hooks-instructions %}
19+
20+
## Troubleshooting
21+
22+
{% data reusables.copilot.coding-agent.troubleshoot-hooks %}
23+
24+
## Further reading
25+
26+
* [AUTOTITLE](/copilot/reference/hooks-configuration)
27+
* [AUTOTITLE](/copilot/concepts/agents/coding-agent/about-coding-agent)
28+
* [AUTOTITLE](/copilot/concepts/agents/about-copilot-cli)
29+
* [AUTOTITLE](/copilot/how-tos/use-copilot-agents/coding-agent/customize-the-agent-environment)

content/copilot/how-tos/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ children:
1010
- /set-up
1111
- /get-code-suggestions
1212
- /chat-with-copilot
13+
- /copilot-cli
1314
- /use-copilot-agents
1415
- /use-ai-models
1516
- /provide-context

content/copilot/how-tos/set-up/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Setting up GitHub Copilot
33
shortTitle: Set up
4-
intro: 'Learn how to set up {% data variables.product.prodname_copilot %}.'
4+
intro: Learn how to set up {% data variables.product.prodname_copilot %}.
55
topics:
66
- Copilot
77
versions:
@@ -12,9 +12,9 @@ children:
1212
- /set-up-for-enterprise
1313
- /set-up-a-dedicated-enterprise-for-copilot-business
1414
- /install-copilot-extension
15-
- /install-copilot-cli
1615
redirect_from:
1716
- /copilot/setting-up-github-copilot
1817
- /copilot/get-started/setting-up-github-copilot
1918
contentType: how-tos
2019
---
20+

content/copilot/how-tos/use-copilot-agents/coding-agent/use-hooks.md

Lines changed: 4 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Using hooks with GitHub Copilot agents
33
shortTitle: Use hooks
4-
intro: 'Learn how to extend and customize {% data variables.product.prodname_copilot %} agent behavior by executing custom shell commands at key points during agent execution.'
4+
intro: 'Extend and customize {% data variables.product.prodname_copilot %} agent behavior by executing custom shell commands at key points during agent execution.'
55
versions:
66
feature: copilot
77
topics:
@@ -11,101 +11,15 @@ category:
1111
- Configure Copilot
1212
---
1313

14-
Hooks allow you to extend and customize the behavior of {% data variables.product.prodname_copilot %} agents by executing custom shell commands at key points during agent execution. For a conceptual overview of hooks, see [AUTOTITLE](/copilot/concepts/agents/coding-agent/about-hooks).
14+
{% data reusables.copilot.coding-agent.hooks-intro %}
1515

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

18-
1. Create a new `hooks.json` file with the name of your choice in the `.github/hooks/` folder of your repository. The hooks configuration file **must be present** on your repository's default branch to be used by {% data variables.copilot.copilot_coding_agent %}. For {% data variables.copilot.copilot_cli %}, hooks are loaded from your current working directory.
19-
20-
1. In your text editor, copy and paste the following hook template. Remove any hooks you don't plan on using from the `hooks` array.
21-
22-
```json copy
23-
{
24-
"version": 1,
25-
"hooks": {
26-
"sessionStart": [...],
27-
"sessionEnd": [...],
28-
"userPromptSubmitted": [...],
29-
"preToolUse": [...],
30-
"postToolUse": [...],
31-
"errorOccurred": [...]
32-
}
33-
}
34-
```
35-
36-
1. Configure your hook syntax under the `bash` or `powershell` keys, or directly reference script files you have created.
37-
38-
* This example runs a script that outputs the start date of the session to a log file using the `sessionStart` hook:
39-
40-
```json copy
41-
"sessionStart": [
42-
{
43-
"type": "command",
44-
"bash": "echo \"Session started: $(date)\" >> logs/session.log",
45-
"powershell": "Add-Content -Path logs/session.log -Value \"Session started: $(Get-Date)\"",
46-
"cwd": ".",
47-
"timeoutSec": 10
48-
}
49-
],
50-
```
51-
52-
* This example calls out to an external `log-prompt` script:
53-
54-
```json copy
55-
"userPromptSubmitted": [
56-
{
57-
"type": "command",
58-
"bash": "./scripts/log-prompt.sh",
59-
"powershell": "./scripts/log-prompt.ps1",
60-
"cwd": "scripts",
61-
"env": {
62-
"LOG_LEVEL": "INFO"
63-
}
64-
}
65-
],
66-
```
67-
68-
For a full reference on the input JSON from agent sessions along with sample scripts, see [AUTOTITLE](/copilot/reference/hooks-configuration).
69-
70-
1. Commit the file to the repository and merge it into the default branch. Your hooks will now run during agent sessions.
18+
{% data reusables.copilot.coding-agent.create-hooks-instructions %}
7119

7220
## Troubleshooting
7321

74-
If you run into problems using hooks, use the following table to troubleshoot.
75-
76-
| Issue | Action |
77-
| --- | --- |
78-
| Hooks are not executing | <ul><li>Verify the JSON file is in the `.github/hooks/` directory.</li><li>Check for valid JSON syntax (for example, `jq . hooks.json`).</li><li>Ensure `version: 1` is specified in your `hooks.json` file.</li><li>Verify the script you are calling from your hook is executable (`chmod +x script.sh`)</li><li>Check that the script has a proper shebang (for example, `#!/bin/bash`)</li></ul> |
79-
| Hooks are timing out | <ul><li>The default timeout is 30 seconds. Increase `timeoutSec` in the configuration if needed.</li><li>Optimize script performance by avoiding unnecessary operations.</li> |
80-
| Invalid JSON output | <ul><li>Ensure the output is on a single line.</li><li>On Unix, use `jq -c` to compact and validate the JSON output.</li><li>On Windows, use the `ConvertTo-Json -Compress` command in PowerShell to do the same.</li></ul> |
81-
82-
## Debugging
83-
84-
You can debug hooks using the following methods:
85-
86-
* **Enable verbose logging** in the script to inspect the input data and trace script execution.
87-
88-
```shell copy
89-
#!/bin/bash
90-
set -x # Enable bash debug mode
91-
INPUT=$(cat)
92-
echo "DEBUG: Received input" >&2
93-
echo "$INPUT" >&2
94-
# ... rest of script
95-
```
96-
97-
* **Test hooks locally** by piping test input into your hook to validate its behavior:
98-
99-
```shell copy
100-
# Create test input
101-
echo '{"timestamp":1704614400000,"cwd":"/tmp","toolName":"bash","toolArgs":"{\"command\":\"ls\"}"}' | ./my-hook.sh
102-
103-
# Check exit code
104-
echo $?
105-
106-
# Validate output is valid JSON
107-
./my-hook.sh | jq .
108-
```
22+
{% data reusables.copilot.coding-agent.troubleshoot-hooks %}
10923

11024
## Further reading
11125

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Use GitHub Copilot agents
33
shortTitle: Use Copilot agents
4-
intro: 'Learn how to use {% data variables.product.prodname_copilot %} agents.'
4+
intro: Learn how to use {% data variables.product.prodname_copilot %} agents.
55
versions:
66
feature: copilot
77
topics:
@@ -10,9 +10,9 @@ children:
1010
- /manage-agents
1111
- /coding-agent
1212
- /request-a-code-review
13-
- /use-copilot-cli
1413
- /copilot-memory
1514
redirect_from:
1615
- /copilot/how-tos/agents
1716
contentType: how-tos
1817
---
18+

0 commit comments

Comments
 (0)