К основному содержанию
правило официальный · GitHub

instructions — правило для GitHub Copilot: что делает и как установить

Свод правил и структура для создания качественных файлов инструкций Copilot с привязкой по glob-маскам.

Установить в GitHub Copilot · Вручную: положить файлы Все способы и платформы ↓
.github/instructions/instructions.instructions.md
Открыть на GitHub

Что делает instructions

Правило задаёт стандарт оформления файлов инструкций для GitHub Copilot в каталоге .github/instructions/. Оно действует на файлы с расширением .instructions.md. Каждый документ обязан содержать блок YAML frontmatter. В нём прописывают описание длиной от 1 до 500 символов и шаблон applyTo для фильтрации целевых файлов кодовой базы.

Внутри описана чёткая структура: вводная часть, базовые соглашения, безопасность и контрастные блоки Good Example против Bad Example. Текст требует писать краткими глаголами в повелительном наклонении. Без корректной маски applyTo ассистент просто не сможет привязать правила к нужным файлам репозитория.

Какие задачи решает

  • стандартизировать структуру файлов .instructions.md
  • проверить обязательные поля YAML frontmatter
  • привязать контекстные правила к коду через маски applyTo
  • оформить контрастные примеры хорошего и плохого кода

Примеры запросов агенту

  • Создай инструкцию для TypeScript по шаблону в .github/instructions/
  • Проверь файл react-best-practices.instructions.md на соответствие структуре
  • Добавь в документ блок YAML frontmatter с маской applyTo

Как установить instructions

Вручную: положить файлы

.github/instructions/instructions.instructions.md

Поле applyTo задаёт, к каким файлам применять

По шагам, с командами для каждой платформы: AGENTS.md и CLAUDE.md: что это, кто читает и какой выбрать

Вопросы о instructions

Как установить instructions в GitHub Copilot?

Создайте в проекте файл .github/instructions/instructions.instructions.md и скопируйте в него текст правила.

Что делает правило instructions?

Оно определяет шаблон оформления проектных инструкций Copilot, включая требования к frontmatter, структуре секций и формулировкам.

Какие поля обязательны в YAML frontmatter?

Необходимы два параметра: description в одинарных кавычках объёмом до 500 символов и маска applyTo для выбора целевых файлов.

Исходный текст

instructions.instructions.md · MIT
---
description: 'Guidelines for creating high-quality custom instruction files for GitHub Copilot'
applyTo: '**/*.instructions.md'
---

# Custom Instructions File Guidelines

Instructions for creating effective and maintainable custom instruction files that guide GitHub Copilot in generating domain-specific code and following project conventions.

## Project Context

- Target audience: Developers and GitHub Copilot working with domain-specific code
- File format: Markdown with YAML frontmatter
- File naming convention: lowercase with hyphens (e.g., `react-best-practices.instructions.md`)
- Location: `.github/instructions/` directory
- Purpose: Provide context-aware guidance for code generation, review, and documentation

## Required Frontmatter

Every instruction file must include YAML frontmatter with the following fields:

```yaml
---
description: 'Brief description of the instruction purpose and scope'
applyTo: 'glob pattern for target files (e.g., **/*.ts, **/*.py)'
---
```

### Frontmatter Guidelines

- **description**: Single-quoted string, 1-500 characters, clearly stating the purpose
- **applyTo**: Glob pattern(s) specifying which files these instructions apply to
  - Single pattern: `'**/*.ts'`
  - Multiple patterns: `'**/*.ts, **/*.tsx, **/*.js'`
  - Specific files: `'src/**/*.py'`
  - All files: `'**'`

## File Structure

A well-structured instruction file should include the following sections:

### 1. Title and Overview

- Clear, descriptive title using `#` heading
- Brief introduction explaining the purpose and scope
- Optional: Project context section with key technologies and versions

### 2. Core Sections

Organize content into logical sections based on the domain:

- **General Instructions**: High-level guidelines and principles
- **Best Practices**: Recommended patterns and approaches
- **Code Standards**: Naming conventions, formatting, style rules
- **Architecture/Structure**: Project organization and design patterns
- **Common Patterns**: Frequently used implementations
- **Security**: Security considerations (if applicable)
- **Performance**: Optimization guidelines (if applicable)
- **Testing**: Testing standards and approaches (if applicable)

### 3. Examples and Code Snippets

Provide concrete examples with clear labels:

```markdown
### Good Example
\`\`\`language
// Recommended approach
code example here
\`\`\`

### Bad Example
\`\`\`language
// Avoid this pattern
code example here
\`\`\`
```

### 4. Validation and Verification (Optional but Recommended)

- Build commands to verify code
- Linting and formatting tools
- Testing requirements
- Verification steps

## Content Guidelines

### Writing Style

- Use clear, concise language
- Write in imperative mood ("Use", "Implement", "Avoid")
- Be specific and actionable
- Avoid ambiguous terms like "should", "might", "possibly"
- Use bullet points and lists for readability
- Keep sections focused and scannable

### Best Practices

- **Be Specific**: Provide concrete examples rather than abstract concepts
- **Show Why**: Explain the reasoning behind recommendations when it adds value
- **Use Tables**: For comparing options, listing rules, or showing patterns
- **Include Examples**: Real code snippets are more effective than descriptions
- **Stay Current**: Reference current versions and best practices
- **Link Resources**: Include official documentation and authoritative sources

### Instruction Altitude (Goldilocks Zone)

- Start with the minimum rule set that fully defines expected outcomes
- Add constraints after observed failures, not hypothetical edge cases
- Prefer high-signal examples over exhaustive decision tables

| Altitude | Failure Mode | Result |
| --- | --- | --- |
| Over-specified | Brittle if-else prose | Breaks on unlisted cases |
| Under-specified | Assumes shared context | Generic outputs |
| Right altitude | Heuristics + examples | Stable, generalizable quality |

### Common Patterns to Include

1. **Naming Conventions**: How to name variables, functions, classes, files
2. **Code Organization**: File structure, module organization, import order
3. **Error Handling**: Preferred error handling patterns
4. **Dependencies**: How to manage and document dependencies
5. **Comments and Documentation**: When and how to document code
6. **Version Information**: Target language/framework versions

## Patterns to Follow

### Bullet Points and Lists

```markdown
## Security Best Practices

- Always validate user input before processing
- Use parameterized queries to prevent SQL injection
- Store secrets in environment variables, never in code
- Implement proper authentication and authorization
- Enable HTTPS for all production endpoints
```

### Tables for Structured Information

```markdown
## Common Issues

| Issue            | Solution            | Example                       |
| ---------------- | ------------------- | ----------------------------- |
| Magic numbers    | Use named constants | `const MAX_RETRIES = 3`       |
| Deep nesting     | Extract functions   | Refactor nested if statements |
| Hardcoded values | Use configuration   | Store API URLs in config      |
```

### Code Comparison

```markdown
### Good Example - Using TypeScript interfaces
\`\`\`typescript
interface User {
  id: string;
  name: string;
  email: string;
}

function getUser(id: string): User {
  // Implementation
}
\`\`\`

### Bad Example - Using any type
\`\`\`typescript
function getUser(id: any): any {
  // Loses type safety
}
\`\`\`
```

### Conditional Guidance

```markdown
## Framework Selection

- **For small projects**: Use Minimal API approach
- **For large projects**: Use controller-based architecture with clear separation
- **For microservices**: Consider domain-driven design patterns
```

## Patterns to Avoid

- **Overly verbose explanations**: Keep it concise and scannable
- **Outdated information**: Always reference current versions and practices
- **Ambiguous guidelines**: Be specific about what to do or avoid
- **Missing examples**: Abstract rules without concrete code examples
- **Contradictory advice**: Ensure consistency throughout the file
- **Copy-paste from documentation**: Add value by distilling and contextualizing
- **Hypothetical-rule inflation**: Do not add rules for failures that have not occurred

## Testing Your Instructions

Before finalizing instruction files:

1. **Test with Copilot**: Try the instructions with actual prompts in VS Code
2. **Verify Examples**: Ensure code examples are correct and run without errors
3. **Check Glob Patterns**: Confirm `applyTo` patterns match intended files

## Example Structure

Here's a minimal example structure for a new instruction file:

```markdown
---
description: 'Brief description of purpose'
applyTo: '**/*.ext'
---

# Technology Name Development

Brief introduction and context.

## General Instructions

- High-level guideline 1
- High-level guideline 2

## Best Practices

- Specific practice 1
- Specific practice 2

## Code Standards

### Naming Conventions
- Rule 1
- Rule 2

### File Organization
- Structure 1
- Structure 2

## Common Patterns

### Pattern 1
Description and example

\`\`\`language
code example
\`\`\`

### Pattern 2
Description and example

## Validation

- Build command: `command to verify`
- Linting: `command to lint`
- Testing: `command to test`
```

## Maintenance

- Review instructions when dependencies or frameworks are updated
- Update examples to reflect current best practices
- Remove outdated patterns or deprecated features
- Add new patterns as they emerge in the community
- Keep glob patterns accurate as project structure evolves

## Additional Resources

- [Custom Instructions Documentation](https://code.visualstudio.com/docs/copilot/customization/custom-instructions)
- [Awesome Copilot Instructions](https://github.com/github/awesome-copilot/tree/main/instructions)
- [System Prompt Altitude — Effective Context Engineering for AI Agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents#the-anatomy-of-effective-context)

© github · MIT · github/awesome-copilot

Похожие правила IDE

Все правила IDE по теме «Настройка агента: память, контекст, субагенты» →

Из того же набора770

Весь набор →
joyride-user-project Правило помогает разрабатывать проекты Joyride на ClojureScript через REPL и автоматизировать VS Code. Оно пригодится, когда нужно проверить код в среде VS Code до правок файлов. ★ 40 418звёзд репо java-upgrade Правило подсказывает Copilot подключить скилл java-upgrade, когда вы меняете версию Java в Maven или Gradle. Пригодится при переходе между LTS. ★ 40 418звёзд репо java-mcp-server Набор инструкций для разработки MCP-серверов на Java с официальным MCP Java SDK 2.x. Помогает настроить сборку, транспорт и регистрацию инструментов. ★ 40 418звёзд репо intellij-java-kotlin Правило задаёт Copilot рамки работы с Java и Kotlin в IntelliJ IDEA: сборка через Gradle или Maven, аккуратные правки и проверка теми же командами, что в CI. ★ 40 418звёзд репо html-css-style-color-guide Правило задаёт ограничения и рекомендации для цветового оформления HTML и CSS. Помогает выбирать фоны, текстовые цвета и градиенты с учётом контраста. ★ 40 418звёзд репо go Задаёт стандарты написания идиоматичного Go-кода по гайдам Effective Go и Google. Помогает GitHub Copilot соблюдать структуру пакетов и чистоту синтаксиса. ★ 40 418звёзд репо github-actions-ci-cd-best-practices Правило для GitHub Copilot: подсказывает структуру workflow, работу с секретами, кэшем и матрицами при правке файлов в .github/workflows/. ★ 40 418звёзд репо gilfoyle-code-review Инструкция превращает GitHub Copilot в саркастичного системного архитектора Гилфойла из «Кремниевой долины». Помогает разобрать огрехи в архитектуре, алгоритмах и безопасности без похвалы. ★ 40 418звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой