context-mode

CLI commands

The context-mode command line — doctor, upgrade, insight, index, search, and the hook dispatcher.

Installing the package puts a single callable binary on your PATH: context-mode. This page covers every terminal subcommand, plus the slash commands and chat triggers that surface the rest inside your agent.

SubcommandPurpose
doctorDiagnose runtimes, the FTS5 knowledge base, and host hooks
upgradePull, build, and reconfigure hooks in one step
insightOpen the Insight analytics dashboard
indexIndex a file or directory into the knowledge base
searchSearch the knowledge base for focused snippets
hookRoute data-heavy host output into the sandbox
statuslineRender the Claude Code status line

There is no ctx binary on your PATH. ctx ... (for example ctx stats or ctx doctor) is a chat trigger you type to your agent, which calls the matching MCP tool. In a terminal, always use context-mode .... Note that stats and purge have no terminal subcommand — reach them through the chat trigger or the /context-mode:ctx-stats and /context-mode:ctx-purge slash commands.

Diagnostics and maintenance

context-mode doctor

Diagnose your installation. The doctor checks three things for every connected host, then prints a checklist of what passed and what needs attention:

  • Language runtimes
  • The FTS5 knowledge base
  • Hook registration
Diagnose the install
context-mode doctor

Run this first whenever an agent stops routing output or the knowledge base looks empty. The same check is available as the ctx_doctor tool.

context-mode upgrade

Pull the latest context-mode, build it, and reconfigure host hooks in one step. Run it after a new release to keep three things in sync:

  • The server
  • The dispatcher
  • Your hook configs
Update and reconfigure
context-mode upgrade

The equivalent tool is ctx_upgrade.

Session status

context-mode insight

Open the Insight dashboard in your browser. Insight is the hosted analytics layer at https://context-mode.com/insight; the command prints the URL and opens it in your default browser. It takes no arguments.

Open the dashboard
context-mode insight

See ctx_insight for the underlying tool.

context-mode statusline

Print the Claude Code status line. You rarely run it by hand — Claude Code calls it internally to render the context-mode segment of its status bar.

  • Reads a status-line event on stdin
  • Writes the formatted line to stdout
Render the status line
context-mode statusline

stats and purge — chat and slash commands

stats and purge have no terminal subcommand. Reach them three ways:

  • Type ctx stats or ctx purge to your agent
  • Use the /context-mode:ctx-stats and /context-mode:ctx-purge slash commands
  • In Claude Code and Cursor, both forms are available

ctx stats shows how much context window you saved this session, with a per-tool breakdown of tokens consumed versus tokens avoided.

  • Read-only — it reports and never resets
  • context-mode routinely keeps about 98% of a payload's bytes out of context, and this is where you see that number for your own session
  • Matching tool: ctx_stats

ctx purge irreversibly wipes the knowledge base and resets session stats: everything you have indexed is deleted and your savings counters return to zero.

Purge cannot be undone. It deletes all indexed content and resets stats. Run it only when you want a clean slate. The tool form is ctx_purge.

Knowledge base from the terminal

You do not need an agent in the loop to populate or query the knowledge base. The index and search commands operate on it directly.

context-mode index

Index a file or directory into the FTS5 knowledge base. Tag the content with a descriptive --source label so you can scope later searches to it.

Index a directory
context-mode index ./src --source codebase

The matching tool is ctx_index.

Search the knowledge base with BM25 ranking and get back focused snippets instead of whole files. Narrow the results with --source when you know which label holds the answer.

Search the knowledge base
context-mode search "retry backoff" --source codebase

The matching tool is ctx_search.

The hook dispatcher

Hosts call context-mode hook <platform> <event> internally to route data-heavy output into the sandbox. You rarely run it by hand, but it is useful for testing: pipe a JSON event into it and inspect what comes back.

Test a hook event
echo '{"tool":"Bash","command":"cat large.log"}' | context-mode hook claude-code pretooluse
StreamContract
stdinA JSON event
stdoutA JSON decision

This is the same contract every supported host uses.

Slash commands

In Claude Code and Cursor, every status command is also available as a slash command. They do exactly what their CLI or chat-trigger counterparts do, without leaving the chat.

Slash commandEquivalent
/context-mode:ctx-statsctx stats (chat trigger)
/context-mode:ctx-doctorcontext-mode doctor
/context-mode:ctx-upgradecontext-mode upgrade
/context-mode:ctx-purgectx purge (chat trigger)
/context-mode:ctx-indexcontext-mode index
/context-mode:ctx-searchcontext-mode search
/context-mode:ctx-insightcontext-mode insight

Slash commands exist only on plugin hosts that register them — Claude Code and Cursor. On other hosts (Codex, Gemini, MCP-only clients) use the context-mode CLI binary in a terminal, or type the ctx ... chat trigger to your agent.

On this page