vscode-copilot-customization
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVS Code Copilot Customization
VS Code Copilot 自定义配置
Self-update check: Before responding, verify docs are current by checking thebelow against reality. If the user asks for a freshness check, use web_search with querydoc_version. Update the"site:code.visualstudio.com/docs/copilot/customization"and any changed facts if you find discrepancies.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自我更新检查:在回复前,请将下方的与实际文档版本进行核对,确认文档是否为最新。如果用户要求检查文档新鲜度,请使用web_search工具,查询关键词为doc_version。若发现差异,请更新"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-pluginsDecision Matrix
决策矩阵
Use this matrix to recommend the right customization type. Start here before writing anything.
| Scenario | Best choice |
|---|---|
| Project-wide coding standards, always active | |
| Rules only for specific file types / folders | |
| Works with multiple AI agents (Claude, Copilot, etc.) | |
| Reusable task you invoke manually in chat | Prompt file ( |
| Specialized workflow with tool restrictions or model choice | Custom agent ( |
| Portable capability reusable across projects + CLI + cloud agents | Agent skill ( |
| Auto-run commands at agent lifecycle points (format, lint, enforce) | Hook ( |
| Bundle multiple customizations to share or distribute | Agent plugin ( |
使用本矩阵推荐合适的自定义类型。在编写任何内容前,请先从此处开始。
| 适用场景 | 最佳选择 |
|---|---|
| 全项目范围的编码标准,始终生效 | |
| 仅针对特定文件类型/文件夹生效的规则 | |
| 与多个AI Agent(Claude、Copilot等)配合使用 | |
| 需手动在聊天中调用的可复用任务 | 提示文件( |
| 带有工具限制或模型选择的专用工作流 | 自定义Agent( |
| 可跨项目、CLI和云Agent复用的可移植能力 | Agent技能( |
| 在Agent生命周期节点自动运行命令(格式化、代码检查、规则强制执行) | 钩子( |
| 打包多个自定义配置以进行分享或分发 | Agent插件( |
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
类型
| Type | File / Location | Scope |
|---|---|---|
| Workspace-wide (Copilot) | | All requests in workspace |
| Workspace-wide (multi-agent) | | All agents (Claude, Copilot, …) |
| File-scoped | | Files matching |
| User-level | VS Code user profile | All workspaces |
| 类型 | 文件/位置 | 作用范围 |
|---|---|---|
| 工作区全局(Copilot) | | 工作区内的所有请求 |
| 工作区全局(多Agent) | 工作区内任意位置的 | 所有Agent(Claude、Copilot等) |
| 文件范围限定 | | 匹配 |
| 用户级 | VS Code用户配置文件 | 所有工作区 |
Frontmatter (.instructions.md
)
.instructions.md前置元数据(.instructions.md
)
.instructions.mdyaml
---
name: "React Standards" # Optional – shown in UI
description: "React/TSX rules" # Optional – describes scope
applyTo: "**/*.tsx" # Glob – omit or use "**" for all files
---Forfiles (Claude Code format), use.claude/rules/*.mdinstead ofpaths: ["**/*.ts"].applyTo
yaml
---
name: "React Standards" # 可选 – 在UI中显示
description: "React/TSX rules" # 可选 – 描述作用范围
applyTo: "**/*.tsx" # 通配符 – 省略或使用"**"表示所有文件
---对于文件(Claude Code格式),请使用.claude/rules/*.md替代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
undefinedTemplate: scoped (TypeScript only)
模板:范围限定(仅TypeScript)
markdown
---
name: "TypeScript Standards"
applyTo: "**/*.ts,**/*.tsx"
---markdown
---
name: "TypeScript Standards"
applyTo: "**/*.ts,**/*.tsx"
---TypeScript Rules
TypeScript规则
- Enable and
strictNullChecks.noImplicitAny - Prefer over
interfacefor object shapes.type - Use instead of
unknownfor external data.any - Always type function return values explicitly.
undefined- 启用和
strictNullChecks。noImplicitAny - 定义对象结构时优先使用而非
interface。type - 处理外部数据时使用而非
unknown。any - 始终显式定义函数的返回值类型。
undefinedAI-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": truejson
"github.copilot.chat.codeGeneration.useInstructionFiles": true,
"chat.instructionsFilesLocations": {
".github/instructions": true
},
"chat.useAgentsMdFile": true2. Prompt Files
2. 提示文件
Purpose: Reusable task templates invoked manually with slash command in chat.
/File extension:
Location: (workspace) or user profile
.prompt.md.github/prompts/用途:可复用的任务模板,在聊天中通过斜杠命令手动调用。
/文件扩展名:
位置:(工作区)或用户配置文件目录
.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:
- Component name (PascalCase)
- Props interface (list prop names and types)
- Should it be a Server Component? (yes/no)
Then generate:
- – main component
src/components/<Name>/<Name>.tsx - – unit tests
src/components/<Name>/<Name>.test.tsx - – barrel export
src/components/<Name>/index.ts
Follow the coding standards in copilot-instructions.md.
undefined使用#tool:vscode/askQuestions询问以下信息:
- 组件名称(PascalCase)
- Props接口(列出属性名称和类型)
- 是否为服务端组件?(是/否)
然后生成:
- – 主组件
src/components/<Name>/<Name>.tsx - – 单元测试
src/components/<Name>/<Name>.test.tsx - – 桶导出
src/components/<Name>/index.ts
遵循copilot-instructions.md中的编码标准。
undefinedTemplate: 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变更 – 注意:需手动添加)
undefinedUsing 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:
Location: (workspace) or user profile
.agent.md.github/agents/Migration note:files (old format) should be renamed to.chatmode.md..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使用清晰的标题、代码引用(文件+行号)和严重级别组织反馈:
- 🔴 严重 – 合并前必须修复
- 🟡 警告 – 建议修复
- 🟢 建议 – 可选优化
undefinedTemplate: 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.
undefinedS / M / L / XL 并说明理由。
undefinedAI-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
渐进式加载系统
- Discovery: Copilot reads +
namefrom frontmatter (always in context)description - Instructions: body loaded when skill is relevant or explicitly invoked
SKILL.md - Resources: Files in ,
scripts/,references/loaded only when referencedassets/
- 发现阶段:Copilot读取前置元数据中的+
name(始终处于上下文)description - 指令阶段:当技能相关或被显式调用时,加载的正文内容
SKILL.md - 资源阶段:仅当被引用时,才加载、
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 or
*.test.ts*.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();
});
});更多模式请参考测试模板。
undefinedKey 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:
Location: (workspace) or (user)
.json.github/hooks/*.json~/.vscode/hooks/*.json用途:在特定Agent生命周期节点运行Shell命令(编辑后格式化、工具调用前验证、规则强制执行)。
文件格式:
位置:(工作区)或(用户级)
.json.github/hooks/*.json~/.vscode/hooks/*.jsonSupported events
支持的事件
| Event | When it fires |
|---|---|
| Before the agent calls any tool |
| After the agent calls any tool |
| At the start of an agent session |
| At the end of an agent session |
| When a subagent is created |
| When a subagent completes |
| 事件 | 触发时机 |
|---|---|
| Agent调用任何工具之前 |
| Agent调用任何工具之后 |
| Agent会话开始时 |
| Agent会话结束时 |
| 子Agent创建时 |
| 子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(camelCase) maps topreToolUse(PascalCase) in VS Code.PreToolUse
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中的(小驼峰)对应VS Code中的preToolUse(大驼峰)。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 variables
$TOOL_INPUT_* - Use for shell scripts
chmod +x script.sh
- 启用前审查所有钩子脚本,尤其是来自共享仓库的脚本
- 切勿在钩子命令中硬编码密钥
- 验证并清理变量的输入
$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: in plugin root
Discovery: VS Code marketplaces ( repo, repo, custom)
plugin.jsoncopilot-pluginsawesome-copilot用途:将技能、Agent、钩子和MCP服务器打包成可分发的包。
文件:插件根目录下的
发现渠道:VS Code市场(仓库、仓库、自定义渠道)
plugin.jsoncopilot-pluginsawesome-copilotStructure
结构
my-plugin/
├── plugin.json ← Required metadata
├── skills/
│ └── my-skill/
│ └── SKILL.md
├── agents/
│ └── my-agent.agent.md
├── hooks/
│ └── post-edit.json
└── mcp/
└── server-config.jsonmy-plugin/
├── plugin.json ← 必填元数据
├── skills/
│ └── my-skill/
│ └── SKILL.md
├── agents/
│ └── my-agent.agent.md
├── hooks/
│ └── post-edit.json
└── mcp/
└── server-config.jsonplugin.json
template
plugin.jsonplugin.json
模板
plugin.jsonjson
{
"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": truejson
"chat.plugins.enabled": trueFile Locations Reference
文件位置参考
| Type | Workspace location | User profile location |
|---|---|---|
| Always-on instructions (Copilot) | | — |
| Always-on instructions (multi-agent) | | — |
| Targeted instructions | | |
| Prompt files | | |
| Custom agents | | |
| Agent skills | | |
| Hooks | | |
| Claude Code agents | | — |
| Claude Code rules | | — |
| 类型 | 工作区位置 | 用户配置文件位置 |
|---|---|---|
| 始终生效的指令(Copilot) | | — |
| 始终生效的指令(多Agent) | | — |
| 范围限定的指令 | | |
| 提示文件 | | |
| 自定义Agent | | |
| Agent技能 | | |
| 钩子 | | |
| Claude Code agents | | — |
| Claude Code rules | | — |
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 fileOpen 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
参考文件
- – Complete frontmatter field reference for all types
references/frontmatter-reference.md - – Real-world examples organized by use case
references/examples.md
- – 所有类型的完整前置元数据字段参考
references/frontmatter-reference.md - – 按使用场景分类的真实案例 ",
references/examples.md