ctx-gate: Reduce LLM Context Tokens Through a Proxy

Summary
ctx-gate is a Python proxy that compresses LLM conversation context while aiming to preserve facts relevant to the current prompt. It supports Anthropic and OpenAI-compatible APIs, with evaluation tools to check retention and token savings.
At a glance
- Language
- Python
- License
- MIT
- Stars
- 0
- Forks
- 0
- Added to OSRepos
- September 16, 2026
- Last analyzed
- October 4, 2026
Topics
Click on any tag to explore related repositories
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Overview
ctx-gate sits between an IDE or coding assistant and an LLM provider. It reduces repeated conversation history and verbose tool output, and can retain prompt-relevant earlier details, with the goal of lowering token use without changing the client workflow.
It is most relevant to developers who use coding agents for long sessions and want to measure the effects of compression. The README describes the project as early-stage and reports benchmark results where different compression methods perform differently, so it is worth evaluating against your own workload rather than assuming a fixed saving.
Key Features
- Proxy endpoints for Anthropic Messages and OpenAI-compatible chat completions, including streaming.
- Context compression using summaries, relevance-based retention, file diffs, and tool-output trimming.
- Optional semantic relevance and code retrieval, with lexical or TF-IDF fallbacks.
- Task-shift detection and model-tier routing based on prompt signals.
- Session checkpoints, per-client state isolation, and persistent usage statistics.
- Faithfulness evaluation and benchmark commands for comparing token savings with fact retention.
Use Cases
- Developers using Claude Code who want to reduce repeated context and tool-output tokens without changing their normal client workflow.
- Teams using Cursor, Continue.dev, or OpenAI SDK clients that want to route requests through a local optimization proxy.
- Long-running coding sessions where logs and repeated file contents make up a significant share of the prompt.
- Maintainers testing context-compression changes who need a repeatable fact-retention check or CI gate.
Project Facts
- Language: Python
- License: MIT
- Stars: 0
- Forks: 0
- Topics: ai-agents, anthropic, claude, claude-code, context-management, cursor, developer-tools, gateway, llm, llms, mcp, openai, prompt-engineering, proxy, token-optimization
- Archived: No
Getting Started
Install and start the default Anthropic proxy:
pip install ctx-gate
ANTHROPIC_API_KEY=sk-ant-... python ctx_gate.py serve
For provider configuration, client setup, optional dependencies, and evaluation instructions, see the repository README.
Alternatives
- headroom: Headroom compresses tool outputs, files, logs, and retrieval context through library, proxy, or MCP integrations, while ctx-gate focuses on conversation context.
Considerations
- Token savings depend on the session. The README reports minimal compression for short Q&A and much larger savings for sessions with verbose logs; these are not guaranteed for other workloads.
- The bundled evaluation measures fact retention deterministically, while answer-accuracy evaluation requires an API key. Benchmark conclusions depend on the test corpus and method.
- Semantic relevance, RAG, and LLM-based summaries are optional and can add dependencies or request latency. Defaults use lexical relevance and extractive summaries.
- The README describes the project as early-stage. Check provider model IDs and configuration for your setup, and note that a streaming connection dropped after output begins is not retried.
Found this useful?
Share it with someone who would like ctx-gate.
Comparisons
Source repository
Open the original repository on GitHub.
9 counted GitHub visits
Related repositories
Similar repositories that may be relevant next.

omnigent: Orchestrate AI Coding Agents Across Harnesses
October 5, 2026
Omnigent provides a shared orchestration layer for AI coding agents, with policies, sandboxing, and team collaboration. It suits developers who want to combine agent runtimes and access sessions across devices without tying workflows to one harness.

agentevals: Evaluate AI Agents from OpenTelemetry Traces
October 4, 2026
agentevals scores AI agent behavior from existing OpenTelemetry traces, without rerunning agents or making extra model calls. It suits teams building instrumented agents that need local evaluation, golden-set checks, or CI quality gates.

web-design: Create Consistent Web Pages with a Claude Code Skill
October 3, 2026
web-design is a Claude Code skill that turns product briefs, reference URLs, or screenshots into an editable design specification before generating web code. It is suited to developers and designers who want a repeatable, spec-led workflow for building consistent pages.

oomwoo: Build a DIY Robot Vacuum
October 2, 2026
OOMWOO is a planned, hackable robot vacuum built around Raspberry Pi, ROS2 and 2D LiDAR. It is aimed at makers who want to build and customize a locally controlled vacuum, but its hardware and build instructions are still in development.