context-mode
Installation

KiloCode

Install context-mode in KiloCode as a native TypeScript plugin, sharing the fork-aware OpenCode adapter.

KiloCode is an OpenCode fork, so context-mode routes the kilo platform through the same OpenCodeAdapter and loads as a native TypeScript plugin rather than JSON stdin/stdout hooks:

  • The plugin array in kilo.json registers all 11 ctx_* tools in-process and wires the hooks, so there is no separate MCP child per session.
  • The plugin keeps the bulk of raw payload bytes out of your window by routing data-heavy output into the sandbox and answering from the FTS5 knowledge base.

Hooks match OpenCode and run as in-process functions. Like OpenCode, KiloCode exposes no real SessionStart hook, so context-mode uses the same surrogates:

In-process hookStands in forRole
tool.execute.beforePreToolUseEnforces routing and can block
tool.execute.afterPostToolUseRecords post-execution telemetry
experimental.session.compactingPreCompactBuilds resume snapshots
experimental.chat.system.transformSessionStart (surrogate)Injects the routing block and restores prior-session snapshots
chat.messageUserPromptSubmit (surrogate)Records each request and decision for later search
event (generic bus)—Filters message.updated to capture per-turn token and cost telemetry

KiloCode and OpenCode share one adapter. Behavior, surrogate hooks, and caveats match the OpenCode page — the only difference is the config filename.

Install

KiloCode has no plugin marketplace, so install the package globally first, then point kilo.json at it.

Check the prerequisites

Install Node 22.5 or newer, or Bun, and make sure KiloCode is installed. The sandbox and FTS5 knowledge base depend on a current runtime.

Check your runtime
node --version

Install the package

This installs the plugin entry point and the context-mode command line.

Global install
npm install -g context-mode

Register the plugin

Add the context-mode plugin to kilo.json in your project root (or ~/.config/kilo/kilo.json for a global install). The native TypeScript plugin registers all 11 ctx_* tools in-process, so you do not add a separate mcp entry.

Valid config locations that context-mode discovers and writes:

  • kilo.json (project root) or ~/.config/kilo/kilo.json (global)
  • kilo.jsonc
  • the .kilo/ project subdirectory
  • the .kilocode/ project subdirectory
kilo.json
{
  "$schema": "https://app.kilo.ai/config.json",
  "plugin": ["context-mode"]
}

Restart KiloCode after editing the config so the plugin loads.

Do not keep both the plugin entry and a legacy mcp.context-mode block at the same time. When both are present, KiloCode registers zero ctx_* tools — the plugin suppresses the MCP duplicates, but the legacy mcp.context-mode child then returns an empty tool list, leaving nothing registered.

Copy the routing rules (optional)

The plugin injects the routing block at runtime, so this step is not required. If you also want a static AGENTS.md for model routing awareness — KiloCode ships its own, distinct from the OpenCode copy — drop it into your project root.

Optional routing file
cp node_modules/context-mode/configs/kilo/AGENTS.md AGENTS.md

Configure

The plugin-only config above needs no extra environment variable:

  • The native plugin already exposes the ctx_* tools in-process.
  • It sets CONTEXT_MODE_EMBEDDED_PLUGIN_TOOLS=1 transiently while it imports the tool registry, then restores the previous value immediately afterward.

If you ever run the standalone MCP server alongside the plugin (for example, a leftover mcp.context-mode entry), set this variable where the spawned server can read it — an env block in the kilo.json MCP entry, not a transient shell export — so the duplicate copy of each tool is suppressed:

kilo.json (only if you also run the standalone server)
{
  "$schema": "https://app.kilo.ai/config.json",
  "plugin": ["context-mode"],
  "mcp": {
    "context-mode": {
      "type": "local",
      "command": ["context-mode"],
      "env": { "CONTEXT_MODE_EMBEDDED_PLUGIN_TOOLS": "1" }
    }
  }
}

For the normal plugin-only install, prefer removing the mcp entry entirely (run context-mode upgrade) over running both. See /docs/configuration for the full list of environment variables, storage paths, and permission rules.

Verify

Confirm the install with the doctor. It checks language runtimes, the FTS5 knowledge base, and plugin registration, then reports anything that needs attention.

Verify the setup
context-mode doctor

A clean run means the plugin is loaded and context-mode is ready to route your next data-heavy command.

If the ctx_* tools appear empty after install, a legacy mcp.context-mode entry from an earlier version is usually conflicting with the native plugin — with both present, KiloCode registers zero ctx_* tools. Run context-mode upgrade to reconcile the config and remove the legacy server entry; other MCP servers are preserved (v1.0.140+ also emits a stderr diagnostic when this happens). Restart KiloCode once it finishes.

Verify your savings

These two checks confirm context-mode is actually saving you tokens, not just that the tools loaded.

Check the session savings

In the KiloCode session, type ctx stats to your agent. It reports tokens saved and the context-window savings ratio for the session, plus a per-tool token breakdown — so you can see routing is keeping raw data out of your window.

In the KiloCode chat
ctx stats

Confirm hooks and MCP are registered

Run the doctor to confirm context-mode is in the plugin array of kilo.json (or kilo.jsonc) and that the hooks and ctx_* tools are wired. It warns on a legacy mcp.context-mode block and prints context-mode upgrade as the fix.

Confirm registration
context-mode doctor

KiloCode has no persistent status line, so ctx stats in chat is the quickest read on your live savings.

On this page