DEV Community

Deduped
Deduped

Posted on Originally published at dedupedai.com

Stop Claude Code context bloat with Context Mode: a 5 step setup

Every MCP tool call dumps raw data into your context window. According to the Context Mode README, a Playwright snapshot costs 56 KB, twenty GitHub issues cost 59 KB, and one access log is 45 KB. After about 30 minutes of work, roughly 40% of a Claude Code context can be gone, and when the conversation compacts, the agent forgets which files it was editing.

Context Mode is an MCP server plus a set of hooks that attacks this from two sides: it keeps raw output in a sandbox so only a small result reaches the chat, and it tracks session events in SQLite so work survives compaction. Our shorter walkthrough lives on the Deduped use-case page. Here is the full setup.

Prerequisites

You need Claude Code v1.0.33 or newer. Check with:

claude --version
Enter fullscreen mode Exit fullscreen mode

If /plugin is not recognized, update first with brew upgrade claude-code or npm update -g @anthropic-ai/claude-code.

Step 1: install the plugin

Inside Claude Code, add the marketplace and install:

/plugin marketplace add mksglu/context-mode
/plugin install context-mode@context-mode
Enter fullscreen mode Exit fullscreen mode

Restart Claude Code, or run /reload-plugins.

Step 2: verify with the doctor

/context-mode:ctx-doctor
Enter fullscreen mode Exit fullscreen mode

All checks should show [x]. The doctor validates runtimes, hooks, FTS5 and plugin registration. If something is red, fix that before you continue, because the routing hooks are what make the savings automatic.

What you get

The plugin registers hooks (PreToolUse, PostToolUse, UserPromptSubmit, PreCompact, SessionStart, Stop) and 11 MCP tools. Six are sandbox tools: ctx_batch_execute, ctx_execute, ctx_execute_file, ctx_index, ctx_search and ctx_fetch_and_index. Five are meta tools: ctx_stats, ctx_doctor, ctx_upgrade, ctx_purge and ctx_insight.

Routing is automatic. A SessionStart hook injects routing instructions at runtime, so nothing is written into your project.

Step 3: think in code

The idea the README pushes hardest: the model should program the analysis, not compute it. Instead of reading 50 files into context to count functions, the agent writes a script and prints only the answer:

// Before: 47 x Read() = 700 KB.  After: 1 x ctx_execute() = 3.6 KB.
ctx_execute("javascript", `
  const files = fs.readdirSync('src').filter(f => f.endsWith('.ts'));
  files.forEach(f => console.log(f + ': ' + fs.readFileSync('src/'+f,'utf8').split('\\n').length + ' lines'));
`);
Enter fullscreen mode Exit fullscreen mode

One script replaces many tool calls. The README quotes 315 KB shrinking to 5.4 KB, a 98% reduction, for sandboxed output. Treat those as the project's own numbers, and measure yours.

Step 4: measure your savings

/context-mode:ctx-stats
Enter fullscreen mode Exit fullscreen mode

This shows a per-tool breakdown, tokens consumed and the savings ratio. For a live meter, add a status line to ~/.claude/settings.json:

{
  "statusLine": {
    "type": "command",
    "command": "context-mode statusline"
  }
}
Enter fullscreen mode Exit fullscreen mode

Restart Claude Code and the bar shows dollars saved this session, saved across sessions and percent efficient.

Step 5: index docs you keep re-reading

Point it at a local file or directory and search it later instead of pasting it in:

/context-mode:ctx-index
/context-mode:ctx-search
Enter fullscreen mode Exit fullscreen mode

Content goes into a persistent FTS5 knowledge base and comes back through BM25 search, so only relevant passages enter the chat. If you ever want it gone, /context-mode:ctx-purge permanently deletes everything indexed.

Just want to try it?

Skip the plugin and add only the MCP server:

claude mcp add context-mode -- npx -y context-mode
Enter fullscreen mode Exit fullscreen mode

You get all 11 tools without automatic routing or slash commands. The model can use them but will not be nudged away from raw Bash, Read and WebFetch, so savings are smaller. It is a good way to test before committing.

Session continuity

Context Mode records file edits, git operations, tasks, errors and your decisions in SQLite. After a compaction it does not dump that history back in. It indexes the events into FTS5 and retrieves only what is relevant. One caution from the README: if you do not start with --continue, previous session data is deleted immediately, so a fresh session is a clean slate.

Tips

  • Run ctx-stats after a long session so you know whether the hooks are routing.
  • Other clients are supported too, including Gemini CLI and VS Code Copilot, with their own config files; see the README.
  • If your pain is specifically noisy shell output, compare it with a CLI output compressor before stacking tools.

Who this is for

Anyone who runs long Claude Code sessions with browser, GitHub or log-heavy MCP tools and keeps hitting compaction. If your sessions are short, the overhead is not worth it.

Repo: github.com/mksglu/context-mode. More ways people use it are on Deduped.


Get one email every Monday with the week's hottest AI repos and exactly how to use them: subscribe free at dedupedai.com

Top comments (0)