context-mode
Installation

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.

Cursor is a first-class context-mode host. It uses native lower-camel hook names and flat hook entries in .cursor/hooks.json (not Claude Code's settings.json format), so context-mode routes data-heavy tool output into the sandbox and keeps the bulk of raw payload bytes out of your context window.

  • Cursor v1 ships a native sessionStart hook.
  • context-mode wires preToolUse, postToolUse, sessionStart, and stop.
  • It ships a routing rules file (.cursor/rules/context-mode.mdc) as belt-and-braces awareness alongside the sessionStart hook.

The Cursor Marketplace listing is still awaiting Cursor team review (#485 / #489). Until it is listed, install via the local-folder or manual path below. Once the Marketplace plugin ships, a one-click install will register the MCP server, hooks (preToolUse, postToolUse, sessionStart, stop, afterAgentResponse), rules, and skills with no manual config.

Install

Prerequisites: Node.js >= 22.5 (or Bun), and Cursor with agent mode.

Choose the local-folder plugin path or the manual config path. Both deliver the same routing; pick whichever fits your workflow.

The local-folder install symlinks (or copies) the plugin checkout into Cursor's local plugins directory. No global install is required.

  • Loads hooks/cursor/hooks.json.
  • Registers all five events: preToolUse, postToolUse, sessionStart, afterAgentResponse, stop.
  • Runs each via npx -y context-mode hook cursor <event>.

Clone the repository

Clone context-mode somewhere on your machine.

git clone https://github.com/mksglu/context-mode.git

On macOS and Linux, symlink the checkout into Cursor's local plugins directory.

ln -s "$PWD/context-mode" ~/.cursor/plugins/local/context-mode

On Windows, Cursor does not follow symlinks or junctions, so copy the folder with robocopy instead.

robocopy . "$env:USERPROFILE\.cursor\plugins\local\context-mode" /MIR

Restart Cursor

Restart so the MCP server, hooks, and rules register. The plugin appears in Settings → Plugins as "Context Mode (Local)".

The manual path installs context-mode globally and registers the MCP server, hooks, and routing rules by hand.

Install the package

npm install -g context-mode

Register the MCP server

Create .cursor/mcp.json in your project root (or ~/.cursor/mcp.json for a global install).

.cursor/mcp.json
{
  "mcpServers": {
    "context-mode": {
      "command": "context-mode"
    }
  }
}

Register the hooks

Create .cursor/hooks.json (or ~/.cursor/hooks.json for global). Each command is context-mode hook cursor <event> with a lowercase event name. This is the shipped template (configs/cursor/hooks.json): the preToolUse entry carries a matcher so the hook only fires for the tools context-mode routes.

.cursor/hooks.json
{
  "version": 1,
  "hooks": {
    "preToolUse": [
      {
        "command": "context-mode hook cursor pretooluse",
        "matcher": "Shell|Read|Grep|WebFetch|mcp_web_fetch|mcp_fetch_tool|Task|MCP:ctx_execute|MCP:ctx_execute_file|MCP:ctx_batch_execute|MCP:(?!ctx_)"
      }
    ],
    "postToolUse": [
      { "command": "context-mode hook cursor posttooluse" }
    ],
    "stop": [
      { "command": "context-mode hook cursor stop" }
    ]
  }
}

The template above wires the required set. Two more native hooks are available:

  • sessionStart — state restore after compaction.
  • afterAgentResponse — fire-and-forget; receives the full response text.

Run context-mode upgrade to add the sessionStart and afterAgentResponse entries automatically.

Copy the routing rules file

The sessionStart hook handles state restore, but copying the .mdc rules file gives the model belt-and-braces routing awareness — Cursor accepts additional_context in hook responses but does not surface it to the model, so the rules file and MCP tool descriptions carry routing enforcement.

mkdir -p .cursor/rules
cp node_modules/context-mode/configs/cursor/context-mode.mdc .cursor/rules/context-mode.mdc

Restart Cursor

Restart Cursor or open a new agent session so the server, hooks, and rules load.

Do not run both the local plugin and a .cursor/hooks.json install at once. Each event would fire twice. context-mode doctor warns when both register context-mode hooks — remove one configuration to keep events single-fire.

Hooks

HookWhat it does
preToolUseInspects and reroutes data-heavy tool calls into the sandbox before they run, and can block with { "permission": "deny", "user_message": "..." }.
postToolUseCaptures tool events into the session knowledge base.
sessionStartShipped natively in Cursor v1. context-mode wires it as the SessionStart equivalent to restore state after compaction.
stopMarks turn end and can return followup_message to continue the loop.

The dispatcher also supports afterAgentResponse. The full set of routed events is pretooluse, posttooluse, sessionstart, stop, and afteragentresponse.

Cursor accepts additional_context in postToolUse and sessionStart hook responses but does not surface it to the model (a Cursor upstream bug). Routing enforcement relies on the .mdc rules file and MCP tool descriptions instead of hook context injection.

Configure

Configuration is optional. context-mode resolves its identity and storage from Cursor's hook payloads:

WhatSource
Session IDconversation_id field, falling back to CURSOR_TRACE_ID, then the parent process ID
Project directoryworkspace_roots field on stdin
Captured sessionsStored under ~/.cursor/context-mode/sessions/

See /docs/configuration for storage relocation with CONTEXT_MODE_DIR and the full list of environment variables.

Verify your savings

Confirm context-mode is actually saving you tokens, not just that the tools respond.

Check the savings in chat

In an agent session, type ctx stats. It reports the context-window tokens saved this session — the savings ratio plus a per-tool token breakdown — so you can see routing pay off after a few data-heavy operations.

Confirm hooks and MCP are registered

Run the doctor.

context-mode doctor

It checks the native hooks in .cursor/hooks.json and the MCP server:

  • preToolUse — required (a fail if missing).
  • postToolUse — optional (a warn if missing).
  • sessionStart, stop, afterAgentResponse — not validated.
  • Confirms the MCP server in .cursor/mcp.json (or a plugin manifest).
  • Flags plugin/native duplicate firing (each event fires twice — remove one config).
  • Warns about enterprise or Claude-compat hook configs.

A clean doctor run plus a climbing savings ratio means context-mode is ready to route your next data-heavy command.

Cursor does not register Claude-style slash commands and has no status line. Run the doctor and the other status commands from the terminal with context-mode <command>, or ask the agent in chat to run them.

On this page