claudeers.
// RAG & Knowledge

copium

Context optimization layer for LLMs. 65-90% token savings with zero quality loss. Drop-in proxy for Claude, GPT, Gemini, and local LLMs (Ollama/VLLM/llama.cp…

// RAG & Knowledge[ cli ][ api ][ desktop ][ web ][ mobile ][ claude ]#claude#agent#ai#anthropic#claude-code#context-engineering#context-window#langchain#ragApache-2.0$open-sourceupdated about 7 hours ago

Install with your AI

Paste into Claude Code, Cursor, or any agent — it reads the repo and wires the tool into your project.

Install and set up copium (git-clone project) into my current project.
Found on https://claudeers.com/copium
Repo: https://github.com/iKislay/copium
Homepage/docs: —
Detected install method: git-clone → git clone https://github.com/iKislay/copium
Category: rag. Platforms: cli, api, desktop, web, mobile.
Read the repo's README for exact setup and env vars, then install it and wire it into my project.

Claudeers Health Verdict:
unknown; community-verified: false. Confirm the source before running anything.
// or clone
git clone https://github.com/iKislay/copium

MCP Compression Proxy (New)

Copium now includes an MCP proxy mode that acts as a transparent compression layer between your AI coding tool and upstream MCP servers.

Key capabilities:

  • Tool description compression (70-90 percent reduction)
  • Tool schema compression (~57 percent reduction)
  • Tool response compression (60-95 percent reduction)
  • Session deduplication for repeated tool definitions
  • Progressive tool disclosure with on-demand schema expansion

Quick start:

copium mcp proxy install
copium mcp proxy serve

Helpful commands:

  • copium mcp proxy detect
  • copium mcp proxy status
  • copium mcp proxy uninstall

See docs/mcp-proxy.md for setup and configuration details.

Cross-Agent Context Sharing (New)

Copium is now the context layer for multi-agent systems. Agents don't share context across sessions, tools, or each other — until now. SharedContext compresses what moves between agents, persists it across sessions, and makes it searchable.

Key capabilities:

  • Persistent SharedContext: SQLite-backed storage that survives proxy restarts.
  • Agent Provenance: Track which agent created/modified each context entry.
  • Conflict Resolution: Configurable strategies (last-write-wins, confidence, priority, merge).
  • Semantic Search: Vector-based search over all shared context entries.
  • Audit Trail: Full operation log for enterprise compliance.
  • Framework Integrations: CrewAI, LangGraph, OpenAI Agents SDK, AutoGen, Agno, Strands.
  • Zero-Code Proxy Mode: Any agent routing through the proxy shares context automatically.
from copium import SharedContext

ctx = SharedContext(persistent=True)

# Agent A stores output (compressed + persisted)
ctx.put("research", big_output, agent="researcher")

# Agent B gets compressed version (~80% smaller)
summary = ctx.get("research")

# Semantic search across all shared context
results = ctx.search("database migration findings", top_k=5)

See:

  • guides/shared-context.md
  • copium/shared_context/ (PersistentStore, VectorIndex, ConflictResolver, AuditLog)
  • copium/integrations/ (crewai, openai_agents, autogen, langchain, agno, strands)

Pre-Compaction Data Loss Prevention (New)

Copium now prevents the silent data loss caused by auto-compaction in agentic tools.

When Claude Code, Cursor, or Codex fires auto-compaction, critical context is destroyed: reasoning chains, architectural decisions, file relationships, and user intent. Copium's new compaction hooks preserve this state and make recovery automatic.

Key capabilities:

  • Input-Priority Compression: User messages (high entropy) preserved; tool outputs compressed.
  • Entropy-Based Scoring: Information density scoring for intelligent compression scheduling.
  • Incremental Checkpointing: Gradual state saves every N tool calls (no cliff).
  • Claude Code Hook Integration: Native PreCompact/PostCompact hook bridge.
  • CCR Safety Net: All compression remains reversible via copium_retrieve.

See:

  • guides/compaction-prevention.md
  • copium/hooks/ (InputPriorityHooks, IncrementalCheckpointHooks, claude_code)

Agent Context Management (New)

Copium now includes a Smart Zone based agent-aware context lifecycle in copium/agent_context/.

Key capabilities:

  • Smart Zone budget enforcement to keep context in high-quality ranges.
  • Phase detection: orientation, exploration, implementation, verification.
  • Value-aware and content-type-aware compression scheduling.
  • Orientation cache to reduce first-turn tool-call overhead.
  • Context health monitoring and recommendations for long sessions.

See:

  • guides/agent-context-management.md
  • docs/agent-context-management.md

Position-Aware Compression (Lost in the Middle)

Initial implementation work has started for position-aware compression to reduce "lost in the middle" degradation in long contexts.

Implemented in this iteration:

  • Rust position_aware transform module with zones, scoring, and configuration.
  • Python position_aware module parity helpers.
  • SmartCrusher planner helper for position-aware keep-order optimization.
  • Unit tests covering zone classification, weighting, and bookend reordering.

This is an opt-in foundation. Default behavior remains unchanged when position weighting is disabled.

Quality Preservation (New)

Copium now includes a comprehensive quality preservation framework in copium/quality/.

The community's #1 concern with context compression: "Does it break my agent's answers?" Our answer: verifiable, benchmarked, auditable proof that quality is preserved.

Key capabilities:

  • Quality Gate: Post-compression validation with 4 checks (token reduction, critical markers, structure, density). Auto-reverts to original if any check fails.
  • Quality Metrics: ROUGE-L (≥0.85), IPS (≥0.95), CWQ (≥0.85) measurement.
  • A/B Testing: Statistical framework with Welch's t-test, Cohen's d, power analysis.
  • Quality Dashboard: Real-time session monitoring via copium quality status.
  • Benchmarks: Synthetic and real-world benchmark suites with CI integration.
from copium.quality import QualityGate, GateConfig, ContentType

gate = QualityGate(GateConfig(min_token_savings_pct=10.0))
result = gate.validate(original, compressed, ContentType.JSON)
# Auto-reverts to original if quality drops below threshold

The bottom line: 70-90% compression, <2% accuracy drop — because of structure-aware compression, CCR reversibility, and quality gates that catch failures automatically.

See:

  • docs/content/docs/quality-preservation.mdx
  • copium/quality/ (QualityGate, QualityMetrics, ABTestHarness, QualityDashboard)

Copium

The context compression layer for LLM applications

65–94% fewer tokens. Zero quality loss. Drop-in proxy for Claude, GPT, Gemini, Bedrock, and local LLMs.

Docs · Install · Proof · Alternatives · Agent Guides · GitHub


What is this?

You know how your AI coding assistant (Claude Code, Cursor, Copilot, etc.) sometimes slows down mid-session, starts forgetting things it read earlier, or just becomes weirdly bad at tasks it was great at ten minutes ago? That's the context window filling up. Every file your agent reads, every command it runs, every tool output it processes — it all piles into a prompt that the AI has to re-read from scratch on every single message. You're paying for all of it, every time.

Copium sits between your agent and the AI provider and compresses everything before it goes out. It's a local proxy — your data never leaves your machine. Same answers. Fraction of the tokens.

The gains are real: 1.4 billion tokens saved across 50K+ sessions in production.


Get started (60 seconds)

Install

# Recommended — installs globally in an isolated environment
pipx install "copium-ai[proxy]"

# If you use uv
uv tool install "copium-ai[proxy]"

# Project-local install (less recommended for CLI use)
pip install "copium-ai[proxy]"

Why pipx? It installs CLI tools into isolated environments so copium is available globally without polluting any project's dependencies. If you don't have pipx: pip install pipx && pipx ensurepath.

RTK (Rust Token Killer) — Included automatically

RTK is bundled with Copium and auto-installed on first copium wrap run. No separate install needed.

For RTK-only mode (CLI stdout compression without the proxy):

copium wrap claude --rtk-only

This gives you RTK's exact UX — rtk git status, rtk grep, etc. — then upgrade to full proxy compression anytime by dropping --rtk-only.

To install RTK manually (standalone):

# Via Homebrew (macOS/Linux)
brew install rtk

# Via curl (Linux/macOS)
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/main/install.sh | bash

# Via cargo
cargo install --git https://github.com/rtk-ai/rtk

Then activate for your agent:

# Claude Code
rtk init --claude-code

# Verify savings
rtk gain

Start the proxy

Recommended — background daemon (survives shell exit):

copium start               # starts on http://localhost:8787, detaches from terminal
copium status              # check health, port, today's savings
copium status --prompt     # minimal output for shell prompts (⚡ 38%)
copium stop                # stop gracefully (prints session summary with duration + all-time totals)
copium restart             # restart to pick up config changes
copium ping                # fast health check — exit 0 running, exit 1 stopped

One-shot foreground mode (blocks the terminal):

copium proxy               # or: copium run

Point your agent at the proxy:

# Claude Code
export ANTHROPIC_BASE_URL=http://localhost:8787

# Cursor / Aider / OpenCode / any OpenAI-compatible client
export OPENAI_API_BASE=http://localhost:8787/v1

# Watch the savings live
copium status
# or: copium tui  (live terminal dashboard)
# or: open http://localhost:8787/dashboard in your browser

That's it. No config files. No code changes. Copium automatically compresses every request.


Connect your AI agent

Claude Code

copium wrap claude

That single command starts the proxy and configures Claude Code to route through it. When you're done, copium unwrap claude restores everything.

Alternatively, set it manually:

copium run &
export ANTHROPIC_BASE_URL=http://localhost:8082
claude  # or claude-code, or claude --dangerously-skip-permissions

Cursor

copium run &
# In Cursor settings → OpenAI API Base URL:
# http://localhost:8082/v1

Or via environment:

export OPENAI_API_BASE=http://localhost:8082/v1
cursor .

OpenCode

OpenCode uses the OpenAI-compatible API format:

copium run &
export OPENAI_BASE_URL=http://localhost:8082/v1
opencode

Or set it permanently in your OpenCode config:

{
  "openai": {
    "baseURL": "http://localhost:8082/v1"
  }
}

Aider

copium wrap aider
# or manually:
aider --openai-api-base http://localhost:8082/v1

Codex (OpenAI)

copium wrap codex
# Automatically patches ~/.codex/config.toml
# Undo with: copium unwrap codex

GitHub Copilot

copium wrap copilot

This routes Copilot through Copium while keeping your existing auth. Supports both BYOK and subscription modes.

Mistral / Vibe

copium wrap vibe

VS Code Extensions

Cline

copium wrap cline
# Then configure in VS Code:
#   Settings > Cline > API Provider > Anthropic
#   Base URL: http://localhost:8082

Continue

copium wrap continue
# Auto-injects into .continue/config.json

Antigravity (Google)

Note: As of June 2026, Google transitioned Gemini CLI to Antigravity CLI. The new Antigravity 2.0 Desktop App and CLI use Google Sign-In OAuth authentication and route through Vertex AI — they do not expose proxy/base URL settings. Copium cannot currently intercept Antigravity traffic.

Workarounds:

  • Use the old Gemini CLI (if available) which routes through Cloud Code Assist
  • For enterprise users: configure Vertex AI with Copium proxy separately
  • Wait for Google to add proxy configuration support

Any HTTP client / custom app

If your tool lets you set a base URL or API endpoint:

http://localhost:8082         → Anthropic-compatible
http://localhost:8082/v1      → OpenAI-compatible
http://localhost:8082/bedrock → AWS Bedrock
http://localhost:8082/vertex  → Vertex AI (Google Cloud)

As a Python library

If you don't want the proxy at all and just want to compress messages inline:

import json
from copium import compress

# Works with any messages list you'd send to an LLM
data = json.load(open("data.json"))   # e.g. 500-item JSON array
result = compress([{"role": "user", "content": json.dumps(data)}])

print(f"Saved {result.compression_ratio:.1%} tokens")
# → Saved 64.8% tokens

As an MCP server

pip install "copium-ai[mcp]"

Then add to your MCP client config:

{
  "mcpServers": {
    "copium": {
      "command": "copium",
      "args": ["mcp"]
    }
  }
}

Exposes three tools: copium_compress, copium_retrieve, copium_stats.


How it works

You don't need to understand this to use Copium. But if you're curious:

 Your agent / app
   (Claude Code, Cursor, Aider, OpenCode, your own code...)
        |   prompts, tool outputs, logs, RAG results, files
        v
    +----------------------------------------------------+
    |  Copium   (runs locally — your data stays here)   |
    |  -------------------------------------------------  |
    |  ToolPrefilter  → ContentRouter → SmartCrusher    |
    |  Session Dedup  | SelfCompressor | Kompress       |
    |  Cache Aligner  | Error Compressor | TOON Encoder |
    |  Diff Response  | Output Compressor               |
    +----------------------------------------------------+
        |   compressed prompt (same meaning, fewer tokens)
        v
 LLM provider  (Anthropic, OpenAI, Gemini, Ollama, Bedrock...)

Each component targets a specific kind of waste:

ComponentWhat it removesTypical savings
ToolPrefilterOversized tool outputs (500-match grep → 50 lines)60–95%
ContentRouterRoutes each chunk to the best compressor20–60%
SmartCrusherCompresses JSON arrays, repeated tool outputs40–95%
Session DedupRe-sent file content across conversation turns30–70%
SelfCompressorLLM self-compression markers (_context_updates)40–80%
Error CompressorVerbose stack traces → structured error cards50–80%
ANSI RemoverTerminal colors, spinners, progress bars10–30%
TOON EncoderJSON arrays → pipe-delimited tables15–40%
Cache AlignerStabilizes prefixes for provider KV cache hits10–20%
Diff ResponseSends diffs for repeated tool callsUp to 95%
Output CompressorTrims verbose assistant responses15–40%

The pipeline runs in ~52ms median overhead. Your agent doesn't notice it's there.


Progressive Tool Disclosure

Register 30+ MCP tools without burning 60K tokens per request. Copium loads only the tools the LLM needs, when it needs them.

from copium.mcp_proxy.progressive_disclosure import (
    ProgressiveDisclosureConfig,
    ProgressiveDisclosureInterceptor,
)

# Configure progressive disclosure
config = ProgressiveDisclosureConfig(
    enabled=True,
    eager_load_max=10,       # Max tools loaded eagerly
    search_backend="bm25",   # Fast, dependency-free search
    min_tools_for_disclosure=8,  # Threshold to activate
)

# Use in your proxy pipeline
interceptor = ProgressiveDisclosureInterceptor(config)
modified_request = interceptor.intercept_request(request_body)
# 61 tools → 10 eager + copium_find_tool + copium_call_tool
# Token savings: 70-98%

How it works:

  1. Client sends request with all tools (unchanged workflow)
  2. Copium classifies tools as eager (high-usage) or deferred
  3. LLM receives eager tools + copium_find_tool + copium_call_tool
  4. LLM discovers deferred tools on-demand via BM25 semantic search
  5. Schemas are cached for instant repeated lookups
Tool CountToken SavingsEager Tools
10 tools~40%6-8 loaded
30 tools~75%8-10 loaded
60 tools~95%10 loaded

Session management

Copium is also a universal session manager for AI coding agents. Compress, search, and share session archives across Claude Code, Cursor, Aider, and OpenCode.

# Compact a Claude Code session (40-97% smaller)
copium session compact ~/.claude/projects/.../session.jsonl

# Search across all your sessions
copium session search "authentication bug" --agent claude_code

# Export from Claude Code, import into Cursor
copium session export claude-session.jsonl --format shared
copium session import shared.jsonl --agent cursor

# Batch compact all sessions
copium session compact-all ~/.claude/ -o compacted/

# View session summary with auto-detected format
copium session summary session.jsonl

Pre-compaction hooks — never lose context again

Claude Code's auto-compaction fires at ~83.5% of the context window, silently replacing your conversation with a lossy summary. Copium detects this threshold and saves a state checkpoint before compaction fires:

# Restore session state after compaction
copium session restore <session-id>

# List all saved checkpoints for a session
copium session checkpoints <session-id>

# Restore with output file in OpenAI format
copium session restore <session-id> -o recovery.json --format openai

What gets saved:

  • File paths referenced in the conversation
  • Key decisions extracted from assistant messages
  • Tool output hashes (retrievable via CCR store on demand)
  • Message snapshot (most recent messages within token budget)

The checkpoint is automatic — Copium's proxy detects when context usage crosses the threshold and creates the checkpoint without any manual action.

CCR reversibility

Every compressed session entry includes a CCR hash key. Unlike lossy compaction, Copium's compression is always reversible:

# Expand a compacted archive back to original (via CCR store)
copium session expand compacted.jsonl -o original.jsonl

# The CCR store provides hash-keyed retrieval in <1ms
# No .bak files needed — the store IS the recovery mechanism

Supported agents

AgentFormatCommands
Claude CodeJSONLcompact, apply, expand, export, import, restore
CursorJSONcompact, export, import
AiderJSONL / Markdowncompact, export, import
OpenCodeJSONcompact, export, import

Error compression enhancements

FeatureWhat it doesSavings
Build error groupingGroups identical TS/Rust/GCC errors across files60–85%
Docker build compressionRemoves download progress, deduplicates layers40–60%
Compiler normalizationNormalizes paths, removes timestamps10–20%

Proof

Compression on real content types

Content TypeBefore (tokens)After (tokens)Savings
JSON arrays (100 items)3,16329790.6%
Build logs (200 lines)2,41214893.9%
Shell output (200 lines)3,23846985.5%
JSON arrays (500 items)9,5261,61483.1%
Repeated tool outputs10,0001,50085%
Git diffs3,00030090%

Quality preserved — LLM accuracy benchmarks

The most important thing: does the AI still give correct answers?

BenchmarkBaseline (no compression)With CopiumDelta
HTML Extraction (F1)0.9580.919−0.039
HTML Recall0.98298.2% content preserved
JSON Needle Finding4/44/4100% accuracy at 87.6% compression
GSM8K (Math)0.8700.870+/−0.000
TruthfulQA (Factual)0.5300.560+0.030 (improved)

Run these yourself:

pip install "copium-ai[evals]" && pytest tests/test_evals/ -v -s

Production telemetry (250+ instances, 50K+ sessions)

MetricValue
Total tokens saved1.4 billion
Median proxy overhead52ms
Median compression (all requests)4.8%
Heavy tool-use sessions40–80%

Most requests are short conversational turns — the median 4.8% compression is accurate for those. Where Copium pays for itself is in long agentic sessions with accumulated tool outputs, logs, and search results: that's where you see 40–94%.


When does it help?

You'll see real gains if you:

  • Run AI coding agents daily (Claude Code, Cursor, Codex, etc.)
  • Use local LLMs and need to stay within context limits
  • Work with verbose tool outputs — build logs, JSON, search results, git diffs
  • Want to extend context window life on quantized models (Q4_0, Q8_0)
  • Use Copilot or other subscription services and want more out of each turn

It won't help much if you:

  • Only send short conversational prompts (median savings: 4.8%)
  • Already use a provider's native compaction and don't need more
  • Work in a sandboxed environment where local processes can't run

Compared to alternatives

Copium runs locally, covers every content type, works with every major framework, and supports both cloud and local LLMs.

ScopeDeployLocal LLMsReversibleObservability
CopiumAll context — tools, RAG, logs, files, history, sessionsProxy, library, MCP, CLI✅ (CCR)Full metrics
ContextCrumbToken-level compression for agent toolsMCP proxy onlyBasic inspection
KompactPrompt text & schemasPython library
Claw CompactorPrompt text & structurePython library
HeadroomAll contextProxy, library, middleware, MCP✅ (CCR)
ContextZipSession history / JSONLPython CLI (Claude only)❌ (Lossy)
RTKCLI command outputs onlyCLI wrapper
lean-ctxCLI commands, MCP toolsCLI wrapper, MCP
Compresr, Token Co.Text sent to their APIHosted API call
OpenAI CompactionConversation historyProvider-native
vs Kompact

Kompact is a Python library focused strictly on compressing prompt text and JSON schemas. Copium is a full architecture handling streaming tool outputs, multi-turn session deduplication, and provider caching.

CopiumKompact
ArchitectureProxy, MCP, LibraryLibrary only
Tool OutputsSmartCrusher (statistical)Regex/Text truncation
Session Dedup✅ Cross-turn retrieval
PerformanceCore logic in RustPure Python
SafetyReversible (CCR)Lossy
vs Claw Compactor

Claw Compactor is a high-quality 14-stage pipeline for compressing prompts, but it's restricted to library deployment and irreversible compression. Copium incorporates similar quality-gated pipelines but wraps them in a zero-code proxy with reversible fail-safes.

CopiumClaw Compactor
Zero-Code Usage✅ Drop-in Proxy❌ Library only
Reversibility✅ Compress-Cache-Retrieve❌ Irreversible
Quality Gates✅ Auto-reverts on inflation❌ Manual
Provider SupportUniversal (Anthropic, Bedrock, etc)Manual injection
vs Headroom

Both Copium and Headroom compress AI agent context. Key differences:

CopiumHeadroom
Local LLM support✅ (Ollama, VLLM, llama.cpp)
KV cache precision detection✅ (auto-detect Q4_0/Q8_0/FP16)
Context paging✅ (virtual memory for LLM context)
TelemetryOff by default (opt-in)On by default (opt-out)
CCR integrity checks✅ (SHA-256 verification)
Windows support✅ Pre-built wheels (CI tested)Manual install only
vs ContextZip

ContextZip compresses static session archives (Claude Code JSONL only). Copium does that and live proxy compression, multi-agent support, reversible compression, and pre-compaction hooks.

CopiumContextZip
Live compression✅ (proxy/library/MCP)❌ (offline only)
Session archives✅ (Claude + Cursor + Aider + OpenCode)Claude Code only
Reversibility✅ (CCR with SHA-256)❌ (lossy)
Pre-compaction hooks✅ (auto-detect threshold, save state)
Post-compaction recovery✅ (restore from checkpoint)
Provider supportAll (Anthropic, OpenAI, Google, local)Anthropic only
DeploymentProxy, library, MCP, CLICLI only
Error compressionAdvanced (build grouping, Docker, normalization)Basic
Session search✅ (FTS5 full-text)
Cross-agent sharing✅ (export/import)
KV cache awareness✅ (precision detection)

ContextZip measured the problem. Copium solves it — live, offline, reversibly, universally.

vs ContextCrumb

ContextCrumb is an ONNX-based token compressor for agent workflows with an MCP proxy (contextcrumb-shrink). Copium provides superior compression across every dimension:

CopiumContextCrumb
Architecture37 transform modules, composable pipelineSingle ONNX model
Reversibility✅ CCR (perfect reconstruction)❌ Lossy only
Compression modes4 (lossless, lossy, hybrid, archive)1 (lossy)
Code awarenessAST-level, language-specific transformsToken-level, generic
IntegrationHTTP proxy + SDK + MCP (all three)MCP only
Tool handlingProgressive disclosure (70-98% reduction)Static compression (~40%)
Streaming✅ Full streaming support
CachingSemantic cache (skip repeated content)None
Session managementSave/restore/branch sessionsNone
ObservabilityFull dashboard, diff tools, metricsBasic inspection

Key advantages:

  1. Reversible compression — Copium's CCR lets agents retrieve original context when needed. ContextCrumb's compression is permanent.
  2. Progressive tool disclosure — instead of compressing tool schemas like ContextCrumb, Copium only sends tool stubs until a tool is actually called (70-98% token savings vs ContextCrumb's ~40%).
  3. Multi-mode compression — Copium applies lossless compression to code and lossy to comments, achieving better ratios with higher quality.
  4. Full workflow integration — session persistence, memory store, tool result caching. ContextCrumb only compresses.

Reproduce the benchmark: python -m benchmarks.contextcrumb_comparison_benchmark

ContextCrumb is a compressor. Copium is a context optimization platform.

vs RTK

RTK saves 60-90% on CLI stdout only (rtk git status). Copium saves 40-90% on all context — tool outputs, file reads, search results, conversation history, RAG chunks — and includes RTK for free via copium wrap.

Key differences:

RTKCopium
ScopeCLI stdout onlyEverything (tools, files, search, history)
Setuprtk git status per commandcopium wrap claude (one command)
ReversibilityNoneCCR — LLM can retrieve originals
ObservabilityNoneFull metrics dashboard
Strangeness taxHigh (abbreviated output confuses LLMs)Low (quality gate preserves critical markers)

Migration: pip install "copium-ai[proxy]" && copium wrap claude — drops in as a superset of RTK. Use --rtk-only to start with RTK-only compression, then unlock proxy features when ready.

See docs/migrating-from-rtk.md for the full migration guide.

Reproduce the benchmark: python -m benchmarks.rtk-vs-copium.bench_rtk_vs_copium

vs Provider-native compaction

Provider compaction (OpenAI, Anthropic) only compresses conversation history. Copium compresses everything — tool outputs, logs, RAG results, files — and routes each content type to the best compressor before it ever reaches the provider.


Local LLM Support

Copium is the compression layer for local AI. If you run Ollama, llama.cpp, LM Studio, or any local model, Copium makes your 8GB GPU act like 24GB and your 32K context feel like 128K.

Auto-Detection

Copium automatically detects running local backends:

copium doctor   # detects Ollama, llama.cpp, LM Studio and recommends config

One-Command Setup

# Auto-detect and configure for Ollama
copium wrap ollama

# Configure for llama.cpp server
copium wrap llamacpp

# Configure for LM Studio
copium wrap lmstudio

Supported Local Backends

BackendDetectionAuto-ConfigKV Cache Aware
Ollamalocalhost:11434YesYes
llama.cpplocalhost:8080YesYes
LM Studiolocalhost:1234YesYes
VLLMconfigurableYesYes

KV Cache Precision Detection

When a quantized model's KV cache is too full, accuracy collapses — not gradually, but off a cliff:

Q4_0 KV Cache at 32K context = 2% accuracy (vs 37.9% for FP16)

Copium detects your model's quantization type and starts compressing aggressively before you hit that cliff.

VRAM-Aware Compression

Copium monitors GPU memory and adapts compression in real-time:

from copium.integrations.local import AdaptiveCompressor

compressor = AdaptiveCompressor()
config = compressor.get_config()
# Automatically scales from light → aggressive based on VRAM pressure

Hardware Presets

Pre-configured for common GPU setups:

GPU VRAMPresetCompressionSmart Zone
8GBaggressiveAll transforms35%
12GBstandard+5 transforms40%
16GBmoderate4 transforms40%
24GB+light2 transforms45%

Smart Routing (Triage Engine)

Route simple tasks to your local model, compress complex tasks for cloud:

from copium.integrations.local import LocalTriageEngine

engine = LocalTriageEngine(
    local_model="qwen3:8b",
    cloud_model="claude-sonnet-4-20250514",
    triage_threshold=0.7,
)
decision = await engine.route(messages)
# Simple tasks stay local (free), complex tasks get compressed for cloud

Expected savings: 40-79% fewer cloud tokens on typical coding workloads.

Streaming Compression

For VRAM-constrained environments, compression runs in streaming mode with zero GPU memory overhead:

from copium.integrations.local import StreamingCompressor

compressor = StreamingCompressor(chunk_size=4096)
for chunk in compressor.compress_iter(large_context):
    # Processes chunk-by-chunk, never buffers full content
    send(chunk.content)

It also supports cold/hot context paging — effectively virtual memory for your LLM's context window, cutting context by up to 93% for long sessions.


Configuration

Create copium.json in your project root to customize behavior:

{
  "mode": "optimize",
  "cache_aligner": { "enabled": true },
  "session_dedup": {
    "enabled": true,
    "similarity_threshold": 0.85
  },
  "error_compressor": {
    "enabled": true,
    "max_stack_frames": 3,
    "preserve_security_warnings": true
  }
}

Disable specific transforms per request:

curl -H "X-Copium-Disable: toon,code_compressor" \
     http://localhost:8082/v1/chat/completions

Environment variables:

export COPIUM_PORT=8082
export COPIUM_HOST=0.0.0.0
export COPIUM_LOG_LEVEL=debug
export COPIUM_CCR_TTL_SECONDS=1800   # how long compressed data is cached

Compression presets

copium proxy --preset minimal      # Structural transforms only; safest
copium proxy --preset standard     # Full stack; recommended (default)
copium proxy --preset aggressive   # Maximum savings; more aggressive
copium proxy --preset local-llm    # Optimized for Ollama/VLLM/llama.cpp
copium proxy --preset lossless     # Zero quality loss transforms only

# Inspect any preset without starting the proxy:
copium preset aggressive

View your savings

copium status                  # proxy health, uptime, today's savings
copium status --verbose        # also show all-time stats
copium status --json           # machine-readable JSON
copium status --prompt         # one-liner for shell prompts: ⚡ 38% (empty when stopped)
copium stats                   # detailed savings breakdown
copium stats --period session  # current session only
copium stats --json            # machine-readable output

Check agent status

copium agents                  # list all detected agents and wrap status
copium agents --installed      # show only installed agents
copium agents --json           # machine-readable output

View logs

copium logs                    # show last 100 lines of proxy logs
copium logs -n 50              # show last 50 lines
copium logs -f                 # follow logs in real time (Ctrl+C to stop)
copium logs --level ERROR      # filter by log level

Version and diagnostics

copium version                 # show version, Python, platform, install method
copium version --json          # machine-readable output
copium doctor                  # diagnose installation and configuration

Always-on Background Service

The biggest daily friction with a proxy tool is keeping it running. Copium solves this two ways:

copium start                  # start proxy, detach from terminal — survives shell exit
copium stop                   # stop gracefully (shows session summary: duration, tokens saved, all-time totals)
copium restart                # restart (picks up config changes)
copium status                 # check running/stopped, uptime, savings today
copium status --json          # machine-readable output (for scripts / shell prompts)
copium status --prompt        # minimal one-liner (⚡ 38%) — empty string when stopped
copium ping                   # fast health check: exit 0 running, exit 1 stopped
copium ping --json            # {"status":"running","uptime_s":15423,"tokens_saved_today":312481}

copium start auto-creates a deployment profile on first run. The PID file lives at ~/.copium/deploy/default/runner.pid; logs at ~/.copium/deploy/default/runner.log.

Shell prompt integration

Show a live ⚡ 38% indicator in your shell prompt when the proxy is active:

Starship — add to ~/.config/starship.toml (or run copium init to add it automatically):

[custom.copium]
command = "copium status --prompt"
when    = "copium ping"
format  = "[$output](https://github.com/iKislay/copium/blob/HEAD/$style) "
style   = "bold yellow"

bash / zsh — add to ~/.zshrc or ~/.bashrc:

_copium_prompt() {
  local _s
  _s="$(copium status --prompt 2>/dev/null)"
  echo "${_s:+[$_s] }"
}
PROMPT_COMMAND='_copium_prompt_val=$(_copium_prompt); ${PROMPT_COMMAND:-:}'
export PS1='${_copium_prompt_val}${PS1}'

copium status --prompt outputs nothing when the proxy is stopped, so the segment disappears automatically. copium remove cleans this up along with everything else.

First-request feedback

The first time any request is compressed, Copium prints a one-time celebration to your terminal:

🎉 First request compressed!
   Tokens: 4.8K → 892  (81.5% saved, ~$0.01 saved on this request)

   View live savings:  copium tui
   Or open:           http://localhost:8787/dashboard

This only ever shows once — the flag is stored in ~/.copium/state.json.

copium start --port 9090          # custom port
copium start --preset aggressive  # aggressive compression
copium start --memory             # enable persistent memory
copium start --no-wait            # don't wait for ready signal (fire-and-forget)

Auto-start on login (system service)

For teams or power users who want the proxy running before they even open a terminal:

copium service install        # install as systemd user unit (Linux) or launchd agent (macOS)
copium service status         # show service health
copium service logs           # tail service logs (uses journalctl on Linux)
copium service logs -f        # follow logs continuously
copium service remove         # uninstall the service (keeps your data)

After copium service install, the proxy starts automatically at login and restarts on failure. You never have to think about it again.

Shell completion

Enable tab completion for faster command lookup:

# Bash
copium completions bash >> ~/.bash_completion

# Zsh
copium completions zsh >> ~/.zshrc

# Fish
copium completions fish > ~/.config/fish/completions/copium.fish

# PowerShell
copium completions powershell | Out-String | Invoke-Expression

After installing, reload your shell or run source ~/.zshrc (zsh) / source ~/.bash_completion (bash).

Platform details:

PlatformMechanismConfig location
Linuxsystemd user unit~/.config/systemd/user/copium.service
macOSlaunchd LaunchAgent~/Library/LaunchAgents/com.copium.default.plist
WindowsWindows Service / Task Schedulervia sc.exe or schtasks

Architecture (for the curious)

The full request pipeline:

Request → Cache Aligner → Differential Response → Session Dedup
        → KV Cache Detection → Content Router → Error Compressor
        → Paging → Output Compressor → TOON Encoder → Provider

ContentRouter decides which compressor to use for each piece of content. It detects the content type (JSON array, log output, code, HTML, search results, git diff) and routes it to the appropriate transform. The routing decision is logged for transparency.

SmartCrusher uses statistical analysis — variance-based change point detection, Kneedle algorithm for optimal K, BM25 + embedding relevance scoring — to compress tool output arrays while keeping the items the LLM actually needs. It never generates text; the output contains only items from the original array.

CCR (Compress-Cache-Retrieve) makes compression reversible. When SmartCrusher compresses a 1,000-item array down to 20 items, the original 1,000 items are stored locally (SHA-256 verified). The LLM receives a retrieval marker. If it needs more data, it calls copium_retrieve(hash, query) and gets the relevant subset. Worst case: the LLM retrieves what it needs. Best case: it never needs to.

Session Dedup tracks content hashes (exact SHA-256 + MinHash for near-duplicates) across the entire conversation. If a file read from turn 3 shows up again in turn 15, only a reference marker goes to the LLM. The proxy overhead for this lookup is sub-millisecond.

TOON Encoder converts JSON arrays into pipe-delimited tables — the same semantic content, dramatically fewer tokens. [{"name": "alice", "age": 30}, {"name": "bob", "age": 25}] becomes name | age\nalice | 30\nbob | 25. The LLM reads both perfectly; the table uses 60–80% fewer tokens.

Cache Aligner stabilizes prompt prefixes so provider KV caches actually hit. Anthropic and OpenAI offer prefix caching (massive cost reduction), but a single changed character busts the cache. Cache Aligner moves dynamic content (dates, session IDs, request hashes) to the end of system messages so the stable prefix stays stable.


Integrations

Your setupHow to use
Any Python appcompress(messages)
Anthropic / OpenAI SDKCopiumClient(original_client=...)
Vercel AI SDKCopium middleware
LiteLLMCallback integration
LangChainCopiumChatModel(your_llm)
AgnoCopiumAgnoModel(your_model)
MCP clientspip install "copium-ai[mcp]"
Any HTTP clientcopium run (proxy mode)
Claude Codecopium wrap claude
Codexcopium wrap codex
CursorSet API base URL in settings
OpenCodeexport OPENAI_BASE_URL=http://localhost:8082/v1
Aidercopium wrap aider
GitHub Copilotcopium wrap copilot
Mistral Vibecopium wrap vibe
Cline (VS Code)copium wrap cline
Continue (VS Code/JetBrains)copium wrap continue
Antigravity⚠️ Not supported (no proxy settings)
AWS Bedrockhttp://localhost:8082/bedrock
Google Vertex AIhttp://localhost:8082/vertex
Ollamacopium run --backend ollama

Documentation

Start hereGo deeper
QuickstartArchitecture
ProxyHow compression works
MCP toolsBenchmarks
ConfigurationLimitations
Migration guidePresets

Contributing

git clone https://github.com/iKislay/copium.git && cd copium
uv sync && uv run pytest

See CONTRIBUTING.md.


License

Apache 2.0 — see LICENSE.


Acknowledgments

  • Pichay (arXiv:2603.09023) — Virtual memory paging for LLM context
  • The r/LocalLLaMA community — For identifying and stress-testing the precision cliff problem

// compatibility

Platformscli, api, desktop, web, mobile
Operating systems
AI compatibilityclaude
LicenseApache-2.0
Pricingopen-source
LanguagePython

// faq

What is copium?

Context optimization layer for LLMs. 65-90% token savings with zero quality loss. Drop-in proxy for Claude, GPT, Gemini, and local LLMs (Ollama/VLLM/llama.cpp). Features KV cache-aware compression, session dedup, error cards, and Pichay-proven context paging.. It is open-source on GitHub.

Is copium free to use?

copium is open-source under the Apache-2.0 license, so it is free to use.

What category does copium belong to?

copium is listed under rag in the Claudeers registry of Claude-compatible tools.

0 views
11 stars
unclaimed
updated about 7 hours ago

// embed badge

copium on Claudeers
[![Claudeers](https://claudeers.com/api/badge/copium.svg)](https://claudeers.com/copium)

// retro hit counter

copium hit counter
[![Hits](https://claudeers.com/api/counter/copium.svg)](https://claudeers.com/copium)

// reviews

// guestbook

0/500

// related in RAG & Knowledge

🔓

✨ Light and Fast AI Assistant. Support: Web | iOS | MacOS | Android | Linux | Windows

// ragChatGPTNextWeb/TypeScript88,415MIT[ claude ]
🔓

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant contex…

// ragthedotmack/JavaScript86,462Apache-2.0[ claude ]
🔓

A light-weight and powerful meta-prompting, context engineering and spec-driven development system for Claude Code by TÂCHES.

// raggsd-build/JavaScript64,711MIT[ claude ]
🔓

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 60-95% fewer tokens, same answers. Library, proxy, MCP server.

// ragheadroomlabs-ai/Python58,175Apache-2.0[ claude ]
→ see how copium connects across the ecosystem