Copilot CLI
Install context-mode in GitHub Copilot CLI with one plugin command — it registers the MCP server, the routing skill, and camelCase JSON hooks.
GitHub Copilot CLI integrates context-mode through JSON stdin/stdout hooks that use camelCase event names. The hooks route data-heavy tool output into the sandbox and keep the bulk of raw payload bytes out of your window — the model writes a program that processes the data and prints only the answer. A single plugin command registers the MCP server, the routing skill, and the capture hooks at once.
Each event dispatches through context-mode hook copilot-cli <event>, with the
event token lowercased (e.g. context-mode hook copilot-cli pretooluse). The
install registers six capture hooks under their native camelCase keys, each
mapped to a lowercase dispatch event:
| Hook key (camelCase) | Dispatch event |
|---|---|
preToolUse | context-mode hook copilot-cli pretooluse |
postToolUse | context-mode hook copilot-cli posttooluse |
preCompact | context-mode hook copilot-cli precompact |
sessionStart | context-mode hook copilot-cli sessionstart |
userPromptSubmitted | context-mode hook copilot-cli userpromptsubmit |
agentStop | context-mode hook copilot-cli stop |
Prerequisites:
- Node.js 22.5 or newer (or Bun).
- GitHub Copilot CLI (
copilot) installed. - If you use an isolated Copilot home, set
COPILOT_HOMEfirst — it relocates the hook config, the MCP config, and the session-DB root together.
context-mode runs 100% locally with zero telemetry. Indexing and execution never leave your machine.
Install
The plugin install is a pure plugin command, but the Copilot MCP server runs the
global context-mode binary, so npm install -g context-mode is a prerequisite.
Install the package
Install context-mode globally. The MCP server launches this binary, and the hooks dispatch through it.
npm install -g context-modeInstall the plugin
Run the plugin install. This single command registers the MCP server, the
routing skill, and the capture hooks — there is no separate context-mode upgrade step or agent call to run afterward.
copilot plugin install mksglu/context-mode:configs/copilot-cliThis registers the six capture hooks (preToolUse, postToolUse, preCompact,
sessionStart, userPromptSubmitted, and agentStop) under their native
camelCase keys, each dispatching the matching lowercase event — see the hook
mapping above.
Platform detection
The MCP server is launched with CONTEXT_MODE_PLATFORM=copilot-cli, so it
self-identifies as Copilot CLI regardless of any other CLI installed on the
machine. Platform detection and ctx_upgrade always resolve copilot-cli,
never a co-installed Claude Code.
Alternative (no plugin)
The plugin path above is strongly preferred — it wires the six capture hooks
automatically. This alternative registers the MCP server only and leaves you
without hooks until you run ctx_upgrade from inside Copilot, so reach for it
only if you cannot use the plugin install.
If you prefer to register the MCP server directly instead of using the plugin,
add it with Copilot CLI's own command. It writes ~/.copilot/mcp-config.json
(or $COPILOT_HOME/mcp-config.json), and that context-mode-written marker keeps
detection unambiguous.
copilot mcp add context-mode --env CONTEXT_MODE_PLATFORM=copilot-cli -- context-modeThis path is MCP-only and ships no hooks. To also install the capture hooks
(~/.copilot/hooks/context-mode.json), take one of these two paths:
- Run
context-mode upgradefrom a Copilot CLI context — it writes the hooks file only. - Run the upgrade from inside Copilot so it detects
copilot-clithrough the live MCP client:
copilot -p "Use the context-mode ctx_upgrade tool to install context-mode's hooks." --allow-allVerify
Confirm the install with the doctor. It checks language runtimes, the FTS5 knowledge base, and hook registration, then reports anything that needs attention.
context-mode doctorA clean run means context-mode is ready to route your next data-heavy command.
Caveats
context-mode writes Copilot CLI's native camelCase hook keys (preToolUse,
postToolUse, and so on). The Copilot CLI also accepts PascalCase event names,
so the casing is not load-bearing — but the plugin and context-mode upgrade
always write camelCase to match the CLI's native naming.
Verify your savings
Confirm context-mode is actually saving you tokens, not just installed.
- In a Copilot CLI session, type
ctx statsto see tokens saved, the savings ratio, and a per-tool breakdown for the session. The context-mode tools should appear and respond. - Run
context-mode doctorto confirm the hooks (~/.copilot/hooks/context-mode.json) and the MCP server (~/.copilot/mcp-config.json) are registered.
Related
Codex CLI
Install context-mode on Codex CLI through its plugin marketplace — add the marketplace, enable two feature flags, and optionally copy the routing file.
Cursor
Install context-mode on Cursor with native JSON hooks in .cursor/hooks.json, including shipped sessionStart and stop support. Local-folder plugin today, one-click Marketplace plugin once published.