Skip to main content

GitHub Copilot のリポジトリ カスタム命令を追加する

Copilot Chat への質問に情報を自動的に追加するファイルをリポジトリに作成します。

Note

この機能は現在パブリック プレビューにあり、変更される可能性があります。

Repository custom instructions are currently supported for Copilot Chat in Visual Studio, VS Code and on the GitHub website.

この記事のこのバージョンは、GitHub Web サイト上でリポジトリのカスタム命令を使うためのものです。 他の環境でカスタム指示を使う方法については、上のタブをクリックします。

GitHub Copilot Chat の応答のカスタマイズに使用できる方法の概要については、「About customizing GitHub Copilot Chat responses」をご覧ください。

GitHub Copilot Chat のリポジトリのカスタム命令について

GitHub Copilot は、チームの活動方法、使用するツール、またはプロジェクトの詳細に合わせて調整されたチャット応答を提供できます (そのために十分なコンテキストを指定した場合)。 このコンテキストの詳細をチャットの質問に繰り返し追加するのではなく、この情報を自動的に追加するファイルをリポジトリ内に作成できます。 追加情報はチャットには表示されませんが、Copilot が使用して、より高品質の応答を生成できます。

This example of a .github/copilot-instructions.md file contains three instructions that will be added to all chat questions.

We use Bazel for managing our Java dependencies, not Maven, so when talking about Java packages, always give me instructions and code samples that use Bazel.

We always write JavaScript with double quotes and tabs for indentation, so when your responses include JavaScript code, please follow those conventions.

Our team uses Jira for tracking items of work.

Note

Repository custom instructions are currently supported for Copilot Chat in Visual Studio, VS Code and on the GitHub website.

この記事のこのバージョンは、VS Code でリポジトリのカスタム命令を使うためのものです。 他の環境でカスタム指示を使う手順については、上のタブをクリックします。

GitHub Copilot Chat の応答のカスタマイズに使用できる方法の概要については、「About customizing GitHub Copilot Chat responses」をご覧ください。

GitHub Copilot Chat に対するリポジトリのカスタム指示とプロンプト ファイルについて

GitHub Copilot は、チームの活動方法、使用するツール、またはプロジェクトの詳細に合わせて調整されたチャット応答を提供できます (そのために十分なコンテキストを指定した場合)。 このコンテキストの詳細をチャットの質問に繰り返し追加するのではなく、この情報を自動的に追加するファイルをリポジトリ内に作成できます。

VS Code で GitHub Copilot Chat にコンテキストと指示を提供するには、次の 2 種類のファイルを使用できます。

  • リポジトリ カスタム指示を使うと、リポジトリのコンテキストで行われる会話に適用されるリポジトリ全体の指示とユーザー設定を、1 つのファイルで指定できます。
  • プロンプト ファイル (パブリック プレビュー) を使うと、共通のプロンプト指示と関連するコンテキストを Markdown ファイル (*.prompt.md) に保存し、後でそれをチャット プロンプトで再利用できます。 プロンプト ファイルは、VS Code でのみ使用できます。

カスタム命令は、各 AI ワークフローにコードベース全体のコンテキストを追加するのに役立ちますが、プロンプト ファイルを使うと、特定のチャット操作に命令を追加できます。

リポジトリ カスタム指示の例

This example of a .github/copilot-instructions.md file contains three instructions that will be added to all chat questions.

We use Bazel for managing our Java dependencies, not Maven, so when talking about Java packages, always give me instructions and code samples that use Bazel.

We always write JavaScript with double quotes and tabs for indentation, so when your responses include JavaScript code, please follow those conventions.

Our team uses Jira for tracking items of work.

プロンプト ファイルの例

次の例は、プロンプト ファイルの使用方法を示しています。

  • New React form.prompt.md - React を使ってフォームを生成する再利用可能なタスクの命令が含まれています。

    Your goal is to generate a new React form component.
    
    Ask for the form name and fields if not provided.
    
    Requirements for the form:
    - Use form design system components: [design-system/Form.md](../docs/design-system/Form.md)
    - Use `react-hook-form` for form state management:
      - Always define TypeScript types for your form data
      - Prefer *uncontrolled* components using register
      - Use `defaultValues` to prevent unnecessary rerenders
    - Use `yup` for validation:
      - Create reusable validation schemas in separate files
      - Use TypeScript types to ensure type safety
      - Customize UX-friendly validation rules
    
  • API security review.prompt.md - REST API のセキュリティ プラクティスに関する再利用可能な情報が含まれており、REST API のセキュリティ レビューを行うために使用できます。

    Secure REST API review:
    - Ensure all endpoints are protected by authentication and authorization
    - Validate all user inputs and sanitize data
    - Implement rate limiting and throttling
    - Implement logging and monitoring for security events
    …
    

Note

この機能は現在パブリック プレビューにあり、変更される可能性があります。

Repository custom instructions are currently supported for Copilot Chat in Visual Studio, VS Code and on the GitHub website.

この記事のこのバージョンは、Visual Studio でリポジトリのカスタム命令を使うためのものです。 他の環境でカスタム指示を使う手順については、上のタブをクリックします。

GitHub Copilot Chat の応答のカスタマイズに使用できる方法の概要については、「About customizing GitHub Copilot Chat responses」をご覧ください。

GitHub Copilot Chat のリポジトリのカスタム命令について

GitHub Copilot は、チームの活動方法、使用するツール、またはプロジェクトの詳細に合わせて調整されたチャット応答を提供できます (そのために十分なコンテキストを指定した場合)。 このコンテキストの詳細をチャットの質問に繰り返し追加するのではなく、この情報を自動的に追加するファイルをリポジトリ内に作成できます。 追加情報はチャットには表示されませんが、Copilot が使用して、より高品質の応答を生成できます。

This example of a .github/copilot-instructions.md file contains three instructions that will be added to all chat questions.

We use Bazel for managing our Java dependencies, not Maven, so when talking about Java packages, always give me instructions and code samples that use Bazel.

We always write JavaScript with double quotes and tabs for indentation, so when your responses include JavaScript code, please follow those conventions.

Our team uses Jira for tracking items of work.

リポジトリ カスタム指示の前提条件

  • カスタム指示ファイル (以下の手順を参照)。

リポジトリのカスタム命令ファイルを作成する

  1. リポジトリのルートに .github/copilot-instructions.md という名前のファイルを作成します。

    .github ディレクトリがまだ存在しない場合は作成します。

  2. Markdown 形式で自然言語の指示をファイルに追加します。

    指示と指示の間の空白は無視されるため、複数の指示を 1 つの段落に記述することも、1 行に 1 つずつ記述することもでき、読みやすくするために空白行で区切ることもできます。

指示の動作を確認するには、https://github.com/copilot に移動し、指示ファイルを含むリポジトリをアタッチして、会話を始めます。

カスタム指示ファイルをリポジトリにうまく追加できましたか?

はい いいえ

効果的なリポジトリのカスタム命令を作成する

.github/copilot-instructions.md ファイルに追加する指示は、ユーザーのチャット質問を補完するコンテキストすなわち関連情報を追加する、短い自己完結型の文章であることが必要です。

リポジトリのサイズと複雑さも考慮する必要があります。 次の種類の指示は、コントリビューターが数人だけの小規模なリポジトリでは機能しますが、大規模で多様なリポジトリの場合、Copilot の他の部分で問題が発生する可能性があります。

  • 応答を作成するときに外部リソースを参照するという要求
  • 特定のスタイルで回答するという指示
  • 常に特定の詳細レベルで応答するという要求

たとえば、次の指示では意図した結果が得られない場合があります。

Always conform to the coding styles defined in styleguide.md in repo my-org/my-repo when generating code.

Use @terminal when answering questions about Git.

Answer all questions in the style of a friendly colleague, using informal language.

Answer all questions in less than 1000 characters, and words of no more than 12 characters.

使われているリポジトリのカスタム命令

.github/copilot-instructions.md ファイルの指示は、ファイルを保存するとすぐに Copilot Chat によって使用できます。 完全な指示セットは、指示ファイルを含むリポジトリに関連するチャット プロンプトに自動的に追加されます。

Copilot Chat のイマーシブ ビュー (github.com/copilot) では、指示ファイルを含むリポジトリをアタッチメントとして追加して、リポジトリ カスタム指示を使う会話を開始できます。

リポジトリ カスタム指示が Copilot Chat で使われるたびに、生成される応答に対する参照として指示ファイルが追加されます。 リポジトリ カスタム指示が使われたかどうかを確認するには、[Chat] パネルのチャット応答の上部にある参照一覧を展開し、.github/copilot-instructions.md ファイルが表示されるかどうかを調べます。

展開された [References] リストのスクリーンショット。'copilot-instructions.md' ファイルが濃いオレンジ色の枠線で強調表示されています。

参照をクリックしてファイルを開くことができます。

Note

  • It is possible for multiple types of custom instructions to apply to a conversation. Personal instructions take the highest priority, followed by repository instructions, with organization instructions prioritized last. However, all sets of relevant instructions are still combined and provided to Copilot Chat.
  • Whenever possible, you should avoid providing conflicting sets of instructions. If you are concerned about response quality, you can also choose to temporarily disable repository instructions. See GitHub Copilot のリポジトリ カスタム命令を追加する.

.github/copilot-instructions.md ファイルの指示は、ファイルを保存するとすぐに Copilot Chat によって使用できます。 完全な指示セットは、Copilot Chat ビューまたはインライン チャットで送信した要求に自動的にアタッチされます。

カスタム指示はチャット ビューやインライン チャットには表示されませんが、チャット ビューで応答の参照リストを確認することで、それらが Copilot によって使われていることを確認できます。 モデルに送信されたプロンプトにカスタム指示が追加されると、.github/copilot-instructions.md ファイルが参照として一覧表示されます。 参照をクリックしてファイルを開くことができます。

展開された [References] リストのスクリーンショット。'copilot-instructions.md' ファイルが濃いオレンジ色の枠線で強調表示されています。

.github/copilot-instructions.md ファイルの指示は、ファイルを保存するとすぐに Copilot Chat によって使用できます。 完全な指示セットは、Copilot Chat ビューまたはインライン チャットで送信した要求に自動的にアタッチされます。

カスタム指示はチャット ビューやインライン チャットには表示されませんが、チャット ビューで応答の参照リストを確認することで、それらが Copilot によって使われていることを確認できます。 モデルに送信されたプロンプトにカスタム指示が追加されると、.github/copilot-instructions.md ファイルが参照として一覧表示されます。 参照をクリックしてファイルを開くことができます。

[References] ポップアップのスクリーンショット。'copilot-instructions.md' ファイルが濃いオレンジ色の枠線で強調表示されています。

リポジトリのカスタム命令の有効化または無効化

チャット質問にカスタム指示を追加するかどうかを選択できます。

  1. [Chat] パネルの上部、またはイマーシブ ページの右上にある ボタンをクリックします。

  2. [Disable custom instructions] または [Enable custom instructions] をクリックします。

    Note

    イマーシブ モードでは、カスタム命令ファイルを含むリポジトリをアタッチした場合にのみ、これらのオプションが表示されます。

選んだ内容は、変更するまで保持されます。

  1. キーボード ショートカット Command+, (Mac) / Ctrl+, (Linux/Windows) を使用して設定エディターを開きます。
  2. 検索ボックスに、「instruction file」と入力します。
  3. [Code Generation: Use Instruction Files] の下のチェックボックスをオンまたはオフにします。
  1. Visual Studio メニュー バーの [ツール] で、 [オプション] をクリックします。

    Visual Studio メニュー バーのスクリーンショット。 [ツール] メニューが展開され、[オプション] 項目がオレンジ色の枠線で強調表示されています。
  2. [Options] ダイアログで、検索ボックスに「custom instructions」と入力し、[Copilot] をクリックします。

  3. [(Preview) Enable custom instructions to be loaded from .github/copilot-instructions.md files and added to requests] のチェックボックスをオンまたはオフにします。

プロンプト ファイルの有効化と使用

Note

プロンプト ファイルは パブリック プレビュー 段階であり、変更される可能性があります。

プロンプト ファイルを使うと、追加のコンテキストを含む再利用可能なプロンプト命令を作成し、共有することができます。 プロンプト ファイルはワークスペースに格納される Markdown ファイルです。Copilot Chat でプロンプトを記述する既存の形式 (たとえば、Rewrite #file:x.ts) を模倣したものです。 ワークスペースには複数のプロンプト ファイルを含めることができます。そのそれぞれに異なる目的のプロンプトを定義します。

プロンプト ファイルを有効にする

プロンプト ファイルを有効にするには、ワークスペースの設定を構成します。

  1. Ctrl+Shift+P キー (Windows/Linux) または Command+Shift+P キー (Mac) を押してコマンド パレットを開きます。
  2. 「Open Workspace Settings (JSON)」と入力し、表示されるオプションを選びます。
  3. settings.json ファイルに "chat.promptFiles": true を追加します。これで、.github/prompts フォルダーはプロンプト ファイルの場所として有効になります。 このフォルダーが存在しない場合は作成されます。

プロンプト ファイルを作成する

  1. Ctrl+Shift+P キー (Windows/Linux) または Command+Shift+P キー (Mac) を押してコマンド パレットを開きます。

  2. 「prompt」と入力し、[Chat: Create Prompt] を選びます。

  3. ファイル名の拡張子 .prompt.md を除いたプロンプト ファイルの名前を入力します。 名前には英数字とスペースを含めることができます。また、ファイルに含まれるプロンプト情報の目的がわかるようにすることをお勧めします。

  4. Markdown 形式を使ってプロンプト命令を記述します。

    ワークスペース内の他のファイルを参照するには、Markdown リンク ([index](../../web/index.ts) など) を使うか、#file:../../web/index.ts 構文を使います。 パスはプロンプト ファイルからの相対パスです。 他のファイルを参照することで、API 仕様や製品ドキュメントなどの追加のコンテキストを提供できます。

プロンプト ファイルを使う

  1. Copilot Chat ビューの下部にある [Attach context] アイコン () をクリックします。

  2. ドロップダウン メニューの **[Prompt...] ** をクリックし、使うプロンプト ファイルを選びます。

  3. 必要に応じて、プロンプト ファイルなどの追加ファイルを添付して、より多くのコンテキストを提供します。

  4. 必要に応じて、チャット プロンプト ボックスにその他の情報を入力します。

    これが必要かどうかは、使うプロンプトのコンテンツによって異なります。

  5. チャット プロンプトを送信します。

プロンプト ファイルについて詳しくは、Visual Studio Code のドキュメントの「VS Code での GitHub Copilot に対するカスタム指示」をご覧ください。