0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCode 用の Copilot 設定で、chatmode/allowlist/editRequest が便利

Last updated at Posted at 2025-07-14

背景

Copilot を使う設定で、自動承認機能来ないかなぁとか思ってたら、いい感じできたので、settings.json にコピペできるように使いそうなものを集めてみた。

settings.json をコピペして使ってみるのが一番ですね。

vscode version

バージョン: 1.102.0 (user setup)
コミット: cb0c47c0cfaad0757385834bd89d410c78a856c0
日付: 2025-07-09T22:10:34.600Z
Electron: 35.6.0
ElectronBuildId: 11847422
Chromium: 134.0.6998.205
Node.js: 22.15.1
V8: 13.4.114.21-electron.0
OS: Windows_NT x64 10.0.26100

チャットの指示方法:三種

Visual Studio Code の Copilot では、AI 応答やコード生成をプロジェクトごとに柔軟にカスタマイズできる。

主な手法は以下の 3 つ。

三番目のは、従来の、Agent/Ask/Eidt を拡張できるようになったので、より柔軟に用途に応じたチャットが定義出来ていい感じ

1. カスタム指示ファイル(instructions)

  • プロジェクト全体や特定言語・タスクごとのルールを Markdown で記述
  • .github/copilot-instructions.md:全体共通の指示
  • .github/instructions/*.instructions.md:言語・タスクごとに細分化。applyTo で適用範囲指定

例:

---
applyTo: "**/*.ts,**/*.tsx"
---

# TypeScript/React コーディング指示

- コンポーネント名はパスカルケース
- useState は必ず型指定

2. プロンプトファイル(prompts)

  • よく使うチャット指示やコード生成テンプレートを Markdown で記述
  • .github/prompts/*.prompt.md に保存

例:

# コード生成プロンプト

このプロジェクトでは、必ず JSDoc コメントを付与してください。

3. カスタムチャットモード

  • チャットの動作範囲や利用ツール・権限を事前に定義し、特定用途に合わせて AI のふるまいを制御できる機能です。

1. 目的

  • 例:フロントエンド開発専用、リサーチ専用、設計レビュー専用など
  • 利用できるツールや編集権限、AI の応答スタイルを制限・指定

2. 設定方法

  • .github/chatmodes 以下に、ファイル名 *.chatmode.md とし、以下のような内容で記述します。
  • * の部分が、チャットモード選択名に利用されます

例:

Design.chatmode.md
---
model: GPT-4.1
tools: ["web-search" ]
description: "外部情報調査用"
---

# 外部情報調査モード

このチャットでは 外部情報を検索して、応答するようにしてください
  • mode でチャットの動作タイプ(ask, edit, agent)を指定
  • tools で利用可能なツールセットを列挙
  • description で用途や制限を記述

3. 使い方

  • .github/prompts/ に上記のような .prompt.md ファイルを作成
  • チャット画面で /ファイル名 で実行、または「Chat: Run Prompt」コマンドで選択
  • モードごとに AI のふるまい・権限が切り替わる

4. 応用例

  • 設計レビュー専用モード(編集不可、コメントのみ)
  • バックエンド API 設計モード(API 定義ファイルのみ編集可能)
  • リサーチモード(外部 Web 検索のみ許可)

利用・運用ポイント

  • 指示ファイルはチャットでの AI 応答・コード生成時に自動反映(インライン補完には未対応)
  • applyTo の glob パターン指定で適用範囲を制御
  • 指示・プロンプトファイルは Markdown 形式で記述し、可読性を意識
  • 設定や指示が競合しないよう注意(優先順位は明示されていない)
  • チャット画面やコマンドパレットから指示・プロンプトファイルの新規作成・編集・実行が可能

フォルダ構成例

.github/
  copilot-instructions.md
  chatmodes/
    Design.chatmode.md
    Research.chatmode.md
    ...
  instructions/
    typescript-react.instructions.md
    backend-python.instructions.md
    ...
  prompts/
    codegen.prompt.md
    review.prompt.md
    ...

Copilot 関連 settings 一覧

  • chat.promptFiles(Experimental): プロンプト・指示ファイルの利用有効化
  • chat.promptFilesLocations(Experimental): プロンプトファイルの検索場所(辞書形式・有効/無効指定)
  • github.copilot.chat.codeGeneration.useInstructionFiles: .github/copilot-instructions.md の指示を利用
  • chat.instructionsFilesLocations(Experimental): 指示ファイルの検索場所(辞書形式・有効/無効指定)
  • github.copilot.chat.reviewSelection.instructions(Preview): 選択範囲レビュー時に追加する指示
  • github.copilot.chat.commitMessageGeneration.instructions(Experimental): コミットメッセージ生成時に追加する指示
  • github.copilot.chat.pullRequestDescriptionGeneration.instructions(Experimental): PR タイトル・説明生成時に追加する指示

settings.json サンプル

{
  // Copilot 指示ファイル・プロンプトファイル関連設定
  "chat.promptFiles": true,
  "chat.promptFilesLocations": {
    ".github/prompts": true,
    "setup/**/prompts": false
  },
  "github.copilot.chat.codeGeneration.useInstructionFiles": true,
  "chat.instructionsFilesLocations": {
    ".github/instructions": true,
    "src/frontend/instructions": false,
    "src/backend/instructions": false
  },

  // 各種タスクごとのカスタム指示
  "github.copilot.chat.reviewSelection.instructions": [
    { "file": "guidance/backend-review-guidelines.md" },
    { "file": "guidance/frontend-review-guidelines.md" }
  ],
  "github.copilot.chat.commitMessageGeneration.instructions": [
    { "text": "コミットメッセージは50文字以内で簡潔に記述してください。" }
  ],
  "github.copilot.chat.pullRequestDescriptionGeneration.instructions": [
    { "text": "必ず主要な変更点リストを含めること。" }
  ],

  // 過去リクエストの編集方法(Experimental)
  // "chat.editRequests": "hover" | "inline" | "none"
  "chat.editRequests": "hover",


  // ターミナル自動承認設定(Experimental)
  "github.copilot.chat.agent.terminal.allowList": {
    "npm run test": true,
    "/^git (status|log)$/": true
  },
  "github.copilot.chat.agent.terminal.denyList": {
    "rm": true,
    "rmdir": true
  }
}

参考: 公式ドキュメント

あとがき

以下、特に便利

  • chat.editRequests: hover
    • 巻き戻しが出来るのがいい
  • allowlist/denylist
    • なにより、自動承認は便利。flutter analysis を毎回承認するの面倒だった :sweat:

あと、以前は、general-coding.instructions.md だったけど、copilot-coding.instructions.md で落ち着くのかな?

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?