Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .lychee.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ exclude = [
# 需要登录的 GitHub 仓库设置页
"^https?://github\\.com/.+/settings",

# 对 CI 爬虫返回 403 的站点(人工访问正常)
"^https?://platform\\.openai\\.com",

# QQ 链接跳转
"^https?://qm\\.qq\\.com",
]
Expand Down
103 changes: 77 additions & 26 deletions copilot/README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# GitHub Copilot Best Practices

> GitHub Copilot is the built-in AI coding assistant for VS Code and JetBrains IDEs. Its core strength is **seamless integration** — no tool switching needed, just write code in your editor and get completions and suggestions naturally. Copilot Agent mode evolves it from a completion tool into an autonomous agent that can tackle tasks independently.
>
> Last updated: 2026-09.

---

Expand All @@ -11,12 +13,13 @@
| Concept | Description | Use Case |
|---------|-------------|----------|
| **Code Completion** | Inline gray suggestions | Daily coding, press Tab to accept |
| **Chat** | Sidebar conversation `Cmd+Shift+I` | Q&A, code explanations |
| **Agent Mode** | Autonomously completes multi-step tasks | Complex tasks, cross-file changes |
| **Chat** | Chat view `⌃⌘I` | Q&A, code explanations |
| **Agent Mode** | Autonomously completes multi-step tasks (`⇧⌘I` opens chat in agent mode) | Complex tasks, cross-file changes |
| **Copilot Instructions** | `.github/copilot-instructions.md` | Project-level configuration |
| **Chat Modes** | Custom conversation roles | Security auditor, testing expert, etc. |
| **MCP Server** | Extends Copilot's tool capabilities | Connect to databases, APIs, etc. |
| **# References** | `#file` `#selection` `#terminal` | Pinpoint context precisely |
| **Instructions files** | `.github/instructions/*.instructions.md`, scoped by path via `applyTo` | Per-directory / per-file-type rules |
| **Custom Agents** | `.github/agents/*.agent.md` (formerly Chat Modes) | Security auditor, testing expert, etc. |
| **MCP Server** | `.vscode/mcp.json`, extends Copilot's tool capabilities | Connect to databases, APIs, etc. |
| **# References** | `#file` `#selection` `#terminal` `#codebase` | Pinpoint context precisely |

---

Expand Down Expand Up @@ -63,6 +66,9 @@ Create `.github/copilot-instructions.md` in your project root:

# Reference VS Code problems panel
#problems Fix these type errors for me

# Force a semantic search of the codebase
#codebase Where in the project do we build SQL by string concatenation?
```

---
Expand All @@ -75,10 +81,10 @@ Copilot Agent was the biggest update of 2025. Enter a task in the chat, and Agen

### Using Agent Mode

Select Agent mode in Chat (or just describe a complex task):
Select Agent mode in Chat (or press `⇧⌘I` to jump straight in). The agent searches the codebase on its own — no need for `@workspace`:

```
@workspace Add rate limiting to all endpoints under src/api/,
Add rate limiting to all endpoints under src/api/,
using Redis as the counter. Max 60 requests per user per minute.
Requirements:
1. A reusable rate_limit decorator
Expand All @@ -89,15 +95,14 @@ Requirements:

### Agent + MCP for Extended Capabilities

Use MCP Servers to give Agent access to external tools:
Use MCP Servers to give Agent access to external tools. Create `.vscode/mcp.json` in your project (the top-level key is `servers`):

```json
// .vscode/settings.json
{
"github.copilot.chat.mcpServers": {
"servers": {
"postgres": {
"command": "npx",
"args": ["@modelcontextprotocol/server-postgres", "postgresql://..."]
"args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://..."]
}
}
}
Expand Down Expand Up @@ -141,36 +146,57 @@ You are a security review expert. When reviewing code:
4. Label risk levels: 🔴 Critical / 🟡 Medium / 🟢 Low
```

Invoke this role in Chat with `@security-reviewer`.
Select it from the **Agent dropdown** in the Chat view, or type `/agents` in the chat input to pick it from the list.

### 3. Leverage Workspace for Global Understanding
### 3. Let the Agent Search the Whole Codebase

```
@workspace Are there any hardcoded secrets or sensitive values in the project?
Are there any hardcoded secrets or sensitive values in the project?
Find them all and refactor to use environment variables.
```

The agent searches the codebase automatically; add `#codebase` when you want to force a semantic search.

---

## Advanced Tips

### Custom Instruction Files
### Custom Instructions and Extension Files

Copilot supports these files to fine-tune behavior:

| File | Purpose |
|------|---------|
| `.github/copilot-instructions.md` | Global project instructions |
| `.github/instructions/*.instructions.md` | Scoped by path via the `applyTo` glob in frontmatter |
| `AGENTS.md` / `CLAUDE.md` | Cross-tool instruction files, also read by Copilot |
| `.github/agents/*.agent.md` | Custom agents (`.chatmode.md` is deprecated — rename to `.agent.md` to migrate) |
| `.github/prompts/*.prompt.md` | Reusable prompts, invoked in Chat as `/name` |
| `.github/skills/`, `.claude/skills/`, `.agents/skills/` | Agent Skills, loaded on demand |
| Hooks | Run scripts before/after agent actions |

Copilot supports instruction files to fine-tune behavior:
`applyTo` example (`.github/instructions/python.instructions.md`):

- **`.github/copilot-instructions.md`** — Global project instructions
- **`.github/chatModes/`** — Custom Chat roles (e.g., security reviewer, testing expert)
```markdown
---
applyTo: "**/*.py"
---

If you use superpowers-zh, you can also write methodology in skill files under `.claude/skills/` — Copilot Agent's `@workspace` command reads markdown files in the project.
- All functions must have type annotations
- Use pytest, not unittest
```

### VS Code Keyboard Shortcuts
If you use superpowers-zh, put the skill files under `.github/skills/`, `.claude/skills/` or `.agents/skills/` — Copilot Agent loads them on demand as Agent Skills.

### VS Code Keyboard Shortcuts (macOS)

| Shortcut | Action |
|----------|--------|
| `Tab` | Accept completion |
| `Esc` | Reject completion |
| `Cmd+Shift+I` | Open Copilot Chat |
| `Cmd+I` | Inline edit |
| `⌃⌘I` | Open the Chat view |
| `⇧⌘I` | Open chat in agent mode |
| `⌘I` | Inline chat (in the editor) |
| `Alt+]` / `Alt+[` | Cycle through completion suggestions |

### Completion Optimization
Expand All @@ -182,6 +208,30 @@ Tips for more accurate Copilot completions:
3. **Write function signatures first** — Define the name, parameters, and return type, then let Copilot complete the body
4. **Keep files short** — Large files add context noise, causing Copilot to drift

### Billing and Plans

Since 2026-06-01 Copilot bills usage in **GitHub AI Credits**: Chat, agent mode, code review, the cloud agent, Copilot CLI, etc. consume credits; code completions stay unlimited on paid plans.

| Plan | Price | Included per month |
|------|-------|--------------------|
| Free | $0 | 2,000 completions + a small credit allowance |
| Pro | $10/mo | 1,500 credits |
| Pro+ | $39/mo | 7,000 credits |
| Max | $100/mo | 20,000 credits |
| Business | $19/seat/mo | 1,900 credits per user |
| Enterprise | $39/seat/mo | 3,900 credits per user |

See the [official plans page](https://docs.github.com/en/copilot/get-started/plans) for the latest.

### New in 2026

- **Copilot coding agent renamed to Copilot cloud agent**: takes an Issue to a PR in the cloud
- **GitHub Copilot app**: desktop app, GA on 2026-06-17, available on all plans
- **Copilot CLI GA**: Copilot agent in the terminal
- **Agent Plugins 1.0**: package and distribute custom agents, skills and more
- **Copilot code review**: consumes AI Credits + GitHub Actions minutes
- **JetBrains**: custom agents, subagents and the plan agent went GA in March 2026, with AGENTS.md / CLAUDE.md support

---

## Common Pitfalls
Expand All @@ -190,10 +240,10 @@ Tips for more accurate Copilot completions:
|---------|-------------|----------|
| Outdated API completions | Copilot suggests deprecated library APIs | Open the library source or docs as a tab for context |
| Agent edits wrong files | Multi-file changes touch things they shouldn't | Use `#file` to limit scope |
| Ignores .gitignore | Copilot may read node_modules | Check exclude settings in configuration |
| Instructions too long | Exceeds model context window | Trim to essential rules, move details into Chat Modes |
| Sensitive files get read | Agent mode in the IDE doesn't support content exclusion, so `.env` etc. may still be read | Keep secrets out of the project directory; content exclusion is configured at repo/org/enterprise level and doesn't apply to agent mode |
| Instructions too long | Key points get buried, later rules work poorly | Trim to essential rules; move situational rules into `.instructions.md` (`applyTo`) or custom agents |

👉 **Deep dive**: [Copilot Pitfalls](../pitfalls/copilot.en.md) — 8 real-world traps (Agent reads .env / MCP silent fail / free tier throttling and more), each with Symptom / Cause / Recovery / Prevention
👉 **Deep dive**: [Copilot Pitfalls](../pitfalls/copilot.en.md) — 8 real-world traps (Agent reads .env / MCP silent fail / running out of credits and more), each with Symptom / Cause / Recovery / Prevention

---

Expand All @@ -204,12 +254,13 @@ Copy directly into your project:
| Template | Purpose |
|----------|---------|
| [copilot-instructions.md](templates/copilot-instructions.md) | Project guidelines template, copy to `.github/copilot-instructions.md` |
| [security-reviewer.agent.md](templates/security-reviewer.agent.md) | Security reviewer role, copy to `.github/agents/` |
| [security-reviewer.agent.md](templates/security-reviewer.agent.md) | Security reviewer custom agent, copy to `.github/agents/` |

---

## Further Reading

- [Copilot Official Docs](https://docs.github.com/en/copilot)
- [VS Code Copilot customization docs](https://code.visualstudio.com/docs/copilot/customization/custom-agents) — Custom agents, instructions, MCP
- [awesome-copilot](https://github.com/github/awesome-copilot) — Official resource collection (27k+ stars)
- [superpowers-zh](https://github.com/jnMetaCode/superpowers-zh) — Skills methodology (also supports VS Code Copilot)
Loading
Loading