Skip to content

Conditional Instruction Management with GitHub Copilot applyTo Patterns

GitHub Copilot Complete Guide

Target Audience

  • Those who want to use Copilot differently across projects with mixed technology stacks

📍 Position within the Instruction Hierarchy

The applyTo pattern serves as the "Path-specific rules" layer within GitHub Copilot's instruction hierarchy.

LayerFileWhen Applied
Repository-wide.github/copilot-instructions.mdAll requests (always)
Path-specific.instructions.md + applyToWhen path matches (automatic)
Agent Skills.github/skills/*/SKILL.mdWhen agent determines need (on-demand)
AGENTS.mdAGENTS.mdOn agent startup (shared across multi-tool)

Choosing between applyTo and Agent Skills

  • applyTo = Automatic application based on file paths. The right rules take effect without developers needing to think about it
  • Agent Skills = Procedural knowledge loaded on-demand when the agent determines it's needed
  • Example: React component coding conventions -> applyTo; Terraform plan review procedures -> Skills

For a detailed overview, see the Custom Instructions Complete Guide.

Key Points

  • Conditional Instructions

    Automatic rule application based on file extensions and naming patterns

  • Context Optimization

    Focused delivery of only highly relevant information within the 64k token limit

  • Multi-Technology Stack Support

    Optimized development assistance in mixed environments with React/Python/YAML and more

  • Team Workflow Standardization

    Automatic naming conventions and formatting when creating meeting notes, PRs, and specifications

Quick Start (3 Minutes)
// 1. Add to .vscode/settings.json
{
  "chat.instructionsFilesLocations": {
    ".github/instructions/**/*.instructions.md": true
  }
}
// 2. Create .github/instructions/frontend.instructions.md
---
applyTo: "**/*.tsx,**/*.ts"
---

# Frontend Rules
- React Hooks: always specify dependency arrays
- TypeScript strict mode
- Component names: PascalCase

Open a .tsx file and check that the instruction appears in Copilot Chat References.

📖 What Are applyTo Patterns?

If the path matches, it takes effect automatically

GitHub Copilot's applyTo pattern is a feature in custom instruction files that applies instructions only to files matching specific conditions.

While traditional custom instructions apply to all files, using applyTo enables:

  • Dedicated rules by file extension
  • Automatic formatting by naming pattern
  • Optimization of context usage

⚙️ Prerequisites: settings.json Configuration

Important: Will not work without configuration

To use applyTo patterns, you must enable loading of multiple instruction files in VS Code's settings.json.

Required Settings

{
  "chat.instructionsFilesLocations": {
    ".github/instructions/**/*.instructions.md": true
  }
}

Sharing Settings Across the Team

Add the configuration as a project setting in .vscode/settings.json to standardize it across the entire team:

{
  "chat.instructionsFilesLocations": {
    ".github/instructions/**/*.instructions.md": true,
    "docs/instructions/**/*.instructions.md": true
  }
}

🏗️ Basic File Structure

project-root/
├── .github/
│   ├── copilot-instructions.md         # Base rules (always loaded)
│   └── instructions/
│       ├── frontend.instructions.md    # For React/TypeScript
│       ├── backend.instructions.md     # For Python/API
│       ├── meeting.instructions.md     # For meeting notes
│       └── docs.instructions.md        # For documentation
├── .vscode/
│   └── settings.json                   # Project settings
└── docs/
    └── instructions/
        └── style.instructions.md       # For style guide

YAML Frontmatter Properties

The following properties can be used in the YAML Frontmatter at the top of each .instructions.md file.

PropertyRequiredDescription
descriptionRecommendedSummary of the instruction (used by Copilot for loading decisions)
applyToYesGlob pattern(s) for target files (multiple patterns can be separated by commas)
excludeAgent-Exclude application to specific agents

Application Control with excludeAgent

By specifying excludeAgent, you can prevent instructions from being applied to specific agents.

---
description: "テスト実装ガイドライン"
applyTo: "**/*.test.ts,**/*.spec.ts"
excludeAgent: "code-review"
---
excludeAgent ValueExcluded Target
coding-agentGitHub Copilot Coding Agent (automatic Issue processing)
code-reviewCopilot Code Review

Relationship with Agent Mode

excludeAgent does not apply to Agent Mode (the chat agent within VS Code). excludeAgent targets Coding Agent and Code Review, which operate on GitHub.com.

🔧 Practical Implementation Examples

1. Instructions by Technology Stack

For Frontend (React/TypeScript)

---
description: "React/TypeScript専用のコーディング規則"
applyTo: "**/*.tsx,**/*.ts"
---

# React/TypeScript開発ガイドライン

## 基本ルール
- React Hooksの依存配列を必ず適切に設定
- TypeScriptは strict モードで使用
- コンポーネント名はPascalCase
- カスタムHooksは "use" プレフィックス必須

## インポート順序
1. React関連
2. 外部ライブラリ
3. 内部コンポーネント
4. 型定義
5. スタイル

## 命名規則
- コンポーネントファイル: `ComponentName.tsx`
- カスタムHooks: `useFeatureName.ts`
- 型定義: `types/FeatureName.ts`
For Backend (Python/FastAPI)
---
description: "Python/FastAPI専用のコーディング規則"
applyTo: "**/*.py"
---

# Python/FastAPI開発ガイドライン

## 基本ルール
- Type hints必須
- Black フォーマッター使用
- docstringはGoogle形式
- 例外処理は必ず実装

## ファイル構成
- APIエンドポイント: `routers/feature_name.py`
- データモデル: `models/feature_name.py`
- ビジネスロジック: `services/feature_name.py`

## 命名規則
- 関数名: snake_case / クラス名: PascalCase / 定数: UPPER_SNAKE_CASE
For Meeting Notes
---
description: "会議議事録作成時の自動フォーマット"
applyTo: "meeting-*.md,**/meetings/*.md"
---

# 会議議事録作成ガイドライン

## ファイル命名規則
- 形式: `meeting-YYYY-MM-DD-[会議名].md`

## 必須構成
1. **会議情報** - 日時・参加者・会議種別
2. **議題** - 各議題に番号を付与
3. **決定事項** - 何が決定されたか+影響範囲
4. **アクションアイテム** - `[ ] タスク(担当者:@username、期限:YYYY-MM-DD)`
For Pull Requests
---
description: "PR作成時の自動テンプレート適用"
applyTo: "pr-*.md,pull_request_template.md"
---

# プルリクエスト作成ガイドライン

## 必須項目
- 📋 変更内容(新機能/バグ修正/リファクタリング/ドキュメント更新)
- 🔍 テスト(単体/結合/手動/エラーケース)
- 📝 チェックリスト(レビュー依頼/CI通過/ドキュメント更新/影響確認)

## ブランチ命名規則
- feature/機能名 / bugfix/バグ修正内容 / hotfix/緊急修正内容
For Technical Specifications
---
description: "技術仕様書作成時の構成とフォーマット"
applyTo: "**/*-spec.md,**/specs/*.md"
---

# 技術仕様書作成ガイドライン

## 必須構成
1. **概要** - 機能の目的・想定ユーザー・成功基準
2. **技術仕様** - アーキテクチャ図・DB設計・API仕様
3. **実装方針** - 使用技術・設計パターン・セキュリティ考慮
4. **テスト仕様** - 単体/結合テスト範囲・性能要件

💡 Strategy for Combining with Default Loading

Design Philosophy for the Base Configuration

# .github/copilot-instructions.md(基本ルール - 確実読み込み)

## 全体共通ルール
- エラーハンドリング必須
- ログ出力の統一
- セキュリティ原則の遵守

## ファイル作成時の命名規則
- 議事録: `meeting-YYYY-MM-DD-[会議名].md`
- PR: `pr-[機能名]-YYYY-MM-DD.md`
- 仕様書: `[機能名]-spec.md`
- テスト: `[対象].test.[拡張子]`

## 技術スタック別の詳細ルール
フロントエンド: [.github/instructions/frontend.instructions.md]
バックエンド: [.github/instructions/backend.instructions.md]
インフラ: [.github/instructions/infrastructure.instructions.md]

This design achieves the following: - Base rules: Reliably loaded via the default file - Detailed rules: Automatically applied based on conditions via applyTo - Loading reliability: Critical information is always communicated

The window is finite — choose your knowledge wisely

🚀 Benefits of Context Optimization

Loading all instructions:   15,000 tokens
Actually relevant info:      3,000 tokens
Efficiency:                     20%
Loading matched instructions: 4,000 tokens
Actually relevant info:       3,500 tokens
Efficiency:                    87.5%

1. Optimized Token Usage

Traditional approach:
- Loading all instructions: 15,000 tokens
- Actually relevant information: 3,000 tokens
- Efficiency: 20%

applyTo approach:
- Loading only matching instructions: 4,000 tokens
- Actually relevant information: 3,500 tokens
- Efficiency: 87.5%

2. Improved Response Accuracy

Because conditional branching ensures that only highly relevant information is included in Copilot's context:

  • Reduced noise from irrelevant information
  • Suggestions specialized to specific technology stacks
  • More concrete and practical code generation

3. Reduced Cognitive Load

Depending on the file being worked on, developers benefit from: - Appropriate rules being applied automatically - No need to think about "which rules should I follow right now" - Minimal interruption to the development flow

⚠️ Operational Considerations

1. Common Configuration Mistakes

// ❌ Missing extension
"chat.instructionsFilesLocations": {
    ".github/instructions/**/*.md": true
}

// ✅ Correct extension
"chat.instructionsFilesLocations": {
    ".github/instructions/**/*.instructions.md": true
}

2. Mistakes in applyTo Pattern Syntax

# ❌ Incorrect syntax
applyTo: "*.tsx"

# ✅ Correct syntax
applyTo: "**/*.tsx"

3. Over-Segmentation Leading to Management Complexity

❌ Structure to avoid:
├── instructions/
│   ├── react-hooks.instructions.md
│   ├── react-context.instructions.md
│   ├── react-components.instructions.md
│   └── react-routing.instructions.md

✅ Recommended structure:
├── instructions/
│   ├── frontend.instructions.md
│   ├── backend.instructions.md
│   └── docs.instructions.md

🔍 How to Measure Effectiveness

1. Reference Verification

Check the "References" shown in Copilot Chat responses to verify: - Whether the appropriate instruction files are being referenced - Whether unnecessary files are being loaded

2. Response Quality Assessment

Periodically verify the following: - Whether code generation matches expectations - Whether technology stack-specific suggestions are included - Whether naming conventions are being applied correctly

3. Team Feedback

Survey developers on their experience: - Perceived improvement in development efficiency - Appropriateness of suggestions - Ease of configuration

❓ Frequently Asked Questions (FAQ)

Q: Can I specify multiple extensions in an applyTo pattern?

Yes. You can specify multiple patterns separated by commas. Example: applyTo: "**/*.tsx,**/*.ts,**/*.jsx". Each pattern is evaluated as an OR condition.

Q: Can applyTo be used alongside copilot-instructions.md?

Yes. copilot-instructions.md serves as the always-applied base rules, while applyTo provides conditional detailed rules. Both sets of instructions are included in the context.

Q: What should I check if applyTo is not working?
  1. Verify that chat.instructionsFilesLocations is correctly configured in settings.json
  2. Verify that the file extension is .instructions.md (.md alone will not work)
  3. Verify that the glob pattern uses recursive specification like **/*.tsx (*.tsx only matches files in the root directory)

🎯 Summary

The applyTo pattern is a powerful feature that enables improved efficiency and accuracy in GitHub Copilot custom instructions.

Key Takeaways

  1. settings.json configuration is a prerequisite
  2. Combining with default loading ensures reliability
  3. Context optimization makes effective use of the 64k token limit
  4. Optimized development assistance in mixed technology stack environments

With proper design and operation, you can achieve conditional knowledge management that was not possible with traditional custom instructions, simultaneously improving both development efficiency and quality in team development.