Copilot and AI Overview
Purpose and Scope
This page orients contributors and advanced users to the Copilot and AI surfaces represented in this repository. In VS Code, “AI features” is an umbrella for inline suggestions, chat-driven help, autonomous agent workflows, code action integration, and policy-controlled access. The product documentation describes these as features users enable by signing in with a GitHub account that has Copilot access, then use from the editor, the unified Chat view, and agent-specific surfaces. The repository evidence shows several of the boundaries that make those experiences safe and composable: editor action kinds, Copilot extension runtime gates, CLI agent commands, Electron startup, and generated agent protocol types.
Sources: src/vs/editor/contrib/codeAction/common/types.ts, extensions/copilot/src/extension/completions-core/vscode-node/extension/src/codeReferencing/index.ts, cli/src/bin/code/main.rs
A useful mental model is to separate the “user surface” from the “control plane.” The user surface includes the editor lightbulb, inline suggestions, chat, and background agents. The control plane decides which commands are available, whether code references are enabled, which tools an agent may use, and whether a request is handled inside the desktop process or by a local agent host. The files on this page do not implement every Copilot UI feature, but they expose important contracts that other workbench, extension, and agent-host code can rely on when building those features.
Sources: src/vs/code/electron-main/main.ts, src/vs/platform/agentHost/node/codex/protocol/generated/v2/AppsConfig.ts, src/vs/platform/agentHost/node/codex/protocol/generated/v2/AppsDefaultConfig.ts
Relevant Source Files
src/vs/editor/contrib/codeAction/common/types.tsdefines shared editor code-action kinds, trigger sources, filters, and auto-apply modes used by lightbulb, quick fix, refactor, source action, and save-participant flows.cli/src/bin/code/main.rsis the Rust entry point for the publiccodelauncher and dispatches integrated and standalone CLI commands, includingagentsubcommands for host, process listing, stop, kill, and logs.extensions/copilot/src/extension/completions-core/vscode-node/extension/src/codeReferencing/index.tsimplements the Copilot code-reference registration gate, reacting to Copilot token metadata and enabling the engagement tracker only when public-code references are allowed.src/vs/code/electron-main/main.tsis the Electron main-process entry area that imports core platform services and parses startup arguments before constructing the desktop application environment.src/vs/platform/agentHost/node/codex/protocol/generated/v2/AppsConfig.tsdefines generated agent app configuration for per-app enablement, destructive tool behavior, open-world behavior, default approval mode, default tool enablement, and tool-specific configuration.src/vs/platform/agentHost/node/codex/protocol/generated/v2/AppsDefaultConfig.tsdefines generated default agent app configuration for global enablement, destructive actions, and open-world behavior.
Core AI Primitives
Inline suggestions and AI edits are experienced in the editor, but their integration point overlaps with standard editor affordances such as code actions. The CodeActionKind hierarchy defines first-class action families including quickfix, refactor, refactor.extract, refactor.inline, refactor.move, refactor.rewrite, notebook, source, source.organizeImports, source.fixAll, and refactor.surround. This matters for AI because suggested fixes, generated rewrites, and organize-or-fix-all operations can be presented through familiar editor flows instead of requiring a separate command vocabulary. The filter helpers also make source actions opt-in, which prevents broad save-time or source-level actions from appearing unless the caller explicitly requests them.
Sources: src/vs/editor/contrib/codeAction/common/types.ts
The code-action contract also records how an action was triggered. CodeActionTriggerSource distinguishes refactor requests, refactor preview, lightbulb, default invocation, source actions, quick fixes, fix-all, organize imports, auto fix, quick-fix hover, save participants, and the Problems view. These values let the editor and extensions preserve intent when a human, a background participant, or a UI affordance asks for actions. CodeActionAutoApply then describes whether a command may apply if there is one result, apply the first result, or never auto-apply. For AI-powered editing, those distinctions are important because the system can offer assistance while still respecting review-oriented workflows.
Sources: src/vs/editor/contrib/codeAction/common/types.ts
Chat and agents use a different set of primitives. The official product flow encourages users to start from the Copilot status entry point, sign in, then use chat commands such as /init to tailor project instructions. Background Copilot CLI sessions can be started, monitored, and managed from the unified Chat view while they continue running locally. In the repository CLI entry point, the public launcher parses either integrated or standalone command shapes, builds a CommandContext, installs logging for normal command execution, and dispatches agent subcommands. The visible subcommands include process listing, host startup, stop, kill, and logs, which are exactly the operational verbs expected for autonomous background sessions.
Sources: cli/src/bin/code/main.rs
Code Referencing and Access Boundaries
Code referencing is one of the clearest examples of a Copilot feature being gated by account or organization state instead of being purely a local editor behavior. The CodeReference class subscribes to Copilot token updates through onCopilotToken unless running in test mode. When token metadata says codeQuoteEnabled is false, the class disposes existing registrations, clears its subscription aggregate, marks the feature disabled, and logs that public code references are disabled. When the token permits code quotes, it logs that public code references are enabled and instantiates CodeRefEngagementTracker. That design makes the code-reference user experience conditional on service-provided entitlement and policy metadata.
Sources: extensions/copilot/src/extension/completions-core/vscode-node/extension/src/codeReferencing/index.ts
This token-driven gate maps to the product documentation’s access story. Users need Copilot access through a GitHub account, Copilot Free, an individual subscription, or an enterprise-managed account. Some settings, such as telemetry and public-code suggestion behavior, may be managed at the organization level. The repository snippet does not encode plan names, but it does show the runtime pattern: Copilot-specific behavior is not assumed to be universally available. Instead, the extension receives authentication-derived capability information, enables or disables feature registrations, and tears down previously installed behavior when a capability is revoked or absent.
Sources: extensions/copilot/src/extension/completions-core/vscode-node/extension/src/codeReferencing/index.ts
Agent Workflows and Tool Approval Model
Agent workflows combine local execution with approval boundaries. The generated Codex protocol types define AppsDefaultConfig with enabled, destructive_enabled, and open_world_enabled flags. The broader AppsConfig type adds a _default value and per-app records with enabled, nullable destructive and open-world overrides, default_tools_approval_mode, default_tools_enabled, and per-tool configuration. Although this generated file is protocol plumbing, it names the policy concepts that matter to users: an agent may be enabled, may or may not use destructive tools, may or may not operate in an open-world mode, and may require a default approval mode before tools run.
Sources: src/vs/platform/agentHost/node/codex/protocol/generated/v2/AppsConfig.ts, src/vs/platform/agentHost/node/codex/protocol/generated/v2/AppsDefaultConfig.ts
The Copilot CLI documentation describes background sessions as running outside VS Code on the local machine while still being managed from chat. The code launcher source supports that architecture by routing agent commands from the CLI to implementation modules such as agent_host, agent_ps, agent_stop, agent_kill, and agent_logs. A background agent needs more than a UI tab: it needs a host process, observability, and lifecycle controls. The CLI dispatch layer is therefore part of the operational boundary between editor-driven requests and local processes that can continue independent work.
Sources: cli/src/bin/code/main.rs
The desktop application boundary is also relevant. The Electron main entry imports platform services for configuration, diagnostics, environment parsing, file access, instantiation, lifecycle, logging, product metadata, protocol handling, and update contributions. It parses main-process arguments and creates the application service graph used by the desktop shell. Copilot and AI features are surfaced through extensions and workbench contributions, but they still run inside an application that must provide configuration, authentication-related services, logging, lifecycle handling, and startup argument interpretation. Contributors investigating AI behavior should therefore distinguish feature logic from the platform services that make the feature observable and configurable.
Sources: src/vs/code/electron-main/main.ts
System-to-Code Mapping
| User capability | Repository contract visible here | Why it matters |
|---|---|---|
| Inline suggestions and AI edits | CodeActionKind, CodeActionFilter, filtersAction, mayIncludeActionsOfKind | AI assistance can participate in normal quick-fix, refactor, source-action, and preferred-action flows. |
| Chat-managed background agents | code agent dispatch to agent_host, agent_ps, agent_stop, agent_kill, agent_logs | The CLI exposes lifecycle and diagnostics verbs for local agent sessions. |
| Public code references | CodeReference.register, onCopilotToken, codeQuoteEnabled, CodeRefEngagementTracker | Code-reference UI and engagement tracking are enabled only when the Copilot token allows them. |
| Agent tool policy | AppsConfig, AppsDefaultConfig, default_tools_approval_mode, destructive_enabled, open_world_enabled | Agent tools can be governed by default and per-app approval and capability settings. |
| Desktop runtime boundary | Electron main-process imports and startup argument parsing | AI features rely on the same configuration, logging, lifecycle, and service wiring as other workbench features. |
Execution Flow
A typical Copilot journey starts with access. The user enables AI features, signs in, and receives account-specific capabilities. In the code-reference path, those capabilities arrive as Copilot token metadata. If public-code references are disabled, the extension unregisters related disposables; if enabled, it installs engagement tracking. After access is established, the user may request help in the editor, where actions are filtered by hierarchical kind and trigger source, or in chat, where the request may remain conversational, produce edits, or be handed to an agent session.
Sources: extensions/copilot/src/extension/completions-core/vscode-node/extension/src/codeReferencing/index.ts, src/vs/editor/contrib/codeAction/common/types.ts
For autonomous work, VS Code’s chat surface can coordinate with local agent processes. The public code command parses arguments, creates a context with HTTP client, launcher paths, logging, and core arguments, then dispatches to the appropriate command implementation. When the command is an agent command, the CLI handles host, list, stop, kill, and log operations. Agent tools are then further constrained by app configuration types that distinguish default enablement, destructive capability, open-world capability, approval mode, and per-tool configuration. The result is a layered flow: account access, UI request, process lifecycle, and tool approval each have separate code-level boundaries.
Sources: cli/src/bin/code/main.rs, src/vs/platform/agentHost/node/codex/protocol/generated/v2/AppsConfig.ts, src/vs/platform/agentHost/node/codex/protocol/generated/v2/AppsDefaultConfig.ts
Implementation Details
CodeReference uses disposable aggregation to make feature enablement reversible. addDisposable creates or extends a Disposable.from(...) aggregate, while dispose releases both the current aggregate and the token event subscription. This is a small but important implementation pattern for entitlement-sensitive features: turning a feature off should remove listeners, trackers, or UI hooks that were registered while it was on. The class also avoids token subscription in tests through _runtimeMode.isRunningInTest(), which keeps test execution from depending on live Copilot authentication behavior.
Sources: extensions/copilot/src/extension/completions-core/vscode-node/extension/src/codeReferencing/index.ts
filtersAction and mayIncludeActionsOfKind implement defensive filtering around hierarchical action kinds. A provided kind may intersect an included kind, but source actions are hidden unless includeSourceActions is set. Preferred-action filtering depends on action.isPreferred. For AI features, that means the editor can request a narrow class of actions, suppress broad source-level actions by default, and prefer a language server or provider’s designated best fix when the caller asks for preferred actions only. Those semantics are part of the safety and predictability story for generated edits.
Sources: src/vs/editor/contrib/codeAction/common/types.ts
Next Steps
Read the focused pages for the surfaces you are investigating next. Use chat-view for the unified chat UI, inline-chat-and-ai-edits for editor-embedded AI edits, chat-tools-and-approvals for tool permission boundaries, mcp-servers for model-context integrations, and enterprise-policies-and-ai-settings for organization-managed controls. If you are debugging background sessions, start from the command-line-interface and agents-window pages before drilling into agent host protocol types.
Sources: cli/src/bin/code/main.rs, src/vs/platform/agentHost/node/codex/protocol/generated/v2/AppsConfig.ts