← All posts

AI tool reviews › Tokens and context

What is context-mode? Keeping tool output in a sandbox

context-mode is a Claude Code plugin that processes large tool output in a sandbox and passes only the result into context. How it works, and what I measured.

If you’ve used an AI coding agent like Claude Code for a while, you’ve probably heard that the context window fills up faster the longer a task runs. And if you went looking for a fix, perhaps you ran into the name context-mode. Its Hacker News post on February 28, 2026, was titled “MCP server that reduces Claude Code context consumption by 98%,” and it earned 570 points. As of October 28, 2026, the repository has 32,572 GitHub stars.

context-mode is a Claude Code plugin by Mert Köseoğlu that bundles an MCP server, hooks, and skills (GitHub). MCP is a standard protocol that lets an agent call outside tools, and a hook is a command that runs on its own at a set moment, such as right before the agent uses a tool. What the plugin does is take large tool output, like logs, test results, or web pages, handle it in a separate process, and let only the result into the context. The repository and the first npm package were created on February 23, 2026, and the author published an introductory post three days later. It isn’t listed in Anthropic’s official marketplace, so you install it by adding the author’s repository as a marketplace.

What it tries to cut

When an agent runs a command or reads a file, the result is appended to the conversation and goes back to the model with every request after that. In the introductory post, the author writes that a single Playwright snapshot takes 56 KB and that after about 30 minutes, 40% of the context is gone. So context-mode asks the model to write code that computes the answer instead of reading the raw data, and only what that code prints comes into the conversation. It also has a session continuity feature: it records what happens during the work in SQLite and restores it, so the agent doesn’t lose track of the task after Claude Code compacts a long conversation.

What’s inside, and when it steps in

First, there are 11 MCP tools. ctx_execute runs code, ctx_execute_file runs code with a file’s contents loaded into a FILE_CONTENT variable, and ctx_batch_execute handles several commands at once. ctx_index, ctx_search, and ctx_fetch_and_index split documents or web pages into chunks stored in FTS5, SQLite’s full-text search, and find only the pieces you need. The other five are for housekeeping, such as stats and diagnostics.

Next, hooks.json wires up six hooks. When a session starts, the SessionStart hook adds routing instructions that say which ctx tool to use for which job, and right before a tool runs, the PreToolUse hook steps in. Reading the source, though, the cases it actually blocks are narrow. It blocks WebFetch, and it swaps curl or wget calls that print straight to the screen, along with build commands like gradle, for a command that prints a notice. Other Bash, Read, and Grep calls, however, run as usual, with a short tip added once per session. The remaining hooks record events such as file reads, errors, and user prompts in SQLite. Finally, there are eight skills: one that explains when to use the ctx tools, and seven slash commands such as /context-mode:ctx-stats.

Of all this, what loads into every session is the routing instructions (4,631 bytes, about 1,050 tokens by a tiktoken estimate), the descriptions of the eight skills (about 2.8 KB), and the names of the ctx tools. The tool definitions add up to 29,977 bytes, but Claude Code’s tool search, which is on by default, loads MCP tool definitions only when they’re needed, so they don’t all load up front.

Getting only the result back from the sandbox

To see what the tools actually return, I sent requests straight to the MCP server, with no agent in between. I made up a 5,000-line access log and passed the code below to ctx_execute_file, asking it to count requests with a status of 400 or higher by status code and path.

// Runs in the sandbox. FILE_CONTENT holds the file; only console.log output comes back.
const counts = {};
for (const line of FILE_CONTENT.split("\n")) {
  const m = line.match(/"\w+ (\S+) [^"]*" (\d{3})/);
  if (m && +m[2] >= 400) counts[`${m[2]} ${m[1]}`] = (counts[`${m[2]} ${m[1]}`] || 0) + 1;
}
Object.entries(counts).sort((a, b) => b[1] - a[1]).slice(0, 5)
  .forEach(([key, n]) => console.log(String(n).padStart(4), key));

Here’s the output of the script that sent the request, minus the first part that lists the tools.

server: context-mode 1.0.169, 11 tools, 29,977 bytes of tool definitions
input: access.log, 707,040 bytes
ctx_execute_file returned 579 bytes (code echo + stdout). stdout:
 187 502 /api/checkout
 143 404 /static/app.v2.js
 121 401 /api/orders
  96 500 /api/search
  74 429 /api/login

I passed in a 707 KB file and got back 579 bytes, most of which was the server echoing the code I sent. The raw file was read only inside a subprocess on the server side, and only the five lines printed with console.log made it into the result. As the README itself points out, though, that subprocess inherits the process’s filesystem access and the credentials of commands like gh and aws, so you shouldn’t expect OS-level isolation. For very large output, there’s also a path that indexes it in FTS5 and returns only the matching parts. I didn’t get to run the feature that restores session records after compaction, so I checked it only against the README and the source.

Running it side by side in Claude Code

Next, I gave the same kinds of jobs to Claude Code in headless mode and compared runs with and without context-mode. One job was to find the five most frequent errors in the log above. The other was to explain the failures in a small project where 3 of 600 tests fail and every test logs a warning line, which makes the output 44,241 bytes long. Here’s the log run with context-mode.

claude -p "access.log in this folder is a web server access log. What are the five most frequent errors (HTTP status 400 or higher), grouped by status code and path? List them with their counts." \
  --model haiku --output-format stream-json --verbose \
  --allowedTools "Bash,Read,Grep,Glob,Skill,mcp__plugin_context-mode_context-mode" < /dev/null

In practice, I added isolation flags so my personal settings weren’t loaded, and attached the plugin and the MCP server to that run only, with their storage pointed at the work folder. Below is a summary of the saved runs, made with a script. tool out is the bytes that came in as tool results, and 1st req and last req are the input tokens (including cache) of the first and last requests.

task  arm      model  tool calls                         tool out  1st req last req  cost $  ok
log   without  haiku  Bash, Bash                            1,195   20,632   22,200  0.0031  yes
log   with     haiku  ctx_execute_file                      1,643   23,684   25,303  0.0035  yes
log   without  haiku  Bash, Bash                            1,359   20,633   22,352  0.0032  yes
log   with     haiku  Bash, ctx_execute_file                2,235   23,680   26,228  0.0041  yes
tests without  haiku  Bash, Bash, Bash, Bash                7,589   20,640   25,794  0.0050  yes
tests with     haiku  Bash, Bash, Bash                      4,573   23,670   27,814  0.0054  yes
tests without  sonnet Bash, Bash, Read, Bash                9,958   19,813   25,134  0.0685  yes
tests with     sonnet Bash, Read, Bash                      4,819   22,850   25,892  0.0676  yes

All eight runs got the right answer, but in none of them did context-mode shrink the context. With context-mode, the first request was always 3,030 to 3,052 tokens larger. That’s because the routing instructions and skill descriptions ride along with every request, plus the definitions of three resource tools that Claude Code adds whenever an MCP server is attached. On the log job, haiku used ctx_execute_file when context-mode was there, but without it, haiku read just a few lines of results from an awk and sort pipeline, so there wasn’t much to save in the first place. On the test job, neither haiku nor sonnet called a ctx tool even once; they trimmed the output with tail or grep. So the smaller tool out there is better read as a difference in the commands the model chose. On top of that, even without context-mode, Claude Code moved the large output to a file on its own and passed in only a preview. According to the Claude Code docs, Bash output turns into a file path and preview like this once it passes about 30,000 characters.

Of course, this is a small experiment with one or two runs each, not a benchmark. The author’s published measurements compare the full raw output with what the ctx tools return, and by that yardstick, 315 KB became 5.5 KB. My baseline, on the other hand, was a current model and Claude Code that already read output sparingly. So perhaps it’s only natural that I didn’t see the same numbers.

How it differs from similar tools

Tools that “save tokens” don’t all cut the same thing.

Tool Mainly cuts How it steps in
context-mode Tool output (logs, web pages, MCP results) MCP tools that compute results, and hooks that steer toward them
RTK Shell command output Intercepts shell commands and compresses their output
Caveman Length of the agent’s replies A skill that makes it talk tersely (with extras that cut input)

RTK runs the same command and shrinks the output before the agent reads it, while context-mode has the model write code that computes the result. General context engineering techniques, such as summarizing the conversation or loading files only when needed, are already built into Claude Code.

When it fits, and what you take on

context-mode probably fits best when MCP tools often return large results, like browser snapshots, or in long sessions where you look up the same documents again and again. On the other hand, for short tasks, or when the agent already reads output sparingly, it may only add a fixed cost of about 3,000 tokens per request, as in my runs. And for work where you need the original output as is, such as editing a file, Read is still the right tool.

Some data stays on your machine, too. Session records and indexes are kept as SQLite files per project under ~/.claude/context-mode/, and CONTEXT_MODE_DIR lets you move them. The records from my runs held the prompt text, the last answer, and token usage. The README says there’s no telemetry, and I didn’t find code in the source that sends records out by default. Still, the server asks the npm registry for the latest version at startup and every hour after that, and ctx_insight opens a team analytics page run by the author’s side.

It also touches settings in your home folder. When the MCP server starts, start.mjs places a self-heal hook file in ~/.claude/hooks/ and, if ~/.claude/settings.json exists, registers that hook under SessionStart. In my isolated run, I watched the entry appear in an empty settings.json, and I didn’t find code that removes it. And because the ctx tools run arbitrary code, the README itself suggests treating approval of these tools as approval of arbitrary code.

The license is the Elastic License 2.0: you can modify and distribute the code, but you can’t offer it as a hosted service. The February introductory post said MIT, so if you grabbed the code back then, it’s worth checking again. The last stable release is v1.0.169 from June 29, 2026, and a 2.0.0-next.8 prerelease came out on October 28.

Installing it and what to try first

Following the README, you type the first two commands below inside Claude Code, restart, and then check with the diagnostic command on the last line.

/plugin marketplace add mksglu/context-mode
/plugin install context-mode@context-mode
/context-mode:ctx-doctor

To remove it, run claude plugin uninstall context-mode@context-mode in your shell. The ~/.claude/context-mode folder, the self-heal hook file above, and its settings.json entry, though, need to be deleted by hand. If you’re trying it for the first time, I’d suggest handing it a task you usually do, then checking what took up space with /context-mode:ctx-stats and Claude Code’s /context. I checked everything here on October 28, 2026, on macOS with context-mode 1.0.169 (commit b77ba44), Claude Code 2.1.304, and claude-haiku-5-5 and claude-sonnet-5-5.

AI tools helped with the research for this post.