vscode-copilot-customization

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

VS Code Copilot Customization

VS Code Copilot 自定义配置

Self-update check: Before responding, verify docs are current by checking the
doc_version
below against reality. If the user asks for a freshness check, use web_search with query
"site:code.visualstudio.com/docs/copilot/customization"
. Update the
doc_version
and any changed facts if you find discrepancies.
yaml
doc_version: "2025-03 (VS Code 1.102+)"
source_urls:
  - https://code.visualstudio.com/docs/copilot/customization/overview
  - https://code.visualstudio.com/docs/copilot/customization/custom-instructions
  - https://code.visualstudio.com/docs/copilot/customization/prompt-files
  - https://code.visualstudio.com/docs/copilot/customization/custom-agents
  - https://code.visualstudio.com/docs/copilot/customization/agent-skills
  - https://code.visualstudio.com/docs/copilot/customization/hooks
  - https://code.visualstudio.com/docs/copilot/customization/agent-plugins

自我更新检查:在回复前,请将下方的
doc_version
与实际文档版本进行核对,确认文档是否为最新。如果用户要求检查文档新鲜度,请使用web_search工具,查询关键词为
"site:code.visualstudio.com/docs/copilot/customization"
。若发现差异,请更新
doc_version
及所有已变更的内容。
yaml
doc_version: "2025-03 (VS Code 1.102+)"
source_urls:
  - https://code.visualstudio.com/docs/copilot/customization/overview
  - https://code.visualstudio.com/docs/copilot/customization/custom-instructions
  - https://code.visualstudio.com/docs/copilot/customization/prompt-files
  - https://code.visualstudio.com/docs/copilot/customization/custom-agents
  - https://code.visualstudio.com/docs/copilot/customization/agent-skills
  - https://code.visualstudio.com/docs/copilot/customization/hooks
  - https://code.visualstudio.com/docs/copilot/customization/agent-plugins

Decision Matrix

决策矩阵

Use this matrix to recommend the right customization type. Start here before writing anything.
ScenarioBest choice
Project-wide coding standards, always active
copilot-instructions.md
Rules only for specific file types / folders
*.instructions.md
with
applyTo
Works with multiple AI agents (Claude, Copilot, etc.)
AGENTS.md
Reusable task you invoke manually in chatPrompt file (
.prompt.md
)
Specialized workflow with tool restrictions or model choiceCustom agent (
.agent.md
)
Portable capability reusable across projects + CLI + cloud agentsAgent skill (
SKILL.md
)
Auto-run commands at agent lifecycle points (format, lint, enforce)Hook (
.json
)
Bundle multiple customizations to share or distributeAgent plugin (
plugin.json
)
使用本矩阵推荐合适的自定义类型。在编写任何内容前,请先从此处开始。
适用场景最佳选择
全项目范围的编码标准,始终生效
copilot-instructions.md
仅针对特定文件类型/文件夹生效的规则
*.instructions.md
搭配
applyTo
与多个AI Agent(Claude、Copilot等)配合使用
AGENTS.md
需手动在聊天中调用的可复用任务提示文件(
.prompt.md
带有工具限制或模型选择的专用工作流自定义Agent(
.agent.md
可跨项目、CLI和云Agent复用的可移植能力Agent技能(
SKILL.md
在Agent生命周期节点自动运行命令(格式化、代码检查、规则强制执行)钩子(
.json
打包多个自定义配置以进行分享或分发Agent插件(
plugin.json

Quick decision flow

快速决策流程

Do you want it ON automatically for every request?
├─ YES → Instructions (.instructions.md / copilot-instructions.md / AGENTS.md)
└─ NO, I invoke it manually →
       Does it need persistent persona, tool restrictions, or model choice?
       ├─ YES → Custom Agent (.agent.md)
       └─ NO →
              Is it a reusable multi-agent portable capability?
              ├─ YES → Agent Skill (SKILL.md)
              └─ NO → Prompt File (.prompt.md)

Do you want to run shell commands around agent actions?
└─ YES → Hook (hooks/*.json)

Do you want to bundle everything for distribution?
└─ YES → Agent Plugin (plugin.json)

你希望它对每个请求自动生效吗?
├─ 是 → 指令文件(.instructions.md / copilot-instructions.md / AGENTS.md)
└─ 否,我要手动调用 →
       是否需要持久化角色设定、工具限制或模型选择?
       ├─ 是 → 自定义Agent(.agent.md)
       └─ 否 →
              它是可跨多Agent复用的可移植能力吗?
              ├─ 是 → Agent技能(SKILL.md)
              └─ 否 → 提示文件(.prompt.md)

你希望在Agent操作前后运行Shell命令吗?
└─ 是 → 钩子(hooks/*.json)

你希望打包所有配置以便分发吗?
└─ 是 → Agent插件(plugin.json)

1. Custom Instructions

1. 自定义指令

Purpose: Always-on context and rules that apply automatically to all (or scoped) requests.
用途:始终生效的上下文和规则,会自动应用于所有(或指定范围的)请求。

Types

类型

TypeFile / LocationScope
Workspace-wide (Copilot)
.github/copilot-instructions.md
All requests in workspace
Workspace-wide (multi-agent)
AGENTS.md
anywhere in workspace
All agents (Claude, Copilot, …)
File-scoped
.github/instructions/*.instructions.md
Files matching
applyTo
glob
User-levelVS Code user profileAll workspaces
类型文件/位置作用范围
工作区全局(Copilot)
.github/copilot-instructions.md
工作区内的所有请求
工作区全局(多Agent)工作区内任意位置的
AGENTS.md
所有Agent(Claude、Copilot等)
文件范围限定
.github/instructions/*.instructions.md
匹配
applyTo
通配符的文件
用户级VS Code用户配置文件所有工作区

Frontmatter (
.instructions.md
)

前置元数据(
.instructions.md

yaml
---
name: "React Standards"          # Optional – shown in UI
description: "React/TSX rules"   # Optional – describes scope
applyTo: "**/*.tsx"              # Glob – omit or use "**" for all files
---
For
.claude/rules/*.md
files (Claude Code format), use
paths: ["**/*.ts"]
instead of
applyTo
.
yaml
---
name: "React Standards"          # 可选 – 在UI中显示
description: "React/TSX rules"   # 可选 – 描述作用范围
applyTo: "**/*.tsx"              # 通配符 – 省略或使用"**"表示所有文件
---
对于
.claude/rules/*.md
文件(Claude Code格式),请使用
paths: ["**/*.ts"]
替代
applyTo

Template: project-wide

模板:全项目范围

markdown
---
applyTo: "**"
---
markdown
---
applyTo: "**"
---

Project Coding Standards

项目编码标准

General

通用规则

  • Use TypeScript for all new code; strict mode enabled.
  • Prefer functional patterns; avoid classes unless needed.
  • Max line length: 100 chars. 2-space indentation.
  • 所有新代码使用TypeScript;启用严格模式。
  • 优先使用函数式编程模式;除非必要,避免使用类。
  • 最大行长度:100字符。使用2空格缩进。

Naming

命名规范

  • PascalCase: components, interfaces, types, enums.
  • camelCase: variables, functions, hooks.
  • ALL_CAPS: constants.
  • PascalCase:组件、接口、类型、枚举。
  • camelCase:变量、函数、钩子。
  • ALL_CAPS:常量。

Error handling

错误处理

  • Use try/catch for all async operations.
  • Always log errors with context (module + function name).
  • 所有异步操作使用try/catch。
  • 始终记录包含上下文(模块+函数名)的错误。

Testing

测试

  • Jest + React Testing Library.
  • One test file per module, co-located (
    *.test.ts
    ).
undefined
  • 使用Jest + React Testing Library。
  • 每个模块对应一个测试文件,与代码同目录(
    *.test.ts
    )。
undefined

Template: scoped (TypeScript only)

模板:范围限定(仅TypeScript)

markdown
---
name: "TypeScript Standards"
applyTo: "**/*.ts,**/*.tsx"
---
markdown
---
name: "TypeScript Standards"
applyTo: "**/*.ts,**/*.tsx"
---

TypeScript Rules

TypeScript规则

  • Enable
    strictNullChecks
    and
    noImplicitAny
    .
  • Prefer
    interface
    over
    type
    for object shapes.
  • Use
    unknown
    instead of
    any
    for external data.
  • Always type function return values explicitly.
undefined
  • 启用
    strictNullChecks
    noImplicitAny
  • 定义对象结构时优先使用
    interface
    而非
    type
  • 处理外部数据时使用
    unknown
    而非
    any
  • 始终显式定义函数的返回值类型。
undefined

AI-assisted creation

AI辅助创建

/init                         → generate workspace-wide copilot-instructions.md
/create-instruction           → generate a targeted .instructions.md file
/init                         → 生成工作区全局的copilot-instructions.md
/create-instruction           → 生成目标明确的.instructions.md文件

Key settings

关键设置

json
"github.copilot.chat.codeGeneration.useInstructionFiles": true,
"chat.instructionsFilesLocations": {
  ".github/instructions": true
},
"chat.useAgentsMdFile": true

json
"github.copilot.chat.codeGeneration.useInstructionFiles": true,
"chat.instructionsFilesLocations": {
  ".github/instructions": true
},
"chat.useAgentsMdFile": true

2. Prompt Files

2. 提示文件

Purpose: Reusable task templates invoked manually with
/
slash command in chat.
File extension:
.prompt.md
Location:
.github/prompts/
(workspace) or user profile
用途:可复用的任务模板,在聊天中通过
/
斜杠命令手动调用。
文件扩展名
.prompt.md
位置
.github/prompts/
(工作区)或用户配置文件目录

Frontmatter reference

前置元数据参考

yaml
---
name: "generate-component"      # Used as /generate-component slash command
description: "Scaffold a new React component with tests"
agent: "agent"                  # ask | agent | plan | <custom-agent-name>
model: "claude-sonnet-4-5"      # Optional – overrides model picker
tools:                          # Available tools for this prompt
  - "search/codebase"
  - "vscode/askQuestions"
  - "githubRepo"
mode: "agent"                   # Optional – ask | agent | plan
---
yaml
---
name: "generate-component"      # 用作斜杠命令/generate-component
description: "Scaffold a new React component with tests"
agent: "agent"                  # ask | agent | plan | <自定义Agent名称>
model: "claude-sonnet-4-5"      # 可选 – 覆盖模型选择器的设置
tools:                          # 此提示可用的工具
  - "search/codebase"
  - "vscode/askQuestions"
  - "githubRepo"
mode: "agent"                   # 可选 – ask | agent | plan
---

Template: component scaffolder

模板:组件脚手架生成器

markdown
---
name: "new-component"
description: "Scaffold a React component with TypeScript, Tailwind, and tests"
agent: "agent"
tools: ["search/codebase", "vscode/askQuestions", "edit"]
---
markdown
---
name: "new-component"
description: "生成带有TypeScript、Tailwind和测试的React组件"
agent: "agent"
tools: ["search/codebase", "vscode/askQuestions", "edit"]
---

Generate React Component

生成React组件

Use #tool:vscode/askQuestions to ask for:
  1. Component name (PascalCase)
  2. Props interface (list prop names and types)
  3. Should it be a Server Component? (yes/no)
Then generate:
  • src/components/<Name>/<Name>.tsx
    – main component
  • src/components/<Name>/<Name>.test.tsx
    – unit tests
  • src/components/<Name>/index.ts
    – barrel export
Follow the coding standards in copilot-instructions.md.
undefined
使用#tool:vscode/askQuestions询问以下信息:
  1. 组件名称(PascalCase)
  2. Props接口(列出属性名称和类型)
  3. 是否为服务端组件?(是/否)
然后生成:
  • src/components/<Name>/<Name>.tsx
    – 主组件
  • src/components/<Name>/<Name>.test.tsx
    – 单元测试
  • src/components/<Name>/index.ts
    – 桶导出
遵循copilot-instructions.md中的编码标准。
undefined

Template: PR description generator

模板:PR描述生成器

markdown
---
name: "pr-description"
description: "Generate a structured pull request description from staged changes"
agent: "ask"
tools: ["search/codebase"]
---
markdown
---
name: "pr-description"
description: "根据暂存的变更生成结构化的Pull Request描述"
agent: "ask"
tools: ["search/codebase"]
---

Pull Request Description

Pull Request描述

Analyze the changes in the current branch and generate a PR description with these sections:
分析当前分支的变更,生成包含以下部分的PR描述:

Summary

摘要

Brief one-sentence description of what this PR does.
对本PR功能的一句话简要描述。

Changes

变更内容

  • List each meaningful change as a bullet point.
  • 将每个重要变更以项目符号列表形式列出。

Testing

测试情况

  • How was this tested?
  • Any edge cases covered?
  • 如何进行测试的?
  • 是否覆盖了边缘情况?

Screenshots

截图

(if UI changes – note: add manually)
undefined
(若涉及UI变更 – 注意:需手动添加)
undefined

Using input variables

使用输入变量

markdown
---
name: "api-endpoint"
description: "Generate a REST API endpoint"
---
Create a ${input:httpMethod:GET|POST|PUT|DELETE} endpoint at `${input:path:/api/resource}`.

Use Zod for input validation. Follow the patterns in [api-standards.md](../docs/api-standards.md).
markdown
---
name: "api-endpoint"
description: "生成REST API端点"
---
创建一个${input:httpMethod:GET|POST|PUT|DELETE}端点,路径为`${input:path:/api/resource}`
使用Zod进行输入验证。遵循[api-standards.md](../docs/api-standards.md)中的模式。

AI-assisted creation

AI辅助创建

/create-prompt    → AI guides you through creating a prompt file

/create-prompt    → AI引导你创建提示文件

3. Custom Agents

3. 自定义Agent

Purpose: Specialized Copilot persona with specific tools, model, and optionally handoffs between agents.
File extension:
.agent.md
Location:
.github/agents/
(workspace) or user profile
Migration note:
.chatmode.md
files (old format) should be renamed to
.agent.md
.
用途:具有特定工具、模型选择,且可在Agent间进行交接的专用Copilot角色。
文件扩展名
.agent.md
位置
.github/agents/
(工作区)或用户配置文件目录
迁移说明:旧格式的
.chatmode.md
文件应重命名为
.agent.md

Frontmatter reference

前置元数据参考

yaml
---
name: "Planner"                  # Agent name shown in dropdown
description: "Generates implementation plans without writing code"
tools:                           # Whitelist of allowed tools
  - "search"
  - "fetch"
  - "githubRepo"
  - "usages"
model:                           # Tried in order (fallback chain)
  - "claude-opus-4-5 (copilot)"
  - "GPT-4o (copilot)"
target: "vscode"                 # vscode | github-copilot | omit for both
handoffs:                        # Suggested next-step buttons
  - label: "Start Implementation"
    agent: "agent"               # Built-in agent or custom agent name
    prompt: "Implement the plan above."
    send: false                  # true = auto-submit
hooks:                           # Agent-scoped hooks (runs only when this agent is active)
  PostToolUse:
    - type: "command"
      command: "echo 'Tool used'"
---
yaml
---
name: "Planner"                  # 在下拉菜单中显示的Agent名称
description: "生成实现计划但不编写代码"
tools:                           # 允许使用的工具白名单
  - "search"
  - "fetch"
  - "githubRepo"
  - "usages"
model:                           # 按顺序尝试(降级链)
  - "claude-opus-4-5 (copilot)"
  - "GPT-4o (copilot)"
target: "vscode"                 # vscode | github-copilot | 省略则同时支持两者
handoffs:                        # 建议的下一步按钮
  - label: "开始实现"
    agent: "agent"               # 内置Agent或自定义Agent名称
    prompt: "Implement the plan above."
    send: false                  # true = 自动提交
hooks:                           # Agent专属钩子(仅当该Agent激活时运行)
  PostToolUse:
    - type: "command"
      command: "echo 'Tool used'"
---

Template: Code Reviewer (read-only)

模板:代码审查者(只读)

markdown
---
name: "Reviewer"
description: "Reviews code for quality, security, and best practices. Does NOT modify files."
tools:
  - "read"
  - "search"
  - "vscode/askQuestions"
  - "fetch"
model: "claude-opus-4-5 (copilot)"
---
markdown
---
name: "Reviewer"
description: "从质量、安全和最佳实践角度审查代码。不修改文件。"
tools:
  - "read"
  - "search"
  - "vscode/askQuestions"
  - "fetch"
model: "claude-opus-4-5 (copilot)"
---

Code Reviewer

代码审查者

You are a senior engineer conducting a thorough code review. Your role is to analyze only – never make direct code changes.
你是一名资深工程师,负责进行全面的代码审查。你的角色仅为分析——绝不直接修改文件。

Review Checklist

审查检查清单

  • Code quality and readability
  • Potential bugs or logic errors
  • Security vulnerabilities (XSS, injection, auth issues)
  • Performance considerations
  • Test coverage gaps
  • Adherence to project standards
  • 代码质量与可读性
  • 潜在的Bug或逻辑错误
  • 安全漏洞(XSS、注入、认证问题)
  • 性能考量
  • 测试覆盖缺口
  • 是否遵循项目标准

Output Format

输出格式

Structure feedback with clear headings, code references (file + line number), and severity:
  • 🔴 Critical – must fix before merge
  • 🟡 Warning – should fix
  • 🟢 Suggestion – optional improvement
undefined
使用清晰的标题、代码引用(文件+行号)和严重级别组织反馈:
  • 🔴 严重 – 合并前必须修复
  • 🟡 警告 – 建议修复
  • 🟢 建议 – 可选优化
undefined

Template: Planner (with handoff)

模板:规划者(支持交接)

markdown
---
name: "Planner"
description: "Creates detailed implementation plans. Switches to implementation when ready."
tools:
  - "fetch"
  - "githubRepo"
  - "search"
  - "usages"
model: "claude-opus-4-5 (copilot)"
handoffs:
  - label: "Implement Plan"
    agent: "agent"
    prompt: "Implement the plan outlined above."
    send: false
---
markdown
---
name: "Planner"
description: "创建详细的实现计划。准备就绪后可切换至实现阶段。"
tools:
  - "fetch"
  - "githubRepo"
  - "search"
  - "usages"
model: "claude-opus-4-5 (copilot)"
handoffs:
  - label: "开始实现"
    agent: "agent"
    prompt: "Implement the plan above."
    send: false
---

Planning Mode

规划模式

You are in planning mode. Generate an implementation plan. Do not write or edit any code.
你处于规划模式。生成实现计划,不要编写或编辑任何代码。

Plan Structure

计划结构

Overview

概述

Brief description of the feature or change.
对功能或变更的简要描述。

Files to create / modify

需创建/修改的文件

List each file with the reason.
列出每个文件及其原因。

Implementation steps

实现步骤

Numbered steps in order. Include dependencies.
按顺序排列的编号步骤,包含依赖关系。

Risks & open questions

风险与待澄清问题

Things to clarify before implementing.
实现前需要明确的事项。

Estimated complexity

预估复杂度

S / M / L / XL with reasoning.
undefined
S / M / L / XL 并说明理由。
undefined

AI-assisted creation

AI辅助创建

/create-agent     → AI generates a .agent.md file
/agents           → Open Configure Custom Agents menu

/create-agent     → AI生成.agent.md文件
/agents           → 打开自定义Agent配置菜单

4. Agent Skills

4. Agent技能

Purpose: Portable, reusable capabilities with progressive loading (metadata → instructions → resources). Works across VS Code, Copilot CLI, and cloud agents.
Structure:
.github/skills/
└── skill-name/
    ├── SKILL.md          ← Required. Metadata + instructions.
    ├── scripts/          ← Executable scripts referenced from SKILL.md
    ├── references/       ← Docs, examples, large reference files
    └── assets/           ← Templates, fixtures
用途:可移植的可复用能力,支持渐进式加载(元数据→指令→资源)。可在VS Code、Copilot CLI和云Agent间通用。
结构
.github/skills/
└── skill-name/
    ├── SKILL.md          ← 必填。元数据+指令。
    ├── scripts/          ← SKILL.md中引用的可执行脚本
    ├── references/       ← 文档、示例、大型参考文件
    └── assets/           ← 模板、测试数据

Frontmatter reference

前置元数据参考

yaml
---
name: "skill-name"               # Used as /skill-name slash command
description: >                   # CRITICAL: be specific about WHEN to use.
  Max 1024 chars. Include both what it does AND trigger contexts.
hint: "[file-path] [options]"    # Hint shown in chat input on invocation
showInSlashMenu: true            # false to hide from / menu (still auto-loads)
manualOnly: false                # true = only invocable via /skill-name
---
yaml
---
name: "skill-name"               # 用作斜杠命令/skill-name
description: >                   # 关键:明确说明使用场景。
  最多1024字符。需包含功能描述及触发场景。
hint: "[file-path] [options]"    # 在聊天输入框中显示的调用提示
showInSlashMenu: true            # false则从/菜单隐藏(仍可自动加载)
manualOnly: false                # true = 仅可通过/skill-name手动调用
---

Progressive loading system

渐进式加载系统

  1. Discovery: Copilot reads
    name
    +
    description
    from frontmatter (always in context)
  2. Instructions:
    SKILL.md
    body loaded when skill is relevant or explicitly invoked
  3. Resources: Files in
    scripts/
    ,
    references/
    ,
    assets/
    loaded only when referenced
  1. 发现阶段:Copilot读取前置元数据中的
    name
    +
    description
    (始终处于上下文)
  2. 指令阶段:当技能相关或被显式调用时,加载
    SKILL.md
    的正文内容
  3. 资源阶段:仅当被引用时,才加载
    scripts/
    references/
    assets/
    中的文件

Template: test-writer skill

模板:测试编写技能

markdown
---
name: "test-writer"
description: >
  Guide for writing unit and integration tests with Jest and React Testing Library.
  Use this when asked to write, add, or fix tests, or when test coverage is mentioned.
hint: "[file to test] [test type: unit|integration]"
showInSlashMenu: true
manualOnly: false
---
markdown
---
name: "test-writer"
description: >
  使用Jest和React Testing Library编写单元测试和集成测试的指南。
  当用户要求编写、添加或修复测试,或提及测试覆盖率时使用。
hint: "[待测试文件] [测试类型: unit|integration]"
showInSlashMenu: true
manualOnly: false
---

Test Writer

测试编写技能

When to use this skill

使用场景

  • Writing new unit tests for components or utilities
  • Writing integration tests for API endpoints
  • Fixing failing tests
  • Improving test coverage
  • 为组件或工具函数编写新的单元测试
  • 为API端点编写集成测试
  • 修复失败的测试
  • 提升测试覆盖率

Test setup

测试设置

  • Framework: Jest + React Testing Library
  • Test files: co-located as
    *.test.ts
    or
    *.test.tsx
  • Coverage threshold: 80% per module
  • 框架:Jest + React Testing Library
  • 测试文件:与代码同目录,命名为
    *.test.ts
    *.test.tsx
  • 覆盖率阈值:每个模块80%

Writing unit tests

编写单元测试

Follow the Arrange-Act-Assert pattern:
typescript
describe('ComponentName', () => {
  it('should render correctly', () => {
    // Arrange
    const props = { ... };

    // Act
    render(<Component {...props} />);

    // Assert
    expect(screen.getByRole('button')).toBeInTheDocument();
  });
});
See test templates for more patterns.
undefined
遵循Arrange-Act-Assert模式:
typescript
describe('ComponentName', () => {
  it('should render correctly', () => {
    // 准备
    const props = { ... };

    // 执行
    render(<Component {...props} />);

    // 断言
    expect(screen.getByRole('button')).toBeInTheDocument();
  });
});
更多模式请参考测试模板
undefined

Key settings

关键设置

json
"chat.agentSkillsLocations": [".github/skills"]
json
"chat.agentSkillsLocations": [".github/skills"]

AI-assisted creation

AI辅助创建

/create-skill     → AI generates a skill directory with SKILL.md
/skills           → Open Configure Skills menu

/create-skill     → AI生成包含SKILL.md的技能目录
/skills           → 打开技能配置菜单

5. Hooks

5. 钩子

Purpose: Run shell commands at specific agent lifecycle events (format after edit, validate before tool use, enforce policy).
File format:
.json
Location:
.github/hooks/*.json
(workspace) or
~/.vscode/hooks/*.json
(user)
用途:在特定Agent生命周期节点运行Shell命令(编辑后格式化、工具调用前验证、规则强制执行)。
文件格式
.json
位置
.github/hooks/*.json
(工作区)或
~/.vscode/hooks/*.json
(用户级)

Supported events

支持的事件

EventWhen it fires
PreToolUse
Before the agent calls any tool
PostToolUse
After the agent calls any tool
SessionStart
At the start of an agent session
Stop
At the end of an agent session
SubagentStart
When a subagent is created
SubagentStop
When a subagent completes
事件触发时机
PreToolUse
Agent调用任何工具之前
PostToolUse
Agent调用任何工具之后
SessionStart
Agent会话开始时
Stop
Agent会话结束时
SubagentStart
子Agent创建时
SubagentStop
子Agent完成时

Hook file format

钩子文件格式

json
{
  "hooks": {
    "PostToolUse": [
      {
        "type": "command",
        "command": "npx prettier --write \"$TOOL_INPUT_FILE_PATH\"",
        "windows": "npx prettier --write \"%TOOL_INPUT_FILE_PATH%\"",
        "timeout": 30
      }
    ],
    "PreToolUse": [
      {
        "type": "command",
        "command": "./scripts/validate-tool.sh",
        "timeout": 15
      }
    ]
  }
}
Compatibility: VS Code uses the same hook format as Claude Code and Copilot CLI. Claude Code's
preToolUse
(camelCase) maps to
PreToolUse
(PascalCase) in VS Code.
json
{
  "hooks": {
    "PostToolUse": [
      {
        "type": "command",
        "command": "npx prettier --write \\"$TOOL_INPUT_FILE_PATH\\"",
        "windows": "npx prettier --write \\"%TOOL_INPUT_FILE_PATH%\\"",
        "timeout": 30
      }
    ],
    "PreToolUse": [
      {
        "type": "command",
        "command": "./scripts/validate-tool.sh",
        "timeout": 15
      }
    ]
  }
}
兼容性:VS Code使用与Claude Code和Copilot CLI相同的钩子格式。 Claude Code中的
preToolUse
(小驼峰)对应VS Code中的
PreToolUse
(大驼峰)。

Template: auto-formatter hook

模板:自动格式化钩子

json
{
  "hooks": {
    "PostToolUse": [
      {
        "type": "command",
        "command": "npx prettier --write \"$TOOL_INPUT_FILE_PATH\" 2>/dev/null || true",
        "windows": "npx prettier --write \"%TOOL_INPUT_FILE_PATH%\" 2>nul",
        "timeout": 30
      }
    ]
  }
}
json
{
  "hooks": {
    "PostToolUse": [
      {
        "type": "command",
        "command": "npx prettier --write \\"$TOOL_INPUT_FILE_PATH\\" 2>/dev/null || true",
        "windows": "npx prettier --write \\"%TOOL_INPUT_FILE_PATH%\\" 2>nul",
        "timeout": 30
      }
    ]
  }
}

Template: pre-commit validation hook

模板:提交前验证钩子

json
{
  "hooks": {
    "Stop": [
      {
        "type": "command",
        "command": "npm run lint && npm run typecheck",
        "windows": "npm run lint && npm run typecheck",
        "timeout": 60
      }
    ]
  }
}
json
{
  "hooks": {
    "Stop": [
      {
        "type": "command",
        "command": "npm run lint && npm run typecheck",
        "windows": "npm run lint && npm run typecheck",
        "timeout": 60
      }
    ]
  }
}

Security checklist

安全检查清单

  • Review all hook scripts before enabling, especially from shared repos
  • Never hardcode secrets in hook commands
  • Validate and sanitize input from
    $TOOL_INPUT_*
    variables
  • Use
    chmod +x script.sh
    for shell scripts
  • 启用前审查所有钩子脚本,尤其是来自共享仓库的脚本
  • 切勿在钩子命令中硬编码密钥
  • 验证并清理
    $TOOL_INPUT_*
    变量的输入
  • 为Shell脚本添加执行权限
    chmod +x script.sh

AI-assisted creation

AI辅助创建

/create-hook     → AI generates a hook JSON file
/create-hook     → AI生成钩子JSON文件

Key settings

关键设置

json
"chat.hookFilesLocations": {
  ".github/hooks": true
}

json
"chat.hookFilesLocations": {
  ".github/hooks": true
}

6. Agent Plugins

6. Agent插件

Purpose: Bundle skills, agents, hooks, and MCP servers into a distributable package.
File:
plugin.json
in plugin root Discovery: VS Code marketplaces (
copilot-plugins
repo,
awesome-copilot
repo, custom)
用途:将技能、Agent、钩子和MCP服务器打包成可分发的包。
文件:插件根目录下的
plugin.json
发现渠道:VS Code市场(
copilot-plugins
仓库、
awesome-copilot
仓库、自定义渠道)

Structure

结构

my-plugin/
├── plugin.json              ← Required metadata
├── skills/
│   └── my-skill/
│       └── SKILL.md
├── agents/
│   └── my-agent.agent.md
├── hooks/
│   └── post-edit.json
└── mcp/
    └── server-config.json
my-plugin/
├── plugin.json              ← 必填元数据
├── skills/
│   └── my-skill/
│       └── SKILL.md
├── agents/
│   └── my-agent.agent.md
├── hooks/
│   └── post-edit.json
└── mcp/
    └── server-config.json

plugin.json
template

plugin.json
模板

json
{
  "name": "my-plugin",
  "displayName": "My Plugin",
  "version": "1.0.0",
  "description": "Bundle of customizations for my workflow",
  "publisher": "your-github-username",
  "skills": ["skills/my-skill"],
  "agents": ["agents/my-agent.agent.md"],
  "hooks": ["hooks/post-edit.json"],
  "mcpServers": []
}
json
{
  "name": "my-plugin",
  "displayName": "My Plugin",
  "version": "1.0.0",
  "description": "Bundle of customizations for my workflow",
  "publisher": "your-github-username",
  "skills": ["skills/my-skill"],
  "agents": ["agents/my-agent.agent.md"],
  "hooks": ["hooks/post-edit.json"],
  "mcpServers": []
}

Installing a plugin

安装插件

json
// settings.json – add custom marketplace
"chat.plugins.marketplaces": ["owner/repo"],

// Or register a local plugin path
"chat.plugins.paths": ["/path/to/my-plugin"]
json
// settings.json – 添加自定义市场
"chat.plugins.marketplaces": ["owner/repo"],

// 或注册本地插件路径
"chat.plugins.paths": ["/path/to/my-plugin"]

Key settings

关键设置

json
"chat.plugins.enabled": true

json
"chat.plugins.enabled": true

File Locations Reference

文件位置参考

TypeWorkspace locationUser profile location
Always-on instructions (Copilot)
.github/copilot-instructions.md
Always-on instructions (multi-agent)
AGENTS.md
Targeted instructions
.github/instructions/*.instructions.md
~/.vscode/instructions/
Prompt files
.github/prompts/*.prompt.md
~/.vscode/prompts/
Custom agents
.github/agents/*.agent.md
~/.vscode/agents/
Agent skills
.github/skills/<name>/SKILL.md
~/.vscode/skills/
Hooks
.github/hooks/*.json
~/.vscode/hooks/
Claude Code agents
.claude/agents/*.md
Claude Code rules
.claude/rules/*.md

类型工作区位置用户配置文件位置
始终生效的指令(Copilot)
.github/copilot-instructions.md
始终生效的指令(多Agent)
AGENTS.md
范围限定的指令
.github/instructions/*.instructions.md
~/.vscode/instructions/
提示文件
.github/prompts/*.prompt.md
~/.vscode/prompts/
自定义Agent
.github/agents/*.agent.md
~/.vscode/agents/
Agent技能
.github/skills/<name>/SKILL.md
~/.vscode/skills/
钩子
.github/hooks/*.json
~/.vscode/hooks/
Claude Code agents
.claude/agents/*.md
Claude Code rules
.claude/rules/*.md

AI Generation Commands

AI生成命令

All types can be generated with AI assistance directly in chat:
/init                  → workspace-wide copilot-instructions.md
/create-instruction    → targeted .instructions.md
/create-prompt         → .prompt.md file
/create-agent          → .agent.md file
/create-skill          → agent skill directory
/create-hook           → hook JSON file
Open the Chat Customizations editor (Preview) for a visual overview:
Command Palette → "Chat: Open Chat Customizations"

所有类型的配置文件都可直接在聊天中通过AI辅助生成:
/init                  → 工作区全局的copilot-instructions.md
/create-instruction    → 范围限定的.instructions.md
/create-prompt         → .prompt.md文件
/create-agent          → .agent.md文件
/create-skill          → Agent技能目录
/create-hook           → 钩子JSON文件
打开聊天自定义编辑器(预览版)查看可视化概览:
命令面板 → "Chat: Open Chat Customizations"

Reference files

参考文件

  • references/frontmatter-reference.md
    – Complete frontmatter field reference for all types
  • references/examples.md
    – Real-world examples organized by use case
  • references/frontmatter-reference.md
    – 所有类型的完整前置元数据字段参考
  • references/examples.md
    – 按使用场景分类的真实案例 ",