/ Directory / Playground / Context Mode
● Community mksglu ⚡ Instant

Context Mode

by mksglu · mksglu/context-mode

Sandbox tool output and persist session state in SQLite — 98% less token waste, no more compaction amnesia.

Context Mode solves the "LLM forgot what it was doing" problem two ways. First, sandbox tools capture raw data out of the context window (playwright snapshot: 56KB → indexed, agent searches what it needs). Second, a per-session SQLite event log survives context compaction — the model picks up exactly where it was. Ships as plugin + MCP for 12 platforms.

Why use it

Key features

Live Demo

What it looks like in practice

context-mode-mcp.replay ▶ ready
0/0

Install

Pick your client

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "context-mode-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "context-mode"
      ]
    }
  }
}

Open Claude Desktop → Settings → Developer → Edit Config. Restart after saving.

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "context-mode-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "context-mode"
      ]
    }
  }
}

Cursor uses the same mcpServers schema as Claude Desktop. Project config wins over global.

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "context-mode-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "context-mode"
      ]
    }
  }
}

Click the MCP Servers icon in the Cline sidebar, then "Edit Configuration".

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "context-mode-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "context-mode"
      ]
    }
  }
}

Same shape as Claude Desktop. Restart Windsurf to pick up changes.

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "context-mode-mcp",
      "command": "npx",
      "args": [
        "-y",
        "context-mode"
      ]
    }
  ]
}

Continue uses an array of server objects rather than a map.

~/.config/zed/settings.json
{
  "context_servers": {
    "context-mode-mcp": {
      "command": {
        "path": "npx",
        "args": [
          "-y",
          "context-mode"
        ]
      }
    }
  }
}

Add to context_servers. Zed hot-reloads on save.

claude mcp add context-mode-mcp -- npx -y context-mode

One-liner. Verify with claude mcp list. Remove with claude mcp remove.

Use Cases

Real-world ways to use Context Mode

Stop wasting context on raw tool output

👤 Heavy Claude Code users who hit compaction mid-session ⏱ ~15 min intermediate

When to use: You feel your agent "forget" after 30 minutes and burn $$ on re-reads.

Prerequisites
  • Claude Code v1.0.33+brew upgrade claude-code or npm update -g @anthropic-ai/claude-code
Flow
  1. Install
    /plugin marketplace add mksglu/context-mode
    /plugin install context-mode@context-mode✓ Copied
    → Plugin registers hooks + 6 sandbox tools
  2. Verify
    /context-mode:ctx-doctor✓ Copied
    → All checks [x]
  3. Use normally
    Now do a big task that would normally blow context — e.g. analyze all .log files under /var/log✓ Copied
    → ctx_execute used instead of raw Read; output indexed not dumped
  4. Check savings
    /context-mode:ctx-stats✓ Copied
    → Per-tool reduction ratio reported

Outcome: Same task, 10x longer before compaction, and the agent remembers.

Pitfalls
  • Other MCPs bypass the routing — Pass their tool calls through ctx_batch_execute for consistent accounting
Combine with: serena

Resume a long task seamlessly after the model compacts

👤 Devs on multi-hour agent sessions ⏱ ~5 min beginner

When to use: Your task is too big to fit in one context window.

Flow
  1. Start with --continue
    [CLI flag] claude --continue✓ Copied
    → Prior session's SQLite loaded
  2. Observe
    What did I last ask you about? What tasks are in progress?✓ Copied
    → Accurate recap from FTS5 index, not hallucinated

Outcome: A genuinely resumable workflow.

Pitfalls
  • Forgetting --continue starts fresh — Persistence requires --continue; absence means deliberate fresh start

Combinations

Pair with other MCPs for X10 leverage

context-mode-mcp + serena

Serena for semantic code nav, context-mode for keeping its output out of context

Use serena for the lookup, ctx_execute to post-process the results.✓ Copied
context-mode-mcp + playwright

Page snapshot output stays sandboxed

Snapshot the page via playwright, let context-mode hold it — search it instead of dumping.✓ Copied

Tools

What this MCP exposes

ToolInputsWhen to callCost
ctx_execute code: str (js/python) Run a script to process data; output only what's needed free
ctx_batch_execute ops: [{tool, args}] Wrap multiple tool calls through the sandbox free
ctx_index content: str, tags?: [] Stash data for later retrieval free
ctx_search query: str Retrieve from session index free
ctx_fetch_and_index url: str Pull a URL, keep it out of context but searchable free
ctx_stats none See how much context was saved free

Cost & Limits

What this costs to run

API quota
Local
Tokens per call
Dramatic reduction — quoted 98% on real sessions
Monetary
Free (ELv2 license)
Tip
The bigger the session, the bigger the win — use on long tasks

Security

Permissions, secrets, blast radius

Credential storage: Session SQLite in ~/.context-mode/
Data egress: None

Troubleshooting

Common errors and fixes

ctx-doctor shows missing hooks

Restart Claude Code fully after install; hooks register at startup

Verify: Re-run /context-mode:ctx-doctor
Sandbox won't execute code

Node/Python runtime missing. Doctor tells you which. Install with brew/asdf.

Search returns nothing

Verify FTS5 built: sqlite3 ~/.context-mode/session.db "SELECT name FROM sqlite_master". Reinstall if broken.

Alternatives

Context Mode vs others

AlternativeWhen to use it insteadTradeoff
Raw Claude Code (no plugin)Short sessions that never hit compactionNo context saving
claude-memYou want the memory layer without the sandbox-tool paradigmDifferent tradeoff — memory only, no tool output sandbox

More

Resources

📖 Read the official README on GitHub

🐙 Browse open issues

🔍 Browse all 400+ MCP servers and Skills