|
| 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) |
0 commit comments