NEW: Claude Code Security — research preview

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

TaskUse
Writing new codeInline suggestions
Questions, brainstormingAsk (chat)
Targeted, in-place editsInline chat (Ctrl+I)
Multi-file featuresAgent mode
Structured planningPlan agent
Commit messages, fix errors, renameSmart 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

  1. 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.
  1. Include verification — add test cases so the AI can validate its own work
  2. Break down complex tasks — one well-scoped step at a time
  3. Avoid vague prompts — not "make this better"; say "reduce time complexity" or "add null validation"
  4. Iterate — add constraints in follow-up messages instead of rewriting the whole prompt
  5. Course-correct early — steer with a follow-up, queue a message, or stop and restart
  6. Ask for clarification — instruct the AI to ask questions before proceeding when the task is ambiguous

Provide the Right Context

  • Use #file, #folder, #symbol to reference specific code
  • Use #fetch for 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:

  1. Explore — use Ask mode to understand the existing code
  2. Plan — use the Plan agent to create a structured implementation plan
  3. Implement — switch to Agent mode, include tests or expected outputs
  4. 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 /compact to 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