virtual-context cloud: a 3 million token virtual window served at 80K real tokens
virtual-context
Virtual memory for LLM context. Give your agent a context window of tens or hundreds of millions of tokens; the model only ever sees the part that matters.
Your client sets contextWindow: 20000000 (or 200,000,000). Your model's real window is 200K. virtual-context sits between them and makes it work, the same way an operating system lets a process address more memory than physically exists. The client keeps sending its whole conversation; virtual-context stores all of it, organizes it by topic, and forwards the model a compact window of what matters for the current turn, at a size you choose. Nothing is discarded, and anything older can be paged back in at full fidelity. The dashboard above shows a live 3 million token conversation served at 80K real tokens.
It runs as an HTTP proxy, so integration is a base-URL change; a Python SDK and an MCP server are there for direct use.
Why
- Memory that lasts. What the user said at turn 12 is still recallable at turn 1,000, across sessions, clients and models.
- Better answers from less context. A focused window of relevant summaries and facts beats a raw window of everything, where the one fact you need is buried.
- Lower cost. Smaller payloads, arranged to keep providers' prompt caches warm.
- Group chats that know who said what. Every message keeps its sender, facts keep their author, and search can be scoped to one person.
- One memory everywhere. Build context in Claude Code, continue it from Telegram, query it from Cursor.
How it works
client ──> virtual-context proxy ──> model provider
│ before the call: retrieve topics and facts for this turn,
│ assemble a bounded window
│ after the call: store the turn, tag it, compact when needed
v
store (SQLite or PostgreSQL)
canonical turns every message verbatim, with sender and channel
segments + facts per-topic summaries and structured facts
topic summaries one digest per topic, the bird's-eye view
Recent turns stay verbatim. Older turns are grouped by topic, summarized and mined for facts. Each turn, the model gets recent turns plus the topics and facts relevant to the question, and a topic index telling it what else it can open with built-in tools (vc_expand_topic, vc_find_quote, vc_recall_all, and others).
Quick start
pip install "virtual-context[proxy,embeddings]" # Python 3.11+
virtual-context uses a language model of your choice to tag turns and write summaries. Pick where it runs:
# A local model server (Ollama, LM Studio, llama.cpp, vLLM): nothing leaves your machine
virtual-context init recommended-local
# Or a hosted model through OpenRouter
virtual-context init recommended
export OPENROUTER_API_KEY=...
Either writes virtual-context.yaml; set tag_generator.model and summarization.model to the model you want. Then start the proxy and point your client at http://127.0.0.1:5757 instead of the provider:
virtual-context proxy --upstream https://api.anthropic.com
A dashboard runs at http://127.0.0.1:5757/dashboard.
The two presets are the hosted service's configuration on one machine and differ only in where the model runs: SQLite storage, paging tools on, fact curation on. Answer quality depends on the model you pick. scripts/smoke_recommended.sh checks a preset end to end from a clean install. The optional parts (PostgreSQL vector search, the judgment layer, group attribution) are each a section of docs/configuration.md; virtual-context presets list shows every preset, and docs/install.md covers install options and running it as a service.
The proxy accepts Anthropic Messages, OpenAI Responses, OpenAI Chat Completions and Gemini requests. The paging tools are injected for Anthropic, OpenAI Responses and Gemini; Chat Completions clients get retrieved context but no tools.
Hosted: virtual-context.com runs the same engine as a service with the dashboard and cost reports; you change your base URL and nothing else.
Integrations
Claude Code
export ANTHROPIC_BASE_URL=http://127.0.0.1:5757
Tool output (file reads, searches, command results) is collapsed into restorable stubs, and when Claude Code trims its own history, the missing turns are restored from storage.
Any client with a base URL (Cursor, Continue, your own app)
client = anthropic.Anthropic(base_url="http://127.0.0.1:5757")
client = OpenAI(base_url="http://127.0.0.1:5757/v1")
OpenClaw: use the OpenClaw plugin. Settings for direct proxy use are in docs/install.md.
Python SDK
from virtual_context import VirtualContextEngine
engine = VirtualContextEngine(config_path="./virtual-context.yaml")
assembled = engine.on_message_inbound(message=user_message, conversation_history=messages) # before the LLM call
report = engine.on_turn_complete(messages) # after it
MCP server: eight tools (recall_context, compact_context, expand_topic, recall_all, remember_when, find_quote, search_summaries, domain_status) plus topic resources, for Claude Desktop, Cursor or any MCP client.
Features
| Feature | What it does | Docs |
|---|---|---|
| Topic memory | Each turn is tagged by topic; older turns become per-topic segment summaries and one digest per topic. Tags converge on an existing vocabulary instead of piling up synonyms. | engine |
| Structured facts | Compaction extracts facts (subject, verb, object, status, time, source turns). Newer facts supersede older ones, and facts can be retrieved by topic and by meaning. | fact lifecycle |
| Retrieval | Topics are ranked by tag overlap, full-text match and embedding similarity, with full-text and semantic search over stored turns as a fallback. | engine |
| Demand paging | The model sees topic digests for cold topics and segment summaries for relevant ones, and opens full text through tools when it needs detail. | engine |
| Time-scoped recall | "What changed between June and July?" resolves by date math on stored timestamps, not by model guessing. | engine |
| Group memory | Sender and channel are stored on every message, facts keep their author, members get person cards, and search can be scoped to one speaker. Direct-message content never appears in a server's context. Off by default. | attribution |
| Tool and media compression | Finished tool exchanges become stubs restorable with vc_restore_tool; screenshots are recompressed with originals kept. |
proxy |
| Prompt-cache aware | Injected context sits after a cache breakpoint, and payload rewrites wait until the provider's cache would have expired anyway. | engine |
| A ceiling you choose | Set context_window to any size; the virtual window the client sees is independent of it. |
configuration |
| Truncation recovery | When a client trims its own history, the missing turns are restored from storage. | proxy |
| History import | ChatGPT, Claude and Grok exports arrive tagged and searchable (virtual-context import). |
commands |
| Native vector search | On PostgreSQL with pgvector, quote search, segment candidates and fact search rank inside the database instead of in each worker. | native vector search |
| Judgment layer (optional) | A typed judgment model can make individual decisions: which topics and segments to retrieve, which facts to keep, which existing tags a turn belongs to, and more. Each decision runs in legacy, shadow (logged side by side) or jev mode and falls back to the built-in behavior on any failure. Needs a TypeSafe API key. |
configuration |
Commands in any conversation
Type these as ordinary messages in a connected client; the proxy handles them without calling the model.
| Command | What it does |
|---|---|
VCATTACH <label|id> |
Reattach this client to another stored conversation |
VCLABEL <name> |
Set the conversation label (no argument shows it) |
VCSTATUS |
Conversation id, label, turns, segments, active topics |
VCRECALL <query> |
Search stored context and bring matching topics into the next turn |
VCCOMPACT |
Compact now |
VCLIST |
List conversations with labels and turn counts |
VCFORGET <tag> |
Delete a topic's segments and summaries |
VCMERGE INTO <label|id> |
Merge this conversation's stored data into another |
VCATTACH is a durable redirect: nothing is deleted and old references keep resolving, so two clients (or two agents) can share one memory. Details: docs/commands.md.
Running it in production
- Storage: SQLite by default; PostgreSQL (
pip install "virtual-context[postgres]") for multi-worker deployments. With pgvector installed,virtual-context admin migrate-semantic-vectorsprepares in-database vector search. - Multi-worker safety: compactions run under leased, fenced operations, lifecycle changes are epoch-guarded, and a backlog sweeper compacts conversations whose traffic never triggers it inline.
- Operator tooling:
virtual-context adminhas 27 guarded backfill, repair and migration commands with dry-run modes. - Security: dashboard endpoints are open until you set
VC_DASHBOARD_TOKEN; the default bind is loopback only. - Observability: per-stage timing logs, request captures in the dashboard, and per-call cost telemetry.
Architecture, including the canonical-turn model and the REST prepare/ingest surface: docs/architecture.md.
Benchmarks
On 100 questions from LongMemEval-500, with the same reader model (Claude Sonnet 4.5):
| virtual-context | Full raw history | |
|---|---|---|
| Correct | 95/100 | 33/100 |
| Tokens per question | 52,347 | 117,582 |
| Cost per question | $0.16 | $0.36 |
These are historical results: the original run's provenance is incomplete and they are not a measurement of the current pipeline. Configuration, results by category, the per-question table and how new runs are recorded: docs/benchmarks.md.
Documentation
| Page | Covers |
|---|---|
| architecture.md | Memory model, request pipeline, multi-worker coordination, identity |
| engine.md | Compaction, tagging, retrieval, code mode, cache awareness |
| fact-lifecycle.md | How facts are extracted, superseded and retrieved |
| attribution.md | Group conversations: who said what, person cards, speaker search |
| proxy.md | Proxy internals, routing, dashboard, streaming, endpoints |
| native-vector-search.md | PostgreSQL + pgvector ranking and its migration |
| configuration.md | Every config key with its default, including the judgment layer |
| commands.md | In-conversation commands, the CLI, import, admin tooling |
| install.md | Install paths, daemons, multi-instance setups |
| design.md | Why it is built this way, and how it compares with RAG and plain compaction |
| benchmarks.md | Suites, results, how to run them |
Development
git clone https://github.com/virtual-context/virtual-context.git
cd virtual-context
python -m venv .venv && source .venv/bin/activate
python -m pip install uv==0.9.30
uv sync --locked --extra all --extra dev
.venv/bin/python scripts/check_contracts.py
License
AGPL-3.0, Copyright Y. Ahmed Kidwai. For commercial licensing: ahmed@kidw.ai
Metadata
Release files for virtual-context 0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| virtual_context-0.6.tar.gz | 5.3 MB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| virtual_context-0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.9 MB
Release files / virtual_context-0.6.tar.gz
| Download URL | virtual_context-0.6.tar.gz |
|---|---|
| Size | 5.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec7feed8161c3bec88a8202e2210c0ee7a31534b72e75be9412f9fe00a55e4d9
|
|
BLAKE2b-256 checksum How to use checksums |
ea42ddc9f0a8d49bdec5cbbee7f24bea036025e954ddcb66fca042ee10a66e68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.
Transparency logRelease files / virtual_context-0.6-py3-none-any.whl
| Download URL | virtual_context-0.6-py3-none-any.whl |
|---|---|
| Size | 2.5 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a1d18453f84ab1087366002296e62aae288b4d2826fbfb3bfb8214911fdc825b
|
|
BLAKE2b-256 checksum How to use checksums |
22305be8a4096d6caf373b618aa2dcbd3e84a821e3c1060fc9f3e9d2f6bf6d09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.
Transparency logSecurity for virtual-context 0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for virtual_context-0.6.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.