context-mode
Installation

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 example pretooluse)
  • 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.

Check the runtime
node --version

Install the package

This installs the MCP server, the hook dispatcher, and the context-mode command line.

Global install
npm install -g context-mode

Register 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.

.vscode/mcp.json
{
  "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.

.github/hooks/context-mode.json
{
  "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.

Optional routing file
cp node_modules/context-mode/configs/vscode-copilot/copilot-instructions.md .github/copilot-instructions.md

Confirm 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_execute
  • context-mode_ctx_search
  • context-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).

PurposeSignal
Project directory (cascade)CLAUDE_PROJECT_DIR first, then VSCODE_CWD, then the current working directory
Host identificationVSCODE_PID
Explicit overrideCONTEXT_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
Verify the setup
context-mode doctor

A fail row comes with the fix to apply:

FailureFix
Missing hookcontext-mode upgrade
Missing MCP entryAdd 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.

On this page