ctx-gate: Reduce LLM Context Tokens Through a Proxy

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
View on GitHub

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

View on GitHub

Related repositories

Similar repositories that may be relevant next.

OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️