Best Practices
Proven techniques for getting the most out of AI in VS Code
Read time: 6 min
title: "Best Practices" description: "Proven techniques for getting the most out of AI in VS Code" section: "Copilot" readTime: "6 min"
Best Practices for AI in VS Code
Pick the Right Tool
| Task | Use |
|---|---|
| Writing new code | Inline suggestions |
| Questions, brainstorming | Ask (chat) |
| Targeted, in-place edits | Inline chat (Ctrl+I) |
| Multi-file features | Agent mode |
| Structured planning | Plan agent |
| Commit messages, fix errors, rename | Smart actions |
Choose the Right Agent Type
- Local — interactive work needing editor context (test failures, debug output, MCP tools)
- Copilot CLI / Cloud — well-defined tasks you can offload while continuing to work
- Cloud — team collaboration, opening PRs, assigning GitHub issues
- Parallel sessions — run multiple agents simultaneously for independent tasks
Hand off between types: start local to explore/plan, hand off to background/cloud for implementation.
Write Effective Prompts
- Be specific — state language, frameworks, libraries, expected behavior
Write a TypeScript function that validates email addresses.
Return true for valid, false otherwise. Don't use regex.
- Include verification — add test cases so the AI can validate its own work
- Break down complex tasks — one well-scoped step at a time
- Avoid vague prompts — not "make this better"; say "reduce time complexity" or "add null validation"
- Iterate — add constraints in follow-up messages instead of rewriting the whole prompt
- Course-correct early — steer with a follow-up, queue a message, or stop and restart
- Ask for clarification — instruct the AI to ask questions before proceeding when the task is ambiguous
Provide the Right Context
- Use
#file,#folder,#symbolto reference specific code - Use
#fetchfor up-to-date information from web pages - Reference source control changes (
#changes), terminal output, or test failures - Attach images or screenshots for visual context
- Open related files so Copilot has broader codebase context
Choose the Right Model
- Fast models — simple completions, boilerplate
- Reasoning models — planning, debugging, architecture decisions
- Pin a model in custom agent or prompt file definitions for consistency
- Experiment: different models produce different results for the same prompt
- Use BYOK (Bring Your Own Key) for additional model options
Plan First, Then Implement
For complex multi-file changes:
- Explore — use Ask mode to understand the existing code
- Plan — use the Plan agent to create a structured implementation plan
- Implement — switch to Agent mode, include tests or expected outputs
- Review — use checkpoints to roll back if the agent goes off track
Review AI Output
- Read generated code before accepting — check edge cases and error handling
- Run tests after every AI change
- Use checkpoints (
chat.checkpoints.enabled) to roll back to before a change - Check for security issues: injection flaws, hardcoded secrets, missing input validation
- Never paste credentials or sensitive data into prompts
Manage Context and Sessions
- Start new sessions for unrelated tasks — context pollution degrades quality
- Delete irrelevant chat history or use
/compactto summarize it - Use subagents for isolated research that shouldn't pollute main context
- Run parallel sessions for independent tasks via the Sessions list
Large Codebases
- VS Code auto-indexes with semantic search + language intelligence
- Enable remote indexing for large GitHub repos
- Use multi-root workspaces to scope context in monorepos
- Add custom instructions describing architecture and module boundaries
- Use the Plan agent for cross-cutting changes spanning many files