2025年8月31日日曜日

Custom Instructions in Copilot Chat (VS Code)

 

Custom instructions allow you to define reusable guidelines that automatically shape Copilot Chat’s responses — ensuring consistency, quality, and alignment with your project or team standards.


📝 Instruction File Types

File TypePurposeApplies To
.github/copilot-instructions.mdWorkspace-wide defaultsAll chat prompts in the workspace
*.instructions.mdTask/file-specificBased on applyTo glob pattern

✅ How to Enable & Use

  1. Enable setting
    In settings.json:

    "github.copilot.chat.codeGeneration.useInstructionFiles": true
  2. Create instructions file
    Options:

    • From Chat View → Configure Chat > Instructions > New instruction file

    • Or run: Chat: New Instructions File from Command Palette

  3. Specify scope using frontmatter

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

📂 Where to Store Instructions

LocationNotes
.github/Workspace instructions (version-controlled)
VS Code User ProfileReusable across projects
settings.jsonDirect config for specialized tasks

✍️ Instruction File Format

--- applyTo: "**/*.py" description: Python coding standards --- # Python Guidelines - Follow PEP 8 style. - Prioritize readability. - Add type hints.
  • Use Markdown for formatting

  • Link to other instructions: [see shared rules](./general-coding.instructions.md)


✨ Use Cases & Examples

✅ General Guidelines

--- applyTo: "**" --- # Naming - camelCase for vars/functions - PascalCase for components # Error Handling - Use try/catch for async

✅ TypeScript + React

--- applyTo: "**/*.ts,**/*.tsx" --- # React/TS Rules - Use React.FC - Prefer functional components - Apply [general guidelines](./general-coding.instructions.md)

✅ Docs Writing

--- applyTo: "docs/**/*.md" --- # Docs Style - Use active voice - Present tense only - Include code blocks when helpful

🛠 Settings-based Instructions

In settings.json:

{ "github.copilot.chat.pullRequestDescriptionGeneration.instructions": [ { "text": "Always include a list of key changes." } ], "github.copilot.chat.reviewSelection.instructions": [ { "file": "guidance/frontend-review-guidelines.md" } ] }

⚡ Generate Instructions Automatically

  1. Open Chat View

  2. Configure Chat > Generate Instructions

  3. Edit the generated .github/copilot-instructions.md


🔁 Sync Across Devices

  • Enable Settings Sync in VS Code

  • From Command Palette: Settings Sync: Configure

  • Enable sync for Prompts and Instructions


💡 Best Practices

  • 🧱 Keep each rule simple and atomic

  • 🔄 Reuse and reference other instructions using links

  • 📁 Use applyTo to scope rules to file types or folders

  • 👥 Store in workspace to share with teams via Git

  • 📚 Split files by language, task, or framework

0 件のコメント:

コメントを投稿