Best Practices
Master the art of working with Copilot Chat. Learn how to write effective prompts, manage context, handle privacy concerns, integrate into team workflows, and avoid common pitfalls.
Writing Effective Chat Prompts
The quality of Copilot Chat's response depends heavily on how you phrase your prompt. Follow these principles for better results:
Be Specific and Detailed
// Vague prompt (poor results) Write a function to process data // Specific prompt (much better results) Write a TypeScript function called processUserData that takes an array of User objects, filters out inactive users (isActive === false), sorts the remaining by lastLoginDate descending, and returns the top 10 with only id, name, and email fields
Provide Context
// Include constraints and requirements Write a caching middleware for Express that: - Caches GET responses in Redis - Uses the request URL as the cache key - Expires after 5 minutes - Skips caching for authenticated routes - Returns appropriate Cache-Control headers - Uses the existing Redis client from #file:src/config/redis.ts
Break Down Complex Tasks
// Instead of one huge prompt, break it down: // Step 1: Design What is the best way to implement rate limiting for our Express API? Consider our architecture in @workspace // Step 2: Implement Implement the sliding window rate limiter you described using Redis // Step 3: Test /tests Generate tests for the rate limiter including edge cases for concurrent requests // Step 4: Document /doc Add comprehensive documentation
When to Use Chat vs Inline vs Quick Chat
Choosing the right interaction mode makes your workflow more efficient:
| Scenario | Best Mode | Why |
|---|---|---|
| Exploring unfamiliar code | Chat Panel | Multi-turn conversation, ask follow-ups |
| Refactoring a function | Inline Chat | See changes in context, quick accept/reject |
| Looking up syntax | Quick Chat | Fast answer, does not interrupt flow |
| Generating a new module | Chat Panel | Complex output, may need iteration |
| Adding a comment or docstring | Inline Chat | Applied directly at cursor position |
| Understanding an error | Chat Panel | May need back-and-forth debugging |
| Renaming across files | Copilot Edits | Multi-file changes with review |
| Quick command lookup | Quick Chat | One-off answer, no context needed |
Context Management Best Practices
Effective context management is the single biggest factor in getting good results from Copilot Chat.
- Start fresh for new topics: Use
/clearwhen switching to a completely different task. Stale context from previous conversations can confuse responses. - Select relevant code: Before asking a question, select the specific code you are asking about. Do not rely on Copilot to guess which part of the file you mean.
- Use #file for cross-file context: When your question involves code in another file, explicitly reference it with
#file. Do not assume Copilot knows about other files. - Use @workspace sparingly: @workspace searches your entire project, which adds latency. Use it for project-wide questions, not for questions about specific code.
- Keep conversations focused: One topic per conversation. If you need to switch topics, start a new chat.
Privacy and Data Handling
Understanding how Copilot Chat handles your code is important, especially in corporate environments.
| Plan | Code Retention | Training Use |
|---|---|---|
| Individual | Snippets may be retained | Opt-out available in settings |
| Business | No code retention by default | Code not used for training |
| Enterprise | No code retention | Code not used for training, IP indemnity |
Team Workflow Integration
Teams get the most value from Copilot Chat when they establish shared practices:
-
Establish Custom Instructions
Create a shared
.github/copilot-instructions.mdthat encodes your team's coding standards, architecture decisions, and testing practices. -
Create Shared Prompt Templates
Build a library of custom slash commands in
.github/copilot-prompts/for common team tasks like code review, migration patterns, and documentation standards. -
Standardize on Workflows
Agree on when to use chat vs inline vs edits mode. Document recommended prompts for common scenarios in your team wiki.
-
Review AI-Generated Code
Treat all AI-generated code as you would any developer's code: it must go through code review, pass tests, and meet quality standards.
Common Mistakes to Avoid
| Mistake | Why It's a Problem | What to Do Instead |
|---|---|---|
| Accepting code without review | AI can generate plausible but incorrect code | Always read, test, and understand generated code |
| Overly vague prompts | Produces generic, unhelpful responses | Be specific about inputs, outputs, constraints |
| Ignoring context management | Wrong context leads to wrong answers | Select code, use #file, /clear between topics |
| One giant prompt | Too many requirements overwhelm the model | Break into smaller, focused requests |
| Not iterating | First response may not be perfect | Refine with follow-up prompts |
| Pasting secrets in chat | Security risk, potential data exposure | Use placeholder values, reference env vars |
Frequently Asked Questions
No. Copilot Chat does not browse the internet in real time. Its knowledge comes from its training data and the context you provide (your code, files, and workspace). It cannot fetch live documentation or check current API responses.
Only when you use @workspace. By default, Copilot Chat has context about the currently open file and any selected code. Using @workspace lets it search across your project, and #file lets you explicitly include specific files.
It depends on your plan. With Copilot Business and Enterprise plans, your code is not retained or used for training. With the Individual plan, you can opt out of code snippets being used for product improvements in your GitHub settings under Copilot preferences.
No. Copilot Chat requires an internet connection because the AI models run on GitHub's servers. Your prompts are sent to the server, processed, and the response is returned to your editor.
Copilot Chat is a conversational interface for asking questions and getting code suggestions. Copilot Edits is a specialized mode for applying changes across multiple files with a working set and diff preview. Think of Chat as your AI advisor and Edits as your AI pair programmer.
The top three strategies are: (1) Be specific in your prompts with clear inputs, outputs, and constraints. (2) Provide good context by selecting relevant code and using #file references. (3) Iterate on responses with follow-up prompts rather than starting over. Also, try switching models - different models excel at different tasks.
In standard chat mode, no - it only generates text and code suggestions. However, in Agent mode, Copilot can propose and run terminal commands (with your approval). It can also suggest code that you can run in the terminal using the "Run in Terminal" button on code blocks.
💡 Try It: Optimize Your Workflow
Reflect on how you have used Copilot Chat throughout this course. Identify your most common use cases and create a personal workflow guide:
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX