New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

context-compress

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

context-compress

Context-aware MCP server that compresses tool output for Claude Code

Source
npmnpm
Version
2026.3.22
Version published
Weekly downloads
407
825%
Maintainers
1
Weekly downloads
 
Created
Source

context-compress

Keep your context window lean. Let the sandbox do the heavy lifting.

CI Node.js License: MIT TypeScript

A context-aware MCP server for Claude Code that compresses tool output by processing it in isolated subprocesses. Raw data stays in the sandbox — only concise summaries enter your context window.

Quickstart for Agents · Getting Started · How It Works · Token Reduction · Configuration · CLI · Changelog

Quickstart for Agents

Install context-compress — an MCP server that compresses tool output for Claude Code.
Raw data stays in sandboxed subprocesses, only concise summaries enter your context window.
Saves ~99% of tokens on large outputs while keeping everything searchable via FTS5.

npm install -g context-compress
claude mcp add context-compress -- node $(which context-compress)
context-compress doctor

More info: https://github.com/Open330/context-compress

Why?

Every byte of tool output that enters your Claude Code context window reduces quality and speed. A single git log or npm test can dump 50KB+ into context — that's ~12,000 tokens gone.

context-compress intercepts these tools, processes output in a sandbox, and returns only what matters:

Before:  git log --oneline -100  →  8.2KB into context
After:   execute("git log ...")  →  0.3KB summary + full data searchable in FTS5

Based on context-mode by Mert Koseoğlu — rewritten in TypeScript with security hardening, architectural improvements, and better DX.

Getting Started

Install

npm install -g context-compress

Add to Claude Code

claude mcp add context-compress -- node $(which context-compress)

Or add to your project's .mcp.json:

{
  "mcpServers": {
    "context-compress": {
      "command": "node",
      "args": ["/path/to/context-compress/dist/index.js"]
    }
  }
}

Verify

context-compress doctor

How It Works

┌─────────────────────────────────────────────────────────┐
│                     Claude Code                          │
│                                                          │
│  "Run tests"  ──→  PreToolUse Hook intercepts            │
│                          │                               │
│                          ▼                               │
│               ┌──────────────────┐                       │
│               │  context-compress │                      │
│               │   MCP Server      │                      │
│               └────────┬─────────┘                       │
│                        │                                 │
│            ┌───────────┼───────────┐                     │
│            ▼           ▼           ▼                     │
│     ┌──────────┐ ┌──────────┐ ┌──────────┐              │
│     │ Executor │ │  Store   │ │  Stats   │              │
│     │ (11 lang)│ │  (FTS5)  │ │ Tracker  │              │
│     └──────────┘ └──────────┘ └──────────┘              │
│            │           │                                 │
│            ▼           ▼                                 │
│     Raw output    Indexed &     Only summary             │
│     stays here    searchable    enters context           │
└─────────────────────────────────────────────────────────┘

7 MCP Tools

ToolWhat it does
executeRun code in 11 languages. Only stdout enters context.
execute_fileProcess a file via FILE_CONTENT variable — file never enters context.
indexChunk markdown/text into FTS5 knowledge base for search.
searchBM25 search with Porter stemming → trigram → fuzzy fallback.
fetch_and_indexFetch URL → HTML-to-markdown → auto-index. Preview only in context.
batch_executeRun N commands + search in ONE call. Replaces 30+ tool calls.
statsReal-time session statistics: bytes saved, tokens avoided, savings ratio.

Supported Languages

javascript · typescript · python · shell · ruby · go · rust · php · perl · r · elixir

Bun auto-detected for 3-5x faster JS/TS execution.

Token Reduction

context-compress achieves 99.2% token reduction across a typical 12-operation coding session.

OperationBeforeAfterReduction
Read bundled file (776KB)194,076 tok105 tok99.9%
Playwright snapshot (56KB)14,000 tok75 tok99.5%
Read CSV/JSON data (100KB)25,000 tok125 tok99.5%
Read source file (21KB)5,250 tok88 tok98.3%
npm install log (15KB)3,750 tok50 tok98.7%
curl API response (12KB)3,000 tok88 tok97.1%
npm test (42 tests)935 tok45 tok95.2%
batch_execute (5 cmds)6,250 tok375 tok94.0%
fetch_and_index (45KB page)11,250 tok750 tok93.3%
grep (small output)361 tok361 tok0%
Session Total267,121 tok2,223 tok99.2%

Without context-compress, 12 operations consume 133% of the 200K context window — overflowing it entirely. With context-compress, the same operations use 1.1%, leaving 98.9% free for actual conversation.

Data isn't deleted — it's indexed in FTS5 and searchable on demand. Small outputs (<5KB) pass through uncompressed.

Read the full Token Reduction Report — includes cost analysis, architecture deep-dive, and FAQ on context loss trade-offs.

What Changed from context-mode

context-modecontext-compress
Credentials20+ auth env vars passed by defaultOpt-in only (passthroughEnvVars: [])
Hook writesSelf-modifies settings.jsonZero filesystem writes
Rust compileShell string → injection riskexecFileSync with array args
Upgradegit clone arbitrary codeRemoved entirely
FTS5 indexingAlways dual-table (Porter + trigram)Lazy trigram — 50% fewer writes
Runtime detectSequential execSync ~250msParallel Promise.all ~40ms
batch_executeSequential commandsPromise.allSettled parallel
ConfigNoneENV + file + defaults
Errors23 silent catch blocksCONTEXT_COMPRESS_DEBUG=1 logs all
UninstallNonecontext-compress uninstall

Configuration

Loaded in order: ENV vars.context-compress.jsondefaults

Environment Variables

# Enable debug logging (stderr)
CONTEXT_COMPRESS_DEBUG=1

# Pass specific env vars to subprocesses (default: none)
CONTEXT_COMPRESS_PASSTHROUGH_ENV=GH_TOKEN,AWS_PROFILE

# Disable curl/wget blocking
CONTEXT_COMPRESS_BLOCK_CURL=0

# Disable WebFetch blocking
CONTEXT_COMPRESS_BLOCK_WEBFETCH=0

# Disable Read/Grep nudges
CONTEXT_COMPRESS_NUDGE_READ=0
CONTEXT_COMPRESS_NUDGE_GREP=0

Config File

Create .context-compress.json in your project root or home directory:

{
  "passthroughEnvVars": ["GH_TOKEN", "AWS_PROFILE", "KUBECONFIG"],
  "blockCurl": true,
  "blockWebFetch": true,
  "debug": false
}

CLI

context-compress            # Start MCP server (stdio)
context-compress setup      # Detect runtimes, show install instructions
context-compress doctor     # Diagnose: runtimes, hooks, FTS5, version
context-compress uninstall  # Clean removal: hooks, MCP reg, stale DBs

Doctor Output Example

  context-compress doctor

  [PASS] Performance: FAST — Bun detected
  [PASS] Language coverage: 7/11 (64%)
  [PASS] Server test: OK
  [PASS] PreToolUse hook configured
  [PASS] FTS5 / better-sqlite3 works

  Version: v2026.3.3
  All checks passed.

Project Structure

context-compress/
├── src/
│   ├── index.ts              # Entry point
│   ├── server.ts             # MCP server (7 tools)
│   ├── executor.ts           # SubprocessExecutor
│   ├── store.ts              # ContentStore (FTS5)
│   ├── config.ts             # Config system
│   ├── logger.ts             # Debug logger
│   ├── snippet.ts            # FTS5 snippet extraction
│   ├── stats.ts              # Session tracker
│   ├── types.ts              # Shared types
│   ├── runtime/
│   │   ├── plugin.ts         # LanguagePlugin interface
│   │   ├── index.ts          # Registry + parallel detection
│   │   └── languages/        # 11 language plugins
│   ├── hooks/
│   │   └── pretooluse.ts     # PreToolUse hook (no self-mod)
│   └── cli/
│       ├── index.ts          # CLI entry
│       ├── setup.ts          # Interactive setup
│       ├── doctor.ts         # Diagnostics
│       └── uninstall.ts      # Clean removal
├── tests/
│   ├── unit/                 # 7 unit test files
│   └── integration/          # 3 integration test files
├── hooks/
│   └── hooks.json            # Hook matcher config
├── skills/                   # Slash command definitions
└── dist/                     # Compiled output

Security

ThreatMitigation
Credential leakagepassthroughEnvVars defaults to [] — zero env vars passed unless opted in
Shell injection (Rust)execFileSync with array arguments — no string interpolation
Hook self-modificationNo fs.writeFileSync in hooks — zero filesystem side effects
Arbitrary code executionNo upgrade command — no git clone or npm install at runtime
Silent failuresDebug mode surfaces all catch block errors to stderr

Contributing

git clone https://github.com/Open330/context-compress
cd context-compress
npm install
npm run typecheck     # Type checking
npm run lint          # Biome linting
npm run test:unit     # Unit tests
npm run test          # All tests (unit + integration)
npm run build         # Compile + bundle

License

MIT — Based on context-mode by Mert Koseoğlu.

Keywords

mcp

FAQs

Package last updated on 04 May 2026

Related posts