Skip to content

Commit a9b2e7f

Browse files
hubwriterCopilot
andauthored
Copilot CLI: add more details for custom instructions (#59478)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e460d69 commit a9b2e7f

6 files changed

Lines changed: 90 additions & 62 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Adding custom instructions for Copilot CLI
3+
shortTitle: Add custom instructions
4+
intro: 'Create 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+
redirect_from:
10+
- /copilot/how-tos/copilot-cli/add-repository-instructions
11+
contentType: how-tos
12+
---
13+
14+
{% data variables.product.prodname_copilot %} can provide responses that are tailored to your personal preferences, the way your team works, the tools you use, or the specifics of your project, if you provide it with enough context to do so. Instead of repeatedly adding this contextual detail to your prompts, you can create custom instructions that automatically add this information for you. The additional information is not displayed, but is available to {% data variables.product.prodname_copilot_short %} to allow it to generate higher quality responses.
15+
16+
## Types of custom instructions
17+
18+
{% data variables.copilot.copilot_cli %} supports the following types of custom instructions.
19+
20+
### Repository-wide custom instructions
21+
22+
These apply to all requests made in the context of a repository.
23+
24+
These are specified in a `copilot-instructions.md` file in the `.github` directory at the root of the repository. See [Creating repository-wide custom instructions](#creating-repository-wide-custom-instructions).
25+
26+
### Path-specific custom instructions
27+
28+
These apply to requests made in the context of files that match a specified path.
29+
30+
These are specified in one or more `NAME.instructions.md` files within or below the `.github/instructions` directory at the root of the repository, or within or below a `.github/instructions` directory in the current working directory. See [Creating path-specific custom instructions](#creating-path-specific-custom-instructions).
31+
32+
If the path you specify in these instructions 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.
33+
34+
### Agent instructions
35+
36+
These are used by various AI agents.
37+
38+
You can create one or more `AGENTS.md` files. These can be located in the repository's root directory, in the current working directory, or in any of the directories specified by a comma-separated list of paths in the `COPILOT_CUSTOM_INSTRUCTIONS_DIRS` environment variable.
39+
40+
Instructions in the `AGENTS.md` file in the root directory, if found, are treated as primary instructions. If an `AGENTS.md` file and a `.github/copilot-instructions.md` file are both found at the root of the repository, the instructions in both files are used.
41+
42+
Instructions found in other `AGENTS.md` files are treated as additional instructions. Any primary instructions that are found are likely to have more effect on {% data variables.product.prodname_copilot_short %}'s responses than additional instructions.
43+
44+
For more information, see the [openai/agents.md repository](https://github.com/openai/agents.md).
45+
46+
Alternatively, you can use `CLAUDE.md` and `GEMINI.md` files. These must be located at the root of the repository.
47+
48+
### Local instructions
49+
50+
These apply within a specific local environment.
51+
52+
You can specify instructions within your own home directory, by creating a file at `$HOME/.copilot/copilot-instructions.md`.
53+
54+
You can also set the `COPILOT_CUSTOM_INSTRUCTIONS_DIRS` environment variable to a comma-separated list of directories. {% data variables.copilot.copilot_cli_short %} will look for an `AGENTS.md` file, and any `.github/instructions/**/*.instructions.md` files, in each of these directories.
55+
56+
## Creating repository-wide custom instructions
57+
58+
1. In the root of your repository, create a file named `.github/copilot-instructions.md`.
59+
60+
Create the `.github` directory if it does not already exist.
61+
62+
1. Add natural language instructions to the file, in Markdown format.
63+
64+
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.
65+
66+
For help on writing effective custom instructions, see [AUTOTITLE](/copilot/concepts/prompting/response-customization#writing-effective-custom-instructions).
67+
68+
## Creating path-specific custom instructions
69+
70+
{% data reusables.copilot.custom-instructions-path %}
71+
72+
{% data reusables.copilot.custom-instructions-note %}
73+
74+
{% data variables.copilot.copilot_cli_short %} caches instructions after they have been read. If you edit an instructions file, and you want to ensure that the changes are used, you must do one of the following:
75+
76+
* Restart {% data variables.copilot.copilot_cli_short %}.
77+
* Use `/resume SESSION-ID`. You can use the `/session` command to find the ID of the current session.
78+
79+
## Further reading
80+
81+
* [AUTOTITLE](/copilot/reference/custom-instructions-support)
82+
* [AUTOTITLE](/copilot/tutorials/customization-library/custom-instructions)—a curated collection of examples
83+
* [AUTOTITLE](/copilot/tutorials/use-custom-instructions)

content/copilot/how-tos/copilot-cli/add-repository-instructions.md

Lines changed: 0 additions & 54 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ children:
88
- /cli-getting-started
99
- /cli-best-practices
1010
- /install-copilot-cli
11-
- /add-repository-instructions
11+
- /add-custom-instructions
1212
- /use-hooks
1313
- /use-copilot-cli
1414
contentType: how-tos

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Plan mode lets you collaborate with {% data variables.product.prodname_copilot_s
125125

126126
### Steer the conversation while {% data variables.product.prodname_copilot_short %} is thinking
127127

128-
You can interact with {% data variables.product.prodname_copilot_short %} while it's thinking. Send follow-up messages to steer the conversation in a different direction, or queue additional instructions for {% data variables.product.prodname_copilot_short %} to process after it finishes its current response.
128+
You can interact with {% data variables.product.prodname_copilot_short %} while it's thinking. Send follow-up messages to steer the conversation in a different direction, or queue additional instructions for {% data variables.product.prodname_copilot_short %} to process after it finishes its current response.
129129

130130
### Include a specific file in your prompt
131131

@@ -193,7 +193,7 @@ You can enhance {% data variables.product.prodname_copilot_short %}’s performa
193193
* Path-specific instructions files: `.github/instructions/**/*.instructions.md`.
194194
* Agent files such as `AGENTS.md`.
195195

196-
For more information, see [AUTOTITLE](/copilot/how-tos/configure-custom-instructions/add-repository-instructions).
196+
For more information, see [AUTOTITLE](/copilot/how-tos/copilot-cli/add-custom-instructions).
197197

198198
### Use {% data variables.copilot.custom_agents_short %}
199199

@@ -278,7 +278,7 @@ Details of your configured MCP servers are stored in the `mcp-config.json` file,
278278
* `/context`: Provides a visual overview of your current token usage
279279
* `/compact`: Manually compresses your conversation history to free up context space
280280

281-
{% data variables.copilot.copilot_cli %} automatically compresses your history in the background when your conversation approaches 95% of the token limit, without interrupting your workflow.
281+
{% data variables.copilot.copilot_cli %} automatically compresses your history in the background when your conversation approaches 95% of the token limit, without interrupting your workflow.
282282

283283
### Review code changes
284284

data/reusables/copilot/custom-instructions-note.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Did you successfully add a custom instructions file to your repository?
66

77
{% endnote %}
88

9-
## Repository custom instructions in use
9+
## Custom instructions in use
1010

11-
The instructions in the file(s) are available for use by {% data variables.product.prodname_copilot_short %} as soon as you save the file(s). The complete set of instructions will be automatically added to requests that you submit to {% data variables.product.prodname_copilot_short %} in the context of that repository. For example, they are added to the prompt you submit to {% data variables.copilot.copilot_chat_short %}.
11+
The instructions in the file(s) are available for use by {% data variables.product.prodname_copilot_short %} as soon as you save the file(s). Instructions are automatically added to requests that you submit to {% data variables.product.prodname_copilot_short %}.

data/reusables/copilot/custom-instructions-path.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
1. Create the `.github/instructions` directory if it does not already exist.
2-
2+
1. Optionally, create subdirectories of `.github/instructions` to organize your instruction files.
33
1. Create one or more `NAME.instructions.md` files, where `NAME` indicates the purpose of the instructions. The file name must end with `.instructions.md`.
4-
54
1. At the start of the file, create a frontmatter block containing the `applyTo` keyword. Use glob syntax to specify what files or directories the instructions apply to.
65

76
For example:

0 commit comments

Comments
 (0)