VS Code Copilot
Install context-mode in the VS Code Copilot agent, a package host that integrates through JSON hooks and a workspace MCP server.
The VS Code Copilot agent is GitHub Copilot's agentic mode inside VS Code. It
integrates context-mode through a workspace MCP server and JSON lifecycle hooks —
PreToolUse, PostToolUse, PreCompact, and SessionStart — that route
data-heavy tool output into the sandbox and keep about 98% of raw payload bytes
out of your window. The model writes a program that processes the data and prints
only the answer.
- Hooks wired:
PreToolUse,PostToolUse,PreCompact,SessionStart - Dispatch command:
context-mode hook vscode-copilot <event>, where the CLI event token is lowercase (for examplepretooluse) - JSON config keys: stay PascalCase (
PreToolUse,PostToolUse, and so on) - Session continuity: the four hooks below give you full continuity — capture, snapshot, and restore
context-mode runs 100% locally with zero telemetry. Indexing and execution never leave your machine.
Install
The Copilot agent has no plugin marketplace, so install the package globally first, then register the server and hooks in your workspace.
Check the prerequisites
You need Node 22.5+ or Bun on your PATH, and VS Code with Copilot Chat v0.32+.
The hook dispatcher and sandbox run on this runtime.
node --versionInstall the package
This installs the MCP server, the hook dispatcher, and the context-mode command
line.
npm install -g context-modeRegister the MCP server
Register the context-mode MCP server in the workspace mcp.json under the
.vscode directory. The global form runs the context-mode binary with no
arguments. Reload the window after saving so VS Code picks up the new server.
{
"servers": {
"context-mode": {
"command": "context-mode"
}
}
}Add the hooks
Add the context-mode hooks file at .github/hooks/context-mode.json. The four
hooks point at the context-mode dispatcher, which decides whether a tool call
should run in the sandbox. The JSON keys are PascalCase (PreToolUse,
PostToolUse, PreCompact, SessionStart); only the dispatch-command event
token is lowercase, as in context-mode hook vscode-copilot pretooluse.
{
"hooks": {
"PreToolUse": [
{ "type": "command", "command": "context-mode hook vscode-copilot pretooluse" }
],
"PostToolUse": [
{ "type": "command", "command": "context-mode hook vscode-copilot posttooluse" }
],
"PreCompact": [
{ "type": "command", "command": "context-mode hook vscode-copilot precompact" }
],
"SessionStart": [
{ "type": "command", "command": "context-mode hook vscode-copilot sessionstart" }
]
}
}Copy the routing instructions (optional)
Routing is automatic through the SessionStart hook. For full model awareness, copy the shipped instructions into your repository so Copilot reads them on every turn.
cp node_modules/context-mode/configs/vscode-copilot/copilot-instructions.md .github/copilot-instructions.mdConfirm the server is connected
Reload the window, then open the MCP Servers view from the Extensions panel (or
run the "MCP: List Servers" command from the Command Palette). Confirm the
context-mode server is running and its tools are exposed.
Tool names
On VS Code Copilot, context-mode applies a fixed context-mode_ prefix to every
tool, so the ctx_* tools surface as:
context-mode_ctx_executecontext-mode_ctx_searchcontext-mode_ctx_batch_execute- …and so on
These are the same ctx_* tools documented elsewhere; the SessionStart routing
block tells the model these exact prefixed names so it calls them correctly.
The .vscode/mcp.json server and the .github/hooks/context-mode.json file are
separate. The agent needs both — the server for the tools and the hooks file for
the routing that keeps raw bytes out of your window.
Detection
context-mode self-identifies as VS Code Copilot from the workspace environment.
The session ID arrives as sessionId (camelCase).
| Purpose | Signal |
|---|---|
| Project directory (cascade) | CLAUDE_PROJECT_DIR first, then VSCODE_CWD, then the current working directory |
| Host identification | VSCODE_PID |
| Explicit override | CONTEXT_MODE_PLATFORM=vscode-copilot |
| Hook configuration | .github/hooks/*.json, with .claude/settings.json as a secondary source |
Verify your savings
Confirm context-mode is actually saving you tokens, not just that the tools respond.
Check the session savings
In Copilot Chat, type ctx stats. It reports the context-window tokens saved this
session and the savings ratio, with a per-tool breakdown so you can see routing at
work.
Confirm hooks and MCP are registered
Run the doctor. It checks:
- Language runtimes
- The FTS5 knowledge base
- The hooks in
.github/hooks/context-mode.json - The MCP server in
.vscode/mcp.json
context-mode doctorA fail row comes with the fix to apply:
| Failure | Fix |
|---|---|
| Missing hook | context-mode upgrade |
| Missing MCP entry | Add context-mode server to .vscode/mcp.json |
Two warn rows always appear for this host — the hooks API is in preview and may
change, and matchers are parsed but ignored (every hook fires on every tool). Treat
them as expected, not failures.
A clean doctor run plus a non-zero ctx stats savings ratio means context-mode is
routing your data-heavy commands and keeping raw bytes out of your window.