AgentSkillsCN

instructions-creator

指导如何创建与更新 VS Code 的自定义指令文件(*.instructions.md 和 copilot-instructions.md)。适用于用户希望创建新指令、更新已有指令、设计指令层级结构,或需要帮助理解 applyTo 模式与指令结构时使用。可通过诸如“创建指令”、“新指令”、“instructions.md”、“copilot-instructions”、“更新指令”、“指令文件”、“编码指南”、“项目规则”、“自定义指令”等短语触发。

SKILL.md
--- frontmatter
name: instructions-creator
description: "Guide for creating and updating VS Code custom instruction files (*.instructions.md and copilot-instructions.md). Use when a user wants to create new instructions, update existing instructions, design instruction hierarchies, or needs help with applyTo patterns and instruction structure. Triggers on: create instructions, new instructions, instructions.md, copilot-instructions, update instructions, instruction file, coding guidelines, project rules, custom instructions."

Instructions Creator

Create effective VS Code custom instruction files that shape AI behavior consistently across chat sessions.

Before Creating Instructions

Fetch Latest Documentation

Before writing or overhauling any instructions file, fetch the latest VS Code custom instructions documentation:

  1. Use fetch_webpage to retrieve: https://code.visualstudio.com/docs/copilot/customization/custom-instructions
  2. Extract current file formats, frontmatter options, and best practices
  3. Apply those patterns throughout the instruction design

If the URL is unreachable, fall back to the embedded format reference below.

Fetch Anthropic Prompt Engineering Best Practices

For instruction content quality, also fetch:

  1. https://platform.claude.com/docs/en/docs/build-with-claude/prompt-engineering/overview
  2. https://platform.claude.com/docs/en/docs/build-with-claude/prompt-engineering/be-clear-and-direct
  3. https://platform.claude.com/docs/en/docs/build-with-claude/prompt-engineering/system-prompts

Extract principles for clear, direct, and effective instructions.


Instruction File Types

Always-On Instructions

Automatically included in every chat request. Two formats:

FileLocationScope
copilot-instructions.md.github/copilot-instructions.mdAll chat requests in workspace
AGENTS.mdWorkspace root (or subfolders)All AI agents in workspace

File-Based Instructions

Applied conditionally based on file patterns or task matching:

FileLocationScope
*.instructions.md.github/instructions/ or configured foldersFiles matching applyTo pattern
*.instructions.mdUser profile prompts/ folderAll workspaces for that user

File Format Reference

Frontmatter (YAML)

yaml
---
name: 'Display Name'           # Optional. Shown in UI. Defaults to filename.
description: 'Short summary'   # Optional. Shown on hover in Chat view.
applyTo: '**/*.py'             # Optional. Glob pattern for auto-application.
---

Frontmatter rules:

  • All three fields are optional
  • Without applyTo, instructions are not applied automatically (manual attachment only)
  • applyTo: '**' applies to all files
  • Glob patterns are relative to workspace root

Common applyTo Patterns

PatternMatches
**All files
**/*.pyAll Python files
**/*.{ts,tsx}All TypeScript files
src/**Everything under src/
**/*.test.{ts,js}All test files
**/api/**All files in any api/ folder
docs/**/*.mdMarkdown files under docs/

Body

Markdown content with the actual instructions. Supports:

  • Standard Markdown formatting
  • Code blocks with examples
  • Markdown links to reference files or URLs
  • Tool references via #tool:<tool-name> syntax

Creation Workflow

Step 1: Determine Instruction Type

ScenarioTypeFile
Project-wide coding standardsAlways-on.github/copilot-instructions.md
Multi-agent workspace conventionsAlways-onAGENTS.md
Language-specific rules (Python, TS...)File-basedpython.instructions.md with applyTo: '**/*.py'
Framework-specific patternsFile-basedreact.instructions.md with applyTo: '**/*.tsx'
Test conventionsFile-basedtesting.instructions.md with applyTo: '**/*.test.*'
Documentation standardsFile-baseddocs.instructions.md with applyTo: '**/*.md'
User-level personal preferencesUser-levelIn profile prompts/ folder

Step 2: Gather Requirements

Clarify with the user:

  1. Scope — Project-wide or file-type-specific?
  2. Purpose — Coding standards, architecture rules, workflow conventions, or domain knowledge?
  3. Audience — Solo developer, team, or organization?
  4. Existing instructions — Check for existing .github/copilot-instructions.md, .instructions.md files, or AGENTS.md
  5. Conflicts — Will these instructions contradict or override existing ones?

Step 3: Draft Instructions

Apply the Writing Principles and structure the content using the Instruction Architecture.

Step 4: Review and Validate

Run through the Quality Checklist before delivering.


Writing Principles

These principles are derived from Anthropic's prompt engineering best practices and adapted for VS Code instruction files.

1. Be Clear, Direct, and Specific

Treat the AI as a skilled new team member with no context on project norms.

PrincipleExample
State concrete rules"Use date-fns instead of moment.js" not "Use modern date libraries"
Include reasoning"Use date-fns — moment.js is deprecated and increases bundle size"
Define ambiguous terms"Component = React functional component with TypeScript props interface"
Set measurable expectations"Functions must not exceed 50 lines" not "Keep functions short"

2. Show, Don't Just Tell

Code examples communicate format, style, and expectations far more effectively than abstract descriptions.

markdown
## Naming conventions

### Preferred
```typescript
// React component files: PascalCase
UserProfile.tsx
OrderHistory.tsx

// Utility functions: camelCase
formatCurrency.ts
parseUserInput.ts

// Constants: UPPER_SNAKE_CASE
const MAX_RETRY_COUNT = 3;
const API_BASE_URL = '/api/v2';

Avoid

typescript
// ❌ No kebab-case for components
user-profile.tsx

// ❌ No abbreviations
fmtCur.ts
code

### 3. Use Positive Instructions

State what TO do, not just what NOT to do. Positive instructions are more effective.

| Instead of | Write |
|------------|-------|
| "Don't use `any` type" | "Use explicit TypeScript types for all parameters and return values" |
| "Don't write long functions" | "Extract functions longer than 30 lines into smaller, named functions" |
| "Don't use console.log" | "Use the project logger (`logger.info()`, `logger.error()`) for all output" |

### 4. Include Reasoning Behind Rules

When instructions explain *why* a convention exists, the AI makes better decisions in edge cases.

```markdown
## Error handling

Wrap all API calls in try-catch blocks with typed error responses.
This ensures the frontend always receives a structured error object
instead of an unhandled 500 response.

5. Focus on Non-Obvious Rules

Skip conventions that standard linters or formatters already enforce. The AI knows standard best practices — provide only project-specific or team-specific knowledge.

markdown
## What to include
- Project-specific architecture decisions
- Team conventions not covered by ESLint/Prettier
- Domain-specific terminology and patterns
- Integration patterns with internal services

## What to skip
- Basic syntax rules (linter handles these)
- Standard formatting (Prettier handles this)
- General language best practices (AI already knows)

6. Keep Instructions Concise

Each instruction file shares the context window with conversation history, other instructions, and the user's request.

  • Target: 50–150 lines per file for file-based instructions
  • Maximum: 300 lines for always-on instructions (.github/copilot-instructions.md)
  • If longer: split into multiple file-based instruction files with specific applyTo patterns

Instruction Architecture

Structure for Always-On Instructions (copilot-instructions.md)

markdown
# Project: [Name]

## Tech Stack
- [Languages, frameworks, key libraries]

## Architecture
- [Key architectural patterns and decisions]

## Coding Conventions
- [Project-specific rules with examples]

## File Structure
- [Important directory conventions]

## Domain Knowledge
- [Business terms, glossary, or domain rules]

## Testing
- [Test conventions and requirements]

Structure for File-Based Instructions

markdown
---
name: '[Descriptive Name]'
description: '[When and why these rules apply]'
applyTo: '[glob pattern]'
---

# [Domain] Standards

## Conventions
- [Rules with code examples]

## Patterns
- [Preferred patterns with examples]

## Anti-Patterns
- [What to avoid and why]

Structure for Domain-Specific Instructions

For complex domains, use a focused approach:

markdown
---
name: 'API Design'
description: 'REST API conventions for backend services'
applyTo: '**/api/**/*.ts'
---

# API Design Standards

## Endpoint Naming
[Convention with examples]

## Request/Response Format
[Schema patterns with code]

## Error Handling
[Standard error structure]

## Authentication
[Auth pattern for this project]

## Versioning
[API versioning approach]

Instruction Hierarchy and Priority

When multiple instruction files exist, VS Code combines them. Higher priority wins on conflicts:

PrioritySourceExample
1 (highest)User-level instructionsPersonal .instructions.md in profile
2Repository instructions.github/copilot-instructions.md, AGENTS.md
3 (lowest)Organization instructionsGitHub org-level instructions

Conflict resolution strategies:

  • Avoid contradictions between instruction files
  • If unavoidable, add explicit override statements: "This rule supersedes any conflicting instruction about X"
  • Use applyTo patterns to scope rules narrowly and prevent overlap

Quality Checklist

Run every instruction file through this checklist:

#CheckQuestion
1ClarityCould a new team member follow every rule without asking questions?
2SpecificityAre vague words ("appropriate", "good", "clean") replaced with measurable criteria?
3ExamplesDoes every non-trivial rule include a concrete code example?
4ReasoningDo rules explain why, not just what?
5ConcisenessIs every line earning its place in the context window?
6Non-obviousAre standard linter/formatter rules excluded?
7PositiveAre instructions stated positively (do X) rather than negatively (don't Y)?
8ScopedIs applyTo set correctly for file-based instructions?
9No conflictsDo these instructions avoid contradicting other instruction files?
10TestableCan compliance with each rule be verified by reading the code?

Anti-Patterns

Anti-PatternProblemFix
Giant monolithic fileContext bloat, buried rulesSplit into scoped .instructions.md files
"Be helpful and write clean code"Too vague, AI already tries to do thisState specific, measurable conventions
Repeating linter rulesWastes context, already enforcedFocus on project-specific rules only
No code examplesRules are ambiguous without examplesAdd preferred/avoid code snippets
Contradicting instructionsAI gets confused, inconsistent outputAudit all files, resolve conflicts
Missing applyToInstructions not auto-appliedAdd appropriate glob pattern
"Don't do X" without alternativeNegative-only rules are weaker"Use Y instead of X because Z"
Mixing scopesBackend rules applied to frontendUse separate files with targeted patterns
Over-constrainingToo many rules cause contradictionsPrioritize the 10-20 most impactful rules
No reasoning behind rulesAI can't handle edge cases wellAdd brief "because..." for each rule

Important Rules

  • Always determine the correct instruction type (always-on vs. file-based) before writing
  • Include code examples for every non-trivial rule — examples communicate more than descriptions
  • State rules positively with reasoning — "Use X because Y" beats "Don't use Z"
  • Respect the context window — challenge every line: "Does the AI need this?"
  • Never duplicate what linters, formatters, or the AI already knows
  • Always set applyTo for file-based instructions to ensure automatic application
  • Audit existing instructions for conflicts before adding new ones
  • Keep individual files under 150 lines; split when approaching this limit