Skip to main content
Glama

context-slim

CI License: MIT Node.js >= 18 Zero Dependencies

Universal, zero-dependency token-saving compressor (CLI + Ultra-Lean stdio MCP Server + Portable SKILL.md) designed for Codex, Gemini CLI, Claude Code / Desktop, Cursor, OpenBot, and web AI chats (--copy).

Compresses files, project directories, JSON payloads, logs, CSVs, and Markdown before sending them to an LLM — cutting context bloat while preserving structural fidelity and enforcing maxTokens budgets.


Why context-slim?

  • Built-in Zero-Dependency Engine (standalone): Compresses code, JSON/JSONL, terminal logs, CSVs, Markdown, and directories anywhere Node.js >= 18 runs.

  • Hybrid Acceleration (auto / hybrid): Automatically leverages repomix (Tree-sitter AST compression for directories) and rtk (rtk json --keys-only) when installed locally, with deterministic built-in fallbacks.

  • Zero MCP Schema Bloat: Exposes only 3 compact MCP tools (slim_audit, slim_file, slim_text) under ~300 schema tokens so the server saves tokens instead of adding overhead.

  • Ready for Web & Terminal Workflows: Pipe from stdin (--stdin), copy straight to the system clipboard (--copy), or inspect savings first (inspect) before sending a single line to an AI model.


Related MCP server: distil

Compression Strategies by Format

Format

balanced (Default)

aggressive / Budgeted

Code (.js, .ts, .py, .go, .rs, etc.)

Strips comments while preserving string literals; collapses redundant blank lines

Extracts structural exports, classes, functions & imports skeleton

JSON / JSONL

Compacts whitespace, replaces huge base64/data blobs, caps long arrays (<= 3 items + count)

Tighter depth/array caps or delegates to rtk json --keys-only when available

Logs & Stacktraces

Strips ANSI codes, collapses consecutive repeats ([repeated Nx]), keeps errors/warnings ±2 context lines

Tighter head/tail + ±1 context around errors/warnings

CSV / TSV

Keeps header + sample head/tail rows with omitted row count

Compact head/tail preview

Directories

Uses repomix --compress (if available) or built-in recursive walker skipping node_modules/.git/binaries

Enforces --max-tokens N budget cleanly across the pack


Quick Start

1. Audit & Compress via CLI

# Dry-run token audit before sending anything to an AI
node bin/context-slim.cjs inspect ./src

# Compress a file or directory and copy straight to clipboard for any AI chat
node bin/context-slim.cjs pack ./src --level balanced --max-tokens 2500 --copy

# Compress piped terminal logs or JSON from stdin
cat app.log | node bin/context-slim.cjs text --format log --copy

# Check detected hybrid engines (built-in + rtk / repomix)
node bin/context-slim.cjs engines

2. Install Across AI Clients (Codex, Gemini CLI, Claude, Cursor)

node bin/context-slim.cjs install --client all
node bin/context-slim.cjs status

This atomically registers the ultra-lean context-slim MCP server and copies skill/SKILL.md into your local AI clients.


Ultra-Lean MCP Tools (bin/mcp-server.cjs)

Tool

Purpose

Required Input

slim_audit

Estimate token count & potential savings before reading

path

slim_file

Compress a file or directory (light / balanced / aggressive, maxTokens)

path

slim_text

Compress raw text, logs, JSON, or code snippets

content


Verification

npm run check
npm test

License

MIT — Built by Emerson Almeida (@deusbr).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      A
      maintenance
      Reversibly compress a large tool output to a recoverable 8-hex handle over stdio, expand it back to the exact original bytes on demand, and report a local token/dollar savings ledger. Zero runtime dependencies; content never leaves the machine.
      3
      626 PyPI
      21
      Apache 2.0
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI coding agents to reduce token usage by condensing source code into AST skeletons, extracting specific symbols, compressing logs, and estimating token budgets.
      4
      MIT