VS Code February events – Agent Sessions Day on Feb 19th
Dismiss this update
This article covers proven practices for getting the most out of using AI in Visual Studio Code. Each section provides actionable guidance with links to deeper documentation.
Custom instructions tell the AI about your team's coding standards, preferred patterns, and project-specific context. This approach reduces repetitive prompting and improves the consistency of generated code.
To get started:
Enter /init in the chat input to generate a copilot-instructions.md or AGENTS.md file tailored to your project structure.
Edit the generated file to add or refine instructions.
For language-specific or framework-specific rules, create additional .instructions.md files with applyTo glob patterns by using the Chat: New Instructions File command.
Write effective instructions:
For more information, see custom instructions and the full customization overview.
AI in VS Code offers several interaction modes. Choosing the right one for the task at hand saves time and produces better results.
| Tool | Best for | Example |
|---|---|---|
| Inline suggestions | Staying in the flow while writing code | Code completions, variable names, boilerplate |
| Ask (chat) | Questions, brainstorming, exploring ideas | "How does authentication work in this project?" |
| Inline chat | Targeted, in-place edits without switching context | Refactoring a function, adding error handling |
| Agents | Multi-file changes that require autonomous planning and tool use | Implementing a feature end-to-end |
| Plan | Structured planning before implementation | Designing an architecture or migration strategy |
| Smart actions | Built-in, specialized one-step tasks | Generating commit messages, fixing errors, renaming symbols |
The quality of AI responses depends on the clarity and specificity of your prompt. These techniques help you get better results.
Be specific about inputs, outputs, and constraints. State the programming language, frameworks, and libraries you want to use. Describe expected behavior or include example input and output.
Write a TypeScript function that validates email addresses.
Return true for valid addresses, false otherwise. Don't use regex.
Example: validateEmail("[email protected]") returns true
Example: validateEmail("invalid") returns false
Break down complex tasks. Instead of asking for an entire feature at once, decompose it into smaller, well-scoped steps. This approach produces more reliable results and makes it easier to catch problems early.
Include expected output for verification. Provide test cases, expected results, or acceptance criteria so the AI can verify its own work. This step is one of the highest-leverage things you can do.
Implement a rate limiter using the token bucket algorithm.
Write unit tests that verify: 10 requests/second allowed,
11th request rejected, bucket refills after 1 second.
Run the tests after implementing.
Iterate with follow-up prompts. Refine responses by adding constraints or corrections in follow-up messages rather than rewriting the entire prompt.
Avoid vague prompts. A prompt like "make this better" gives the AI no direction. Instead, specify what "better" means: "reduce the time complexity" or "add input validation for null values."
For more information, see prompt engineering and find practical prompt examples in the GitHub Copilot documentation.
The AI responds more accurately when it has relevant context. Use these techniques to point the AI at the right information:
#codebase to explicitly instruct the AI to search your workspace for relevant code.#<file>, #<folder>, or #<symbol>. Or, use drag and drop.#fetch to pull content from a web page, or #githubRepo to search a GitHub repository.For more information, see adding context to chat prompts and configuring tools.
For more information, see selecting AI models and available models for Copilot Chat.
For complex changes that span multiple files, separate planning from implementation. This approach prevents the AI from solving the wrong problem.
For more information, see the context engineering workflow.
AI responses might degrade as the conversation fills with irrelevant context. Manage your sessions proactively.
For more information, see session management and workspace indexing.
Commit reusable customization files to your repository so your entire team benefits from consistent AI behavior.
.prompt.md). Trigger them like slash commands by typing / followed by the prompt name (for example, /security-review)..agent.md). Use them for constrained workflows like code review, security audit, or planning.SKILL.md). Include scripts, examples, and reference docs alongside your instructions.description in the Agent Skill YAML frontmatter that states both what the skill does and when to use it. The AI uses this field to decide whether to load the skill.Browse community skills in the awesome-copilot repository.