VS Code Copilot Chat

repository·main·Indexed 27 days ago

https://github.com/microsoft/vscode-copilot-chat

AI chat features for Visual Studio Code powered by GitHub Copilot. Includes support for autonomous agents (Planning, Implementation, and Cloud agents), inline suggestions, and inline chat. Provides the @vscode/chat-lib SDK and tools for customizing workflows via .agent.md, .instructions.md, .prompt.md, and SKILL.md files, as well as integration with Model Context Protocol (MCP) servers and Claude Code session parsing.

Tokens
40.3K
Snippets
75
Records
195
Agent score
94%

What's inside vscode-copilot-chat

  1. Security and Privacy of Copilot Chat OTel data

    main

    Copilot Chat's OpenTelemetry implementation follows these security principles:

    • Off by default: No OTel data is emitted unless github.copilot.chat.otel.enabled is set to true. When disabled, the SDK is not loaded, ensuring zero runtime overhead.
    • No content by default: Prompts, responses, and tool arguments are only captured if github.copilot.chat.otel.captureContent is explicitly enabled.
    • No PII in default attributes: Default attributes like session IDs, model names, and token counts do not contain personally identifiable information.
    • User-controlled endpoints: Data is only sent to the endpoint explicitly configured by the user.
    • Dynamic imports: OTel SDK packages are loaded on-demand to ensure zero bundle impact when telemetry is disabled.
  2. Understand the Trajectory Logging Architecture

    main

    The trajectory logging system captures the sequence of interactions (steps) between a user and an AI agent. It uses a multi-layered approach to translate raw request logs into structured agent trajectories.

    Core Components

    • RequestLogger: An implementation that stores raw request entries in an array. It is bounded and uses an auto-shift mechanism to remove the oldest entries to prevent memory exhaustion.
    • TrajectoryLogger: Manages a collection of IAgentTrajectory objects in a Map. It is unbounded and requires manual calls to clearTrajectory() to free memory.
    • TrajectoryLoggerAdapter: Acts as a bridge/translation layer. It watches RequestLogger events and populates the TrajectoryLogger.

    Data Flow for Exporting Trajectories

    When the "Export Trajectory" command is triggered:

    1. A CapturingToken is retrieved from the UI tree item.
    2. The TrajectoryLoggerAdapter.getSessionIdForToken() method performs a WeakMap lookup to resolve the session ID.
    3. TrajectoryLogger.getAllTrajectories() retrieves the map of session IDs to trajectories.
    4. collectTrajectoryWithSubagents() recursively follows subagent_trajectory_ref to include linked subagent data.
    5. The resulting data is written to .trajectory.json files in the user-selected folder.
  3. Understand the Trajectory Logging Architecture

    main
    The trajectory logging system in VS Code Copilot Chat captures agent execution traces using the ATIF (Agent Trajectory Interchange Format). This is used for analysis, debugging, and benchmarking. The system operates as a pipeline that transforms raw request logs into structured trajectories through three main components: RequestLogger, TrajectoryLoggerAdapter, and TrajectoryLogger.
  4. Understand Agent OTel Instrumentation Strategies

    main

    The Copilot Chat extension uses four different OpenTelemetry (OTel) strategies depending on the agent execution path. Developers should choose the appropriate mental model when debugging or extending agent behavior:

    AgentProcess ModelStrategyDebug Panel Source
    Foreground (toolCallingLoop)Extension hostDirect IOTelService spansExtension spans
    Copilot CLI in-processExtension host (same process)Bridge SpanProcessor — SDK creates spans natively; bridge forwards to debug panelSDK native spans via bridge
    Copilot CLI terminalSeparate terminal processForward OTel env varsN/A (separate process)
    Claude CodeChild process (Node fork)Synthetic spans — extension creates spans from message loopExtension synthetic spans

    Note: The CLI SDK runs in-process with full trace hierarchy, while Claude Code runs as a separate process where internal spans are inaccessible, requiring synthetic spans.

  5. Compare Claude sessions with other Copilot targets

    main

    Claude sessions differ from Local (Copilot), Copilot CLI, and Cloud targets in several ways:

    • Execution: Runs locally via Agent SDK.
    • Agentic Loop: Supports autonomous iteration and a "Plan → review → execute" workflow.
    • Capabilities: Supports direct Bash execution, subagents, and custom lifecycle hooks.
    • Memory: Uses CLAUDE.md files for project context.
    • Persistence: Sessions are saved as JSONL files on disk.
    • Models: Limited to the Claude family of models.
  6. Understand Recently Viewed Files Clipping Strategies

    main

    The NES/xtab prompt uses three distinct clipping strategies to select and truncate recently viewed file content based on a token budget (opts.recentlyViewedDocuments.maxTokens). All strategies use Paged Clipping, where content is divided into pages of pageSize lines and processed as whole units. The final output is reversed to provide a least-recent-first order (oldest files at the top, most recent at the bottom).

    Comparison of Strategies

    PropertyTopToBottomAroundEditRangeProportional
    Budget allocationGreedy, most-recent-firstGreedy, most-recent-firstTwo-pass proportional
    Clip centerTop of fileEdit/visible rangesEdit ranges
    File droppingImplicit (budget exhausted)Implicit (focal cost exceeds budget)Explicit (oldest first)
    Multi-edit per fileSingle entry per fileSingle entry per fileAll entries merged
    History collectioncollectRecentDocumentscollectRecentDocumentscollectRecentDocumentsGrouped
  7. Open a Claude Session

    main

    A session target determines which AI backend processes your requests. To switch to Claude (Anthropic's Claude Agent SDK running locally):

    1. Open the Chat panel (⌃⌘I on macOS / Ctrl+Alt+I on Windows/Linux).
    2. Click the session target name at the bottom of the chat input area (e.g., "Local").
    3. Select Claude from the picker.

    Troubleshooting: If you receive a "Failed to open chat session" error (e.g., Can not find provider for claude-code), ensure you are signed into GitHub via the Accounts button.

  8. Best Practices and Anti-patterns for Workspace Instructions

    main

    To ensure Copilot follows your instructions effectively, adhere to these principles:

    Core Principles

    • Minimal by default: Only include what is relevant to every task.
    • Concise and actionable: Every line should guide behavior.
    • Link, don't embed: Reference existing documentation (docs/**/*.md, CONTRIBUTING.md) instead of copying it. Only inline critical 'gotchas' not documented elsewhere.
    • Keep current: Update instructions when project practices change.

    Anti-patterns to Avoid

    • Using both file types: Do not use both copilot-instructions.md and AGENTS.md.
    • Kitchen sink: Avoid including everything; focus on what matters most.
    • Duplicating docs: Do not copy the README; link to it instead.
    • Obvious instructions: Do not include conventions that are already enforced by linters.
  9. Implement Progressive Loading in SKILL.md

    main

    To optimize performance and token usage, skills use progressive loading:

    1. Discovery: The agent reads the name and description (~100 tokens).
    2. Instructions: The agent loads the SKILL.md body when the task is relevant (<5000 tokens).
    3. Resources: Additional files (scripts, docs) load only when explicitly referenced.

    Best Practices:

    • Keep SKILL.md under 500 lines.
    • Use relative paths for all resources (e.g., [script](./scripts/test.js)).
    • Keep file references only one level deep from SKILL.md.
  10. Use inline suggestions and inline chat

    main

    Beyond autonomous agents, you can use Copilot for direct editor assistance:

    • Inline Suggestions: Receive intelligent code completions via ghost text suggestions and next edit suggestions. Accept suggestions using the Tab key.
    • Inline Chat: Open a targeted chat prompt directly in the editor by pressing Ctrl+I (Windows/Linux) or Cmd+I (macOS). Use this to describe refactors, add error handling, or explain algorithms without leaving the editor.