Project Files
Project Files
README
Never run out of context in LM Studio again. When a long or agentic chat approaches the model's context limit, context-compressor automatically compresses old messages into a faithful, task-aware summary and the conversation just keeps going. Your full chat stays on screen; only the prompt sent to the model shrinks.
Real numbers from a real chat: a 645,516-token agentic conversation (600%+ over a 122k context window) compacted to a 33,214-token prompt β 95% smaller, with the model still answering questions about things said before compaction.
README
Never run out of context in LM Studio again. When a long or agentic chat approaches the model's context limit, context-compressor automatically compresses old messages into a faithful, task-aware summary and the conversation just keeps going. Your full chat stays on screen; only the prompt sent to the model shrinks.
Real numbers from a real chat: a 645,516-token agentic conversation (600%+ over a 122k context window) compacted to a 33,214-token prompt β 95% smaller, with the model still answering questions about things said before compaction.
/compress or /compact β type either in chat to force compaction now. You get a token before/after report instead of a model reply./usage β instant report of real context usage: prompt size vs context window, auto-compact headroom, transcript size, and compression state. The model also gets a get_context_usage tool, so just asking it "how much context do I have left?" works too.agentic-workspace/v1 tool results before generic truncation. It keeps transaction/run/job/To-Do/research/query/source IDs, next actions, command exit evidence, hashes, URLs, report/state paths, and artifact references while dropping declared bulky diffs, page bodies, listings, and command streams. Approvals staged by the workspace's permission gate survive too β the approval_*/plan_* id, its kind, and the exact call to re-issue after you type /accept.npm run bench) measures seeded-fact recall after compaction and after consolidation, prompt reduction, latency, structural integrity, and cache determinism; results are committed under bench/results/.Compacting ββββββββββββ 34% β chunk 2/5), and while compression is active each turn shows the real prompt size (Prompt: ~33,214 tokens ββββββββ 27% of 122,112). Configurable: status line, sender name, or off.~/.lm-context-compressor/cache.json, atomic writes) and survive restarts. Edit or regenerate any old message and the cache cleanly recomputes. Abort mid-compaction and finished chunks are kept. Failures are visible, never silent, and never corrupt state./compress anytime.git clone <this repo> cd lm-context-compressor npm install lms dev --install -y # installs into LM Studio (or run update.bat on Windows)
For live-reload development use lms dev instead.
| Setting | Default | Meaning |
|---|---|---|
| Auto-compact | on | Turn off for bulk-data tasks where the past IS the data |
| Compaction threshold | 75% | Of the model's context window |
| Compact down to | 55% | Hysteresis floor: once triggered, compact well below the trigger so long agentic turns have headroom |
| Reserved output tokens | 2000 | The prompt must fit within context minus this reply reserve |
| Absolute token trigger | 0 (off) | Absolute-token alternative to the %, handy for testing |
| Recent context kept verbatim | 6000 tokens | The newest conversation is never summarized |
| Summarize in chunks of | 16000 tokens | Chunks are cached and reused across compactions |
| Max chunks per pass | 0 (auto) | Cap the work per run; progress carries over |
| Tool rounds per pass | 6 | Agentic turns run in passes so compaction can happen mid-task; 0 = one uncapped loop |
| Max tool result size | 4000 tokens | 0 = unlimited |
| Max tokens per chunk summary | 1500 | |
| Summarizer prompt | Auto (recommended) | Auto/Full (10-section)/Compact β auto always uses the full prompt (bench-confirmed best recall); Compact can be forced here and is also used automatically as a rescue when a model's reasoning runs away |
| Summary budget | 12000 tokens | Above this, oldest summaries consolidate into one (0 = unbounded) |
| Attachment memory | on | Preserve document/image content before compressing past it |
| Announce compaction in chat | on | Token before/after note |
| Prompt meter | Status line | Where the real prompt size is shown |
With the Agentic Workspace plugin (rootmonster/agentic-workspace) 0.2.0+, context-compressor does more than pass tools through. It recognizes the plugin's durable result protocol and compacts it structurally:
large tool result βββ preserve: summary, retention.facts, IDs, status, next action βββ preserve: source URL/hash/path and transaction/job/run artifacts βββ preserve: staged approval β id, kind, and the exact resume call βββ omit: declared diff preview, page text, search result bulk, stdout/stderr βββ recover later from .agentic state using the preserved IDs
From Agentic Workspace 0.3.0 every mutation goes through a permission gate, and a blocked call comes back as a staged approval instead of a result. Those envelopes survive compaction whole: the approval_*/plan_* id, status, title, and the resume call kept byte for byte, so /accept still resumes the right thing after the chat compacted. The recovery index of workspace_inspect { action: "changes" } β its approvals, plans, and background-command jobs entries β is preserved for the same reason.
The summary schema has dedicated Durable workflow state, Verification & evidence, and Source ledger sections. Search snippets remain discovery hints; fetched source_* records and their stored paths remain evidence. The summarizer prompts and the protocol rendering are part of the cache namespace, so old summaries are not silently reused under new preservation rules.
See AGENTIC_WORKSPACE_INTEGRATION.md for the protocol and end-to-end test sequence.
Release validation β the full native test runs and a live benchmark matrix across eight model families β is documented in RELEASE_VALIDATION.md.
The context ring at the bottom still shows a huge percentage β is it working? Yes. LM Studio's built-in ring counts the visible transcript, which this plugin deliberately never shrinks (your scrollback is sacred). The prompt the model actually receives is what gets compressed β read the plugin's own meter line for the true number. A feature request is open with LM Studio to let plugins update the built-in ring.
Does the model really remember things from before compaction? It continues from a structured summary that preserves goals, decisions, code, findings, and next steps verbatim where it matters. It is compression β fine detail in the middle of old conversation fades first. Anything in the recent-tokens window is untouched.
When should I NOT use it?
When the old messages are the data: log analysis, hex dumps, bulk document review. Summarizing destroys exactly what you need. Flip Auto-compact off for those chats (/compress stays available if you change your mind).
What models does it work with? Any normal chat model β token math uses each model's own tokenizer and reported context length; prompt formatting goes through LM Studio's template machinery. Tool passthrough needs a tool-capable model. Selecting a generator plugin as the model isn't supported (nothing to count tokens with) β the plugin says so and passes through.
A first compaction on a giant chat takes a while. Each chunk is one summarization call on your local model. The progress bar shows real progress, aborting keeps completed chunks, and "Max chunks per pass" lets you spread the work over multiple runs. Once cached, chunks are never re-summarized.
Tested live against eight model families for the 0.7.0 release (Qwen3 and Qwen3.5/3.8, DeepSeek-R1 distill, Gemma 3, Llama 3.2 at 3B and 18B, gpt-oss, GLM) β results committed under bench/results/. 0.8.0 changes only how the Agentic Workspace protocol is compacted, so that matrix was not re-run for it.
The other context tools on the LM Studio Hub, honestly compared:
| context-compressor | context-compactor | kosmix/compact | |
|---|---|---|---|
| Auto-compaction on threshold | β with hysteresis floor | β | β manual |
| Bounded summary growth (hierarchical consolidation) | β | β grows forever | β |
| Attachment content preserved through compression | β | β | β |
| Reproducible benchmark suite in-repo | β | β | β |
| Mid-task compaction (marathon tool loops) | β | β | β |
/compress Β· /compact Β· /usage commands | β | β | partial |
| Exact templated-prompt token accounting | β | β estimates | β |
| Survives edited/regenerated messages | β content-addressed cache | β documented limitation | β |
| Resumable, abortable compaction | β chunk-granular, persisted | partial | β |
| Tool passthrough + result capping | β + callId-correlated results | β | β |
| Ask the model "how much context is left?" | β
get_context_usage tool | β | β |
| Summary injection hardening (provenance, no authority escalation) | β | β | β |
| Test cases in source | 289, written test-first | some | β |
(persistent-memory solves a different problem β cross-chat fact storage β and composes fine with this plugin.)
| You see | It means |
|---|---|
Compacting β¦ chunk n/m (k cached chunks reused) | Normal β previously summarized chunks are being reused; stopping is safe, finished chunks are saved |
Mid-task compaction β¦ β continuing | A long agentic turn grew the context; it was compacted between tool passes and the task continues |
Prompt β¦ exceeds the safe budget | Even after safety compaction the prompt is too big β raise the context length, lower "Reserved output tokens", or reduce "Recent context kept verbatim" |
Preserving attachment "x" (1/2)β¦ | A document/image is being extracted into attachment memory before its region compresses |
Consolidating N summaries into oneβ¦ | Accumulated summaries outgrew their budget and are being folded into one denser summary β normal on very long chats |
Compacted into the verbatim tail to fit | The prompt plus tool definitions would not fit even after normal compaction, so recent rounds (never your current message) were summarized too |
Consolidation disabled for this model this session | This model spends any budget reasoning on the merge without ever answering (measured on qwen3.8-27b) β the doomed retries are stopped; summaries stay unmerged and everything else keeps working |
Transient engine error β retrying onceβ¦ | The engine dropped the connection mid-reply; the pass is retried (only when nothing side-effectful ran) |
Compaction floor raised to ~N tokens β¦ (β, once) | Information, not a fault: your "Compact down to" % is smaller than the system prompt + summary budget + kept-verbatim need (a tools provider's schemas alone can exceed 30% of a 16k window), so compaction targets the raised floor. /usage shows both numbers. |
Compaction cannot get below its trigger β¦ (β) | The raised floor is at or above the trigger, so compaction would run every turn: raise the model's context length, or lower "Recent context kept verbatim" or "Summary budget" |
context-compressor needs a real model as the token source | A generator plugin is selected as the model; pick a real model |
| Meter says one thing, LM Studio's ring another | The ring counts the visible transcript (which never shrinks); the meter counts what the model actually receives β see FAQ |
The plugin registers an LM Studio prediction loop handler: each turn it receives the full chat, maps it to a compressed view, and runs your selected model over that view.
/compress does the lot.[system prompt + summary (merged into one system message) + recent tail] streams through your model with tools passed through and results rendered back into the chat.npm run bench:static # structural/determinism checks, no model needed npm run bench # full run against your local LM Studio model
Measures seeded-fact recall from the compacted view (and again after a forced
consolidation, to quantify drift), prompt reduction, per-chunk latency,
structural integrity, and cache determinism across four synthetic fixtures
(coding agent, research, contradictory updates, tool spam). Results are
stamped with the model id and committed under bench/results/ β
see bench/README.md for metric definitions and caveats.
npm install npm test # 308 unit tests (vitest), written test-first npm run typecheck lms dev # hot-reload dev server
Pure logic (hashing, cut rules, chunk planning, truncation, caching) is fully unit-tested; the LM Studio integration layer is deliberately thin.
Free for personal and internal professional use β use it, modify it, self-host it at home or at work at no cost.
Commercial embedding requires a license: incorporating this software (or a derivative) into a product or service that people pay for requires a separate commercial agreement with the author β contact via GitHub or the LM Studio Hub profile. See LICENSE for the full terms. (Hub revisions 1β15 were published under MIT; that grant remains valid for those copies.)
what the model receives what you see on screen
ββββββββββββββββββββββββββ ββββββββββββββββββββββββββ
β system prompt β β every message you ever β
β + task-aware summary β βββ β sent, untouched, fully β
β + recent messages β β scrollable β
ββββββββββββββββββββββββββ ββββββββββββββββββββββββββ
~33k tokens ~645k tokens
/compress or /compact β type either in chat to force compaction now. You get a token before/after report instead of a model reply./usage β instant report of real context usage: prompt size vs context window, auto-compact headroom, transcript size, and compression state. The model also gets a get_context_usage tool, so just asking it "how much context do I have left?" works too.agentic-workspace/v1 tool results before generic truncation. It keeps transaction/run/job/To-Do/research/query/source IDs, next actions, command exit evidence, hashes, URLs, report/state paths, and artifact references while dropping declared bulky diffs, page bodies, listings, and command streams. Approvals staged by the workspace's permission gate survive too β the approval_*/plan_* id, its kind, and the exact call to re-issue after you type /accept.npm run bench) measures seeded-fact recall after compaction and after consolidation, prompt reduction, latency, structural integrity, and cache determinism; results are committed under bench/results/.Compacting ββββββββββββ 34% β chunk 2/5), and while compression is active each turn shows the real prompt size (Prompt: ~33,214 tokens ββββββββ 27% of 122,112). Configurable: status line, sender name, or off.~/.lm-context-compressor/cache.json, atomic writes) and survive restarts. Edit or regenerate any old message and the cache cleanly recomputes. Abort mid-compaction and finished chunks are kept. Failures are visible, never silent, and never corrupt state./compress anytime.git clone <this repo> cd lm-context-compressor npm install lms dev --install -y # installs into LM Studio (or run update.bat on Windows)
For live-reload development use lms dev instead.
| Setting | Default | Meaning |
|---|---|---|
| Auto-compact | on | Turn off for bulk-data tasks where the past IS the data |
| Compaction threshold | 75% | Of the model's context window |
| Compact down to | 55% | Hysteresis floor: once triggered, compact well below the trigger so long agentic turns have headroom |
| Reserved output tokens | 2000 | The prompt must fit within context minus this reply reserve |
| Absolute token trigger | 0 (off) | Absolute-token alternative to the %, handy for testing |
| Recent context kept verbatim | 6000 tokens | The newest conversation is never summarized |
| Summarize in chunks of | 16000 tokens | Chunks are cached and reused across compactions |
| Max chunks per pass | 0 (auto) | Cap the work per run; progress carries over |
| Tool rounds per pass | 6 | Agentic turns run in passes so compaction can happen mid-task; 0 = one uncapped loop |
| Max tool result size | 4000 tokens | 0 = unlimited |
| Max tokens per chunk summary | 1500 | |
| Summarizer prompt | Auto (recommended) | Auto/Full (10-section)/Compact β auto always uses the full prompt (bench-confirmed best recall); Compact can be forced here and is also used automatically as a rescue when a model's reasoning runs away |
| Summary budget | 12000 tokens | Above this, oldest summaries consolidate into one (0 = unbounded) |
| Attachment memory | on | Preserve document/image content before compressing past it |
| Announce compaction in chat | on | Token before/after note |
| Prompt meter | Status line | Where the real prompt size is shown |
With the Agentic Workspace plugin (rootmonster/agentic-workspace) 0.2.0+, context-compressor does more than pass tools through. It recognizes the plugin's durable result protocol and compacts it structurally:
large tool result βββ preserve: summary, retention.facts, IDs, status, next action βββ preserve: source URL/hash/path and transaction/job/run artifacts βββ preserve: staged approval β id, kind, and the exact resume call βββ omit: declared diff preview, page text, search result bulk, stdout/stderr βββ recover later from .agentic state using the preserved IDs
From Agentic Workspace 0.3.0 every mutation goes through a permission gate, and a blocked call comes back as a staged approval instead of a result. Those envelopes survive compaction whole: the approval_*/plan_* id, status, title, and the resume call kept byte for byte, so /accept still resumes the right thing after the chat compacted. The recovery index of workspace_inspect { action: "changes" } β its approvals, plans, and background-command jobs entries β is preserved for the same reason.
The summary schema has dedicated Durable workflow state, Verification & evidence, and Source ledger sections. Search snippets remain discovery hints; fetched source_* records and their stored paths remain evidence. The summarizer prompts and the protocol rendering are part of the cache namespace, so old summaries are not silently reused under new preservation rules.
See AGENTIC_WORKSPACE_INTEGRATION.md for the protocol and end-to-end test sequence.
Release validation β the full native test runs and a live benchmark matrix across eight model families β is documented in RELEASE_VALIDATION.md.
The context ring at the bottom still shows a huge percentage β is it working? Yes. LM Studio's built-in ring counts the visible transcript, which this plugin deliberately never shrinks (your scrollback is sacred). The prompt the model actually receives is what gets compressed β read the plugin's own meter line for the true number. A feature request is open with LM Studio to let plugins update the built-in ring.
Does the model really remember things from before compaction? It continues from a structured summary that preserves goals, decisions, code, findings, and next steps verbatim where it matters. It is compression β fine detail in the middle of old conversation fades first. Anything in the recent-tokens window is untouched.
When should I NOT use it?
When the old messages are the data: log analysis, hex dumps, bulk document review. Summarizing destroys exactly what you need. Flip Auto-compact off for those chats (/compress stays available if you change your mind).
What models does it work with? Any normal chat model β token math uses each model's own tokenizer and reported context length; prompt formatting goes through LM Studio's template machinery. Tool passthrough needs a tool-capable model. Selecting a generator plugin as the model isn't supported (nothing to count tokens with) β the plugin says so and passes through.
A first compaction on a giant chat takes a while. Each chunk is one summarization call on your local model. The progress bar shows real progress, aborting keeps completed chunks, and "Max chunks per pass" lets you spread the work over multiple runs. Once cached, chunks are never re-summarized.
Tested live against eight model families for the 0.7.0 release (Qwen3 and Qwen3.5/3.8, DeepSeek-R1 distill, Gemma 3, Llama 3.2 at 3B and 18B, gpt-oss, GLM) β results committed under bench/results/. 0.8.0 changes only how the Agentic Workspace protocol is compacted, so that matrix was not re-run for it.
The other context tools on the LM Studio Hub, honestly compared:
| context-compressor | context-compactor | kosmix/compact | |
|---|---|---|---|
| Auto-compaction on threshold | β with hysteresis floor | β | β manual |
| Bounded summary growth (hierarchical consolidation) | β | β grows forever | β |
| Attachment content preserved through compression | β | β | β |
| Reproducible benchmark suite in-repo | β | β | β |
| Mid-task compaction (marathon tool loops) | β | β | β |
/compress Β· /compact Β· /usage commands | β | β | partial |
| Exact templated-prompt token accounting | β | β estimates | β |
| Survives edited/regenerated messages | β content-addressed cache | β documented limitation | β |
| Resumable, abortable compaction | β chunk-granular, persisted | partial | β |
| Tool passthrough + result capping | β + callId-correlated results | β | β |
| Ask the model "how much context is left?" | β
get_context_usage tool | β | β |
| Summary injection hardening (provenance, no authority escalation) | β | β | β |
| Test cases in source | 289, written test-first | some | β |
(persistent-memory solves a different problem β cross-chat fact storage β and composes fine with this plugin.)
| You see | It means |
|---|---|
Compacting β¦ chunk n/m (k cached chunks reused) | Normal β previously summarized chunks are being reused; stopping is safe, finished chunks are saved |
Mid-task compaction β¦ β continuing | A long agentic turn grew the context; it was compacted between tool passes and the task continues |
Prompt β¦ exceeds the safe budget | Even after safety compaction the prompt is too big β raise the context length, lower "Reserved output tokens", or reduce "Recent context kept verbatim" |
Preserving attachment "x" (1/2)β¦ | A document/image is being extracted into attachment memory before its region compresses |
Consolidating N summaries into oneβ¦ | Accumulated summaries outgrew their budget and are being folded into one denser summary β normal on very long chats |
Compacted into the verbatim tail to fit | The prompt plus tool definitions would not fit even after normal compaction, so recent rounds (never your current message) were summarized too |
Consolidation disabled for this model this session | This model spends any budget reasoning on the merge without ever answering (measured on qwen3.8-27b) β the doomed retries are stopped; summaries stay unmerged and everything else keeps working |
Transient engine error β retrying onceβ¦ | The engine dropped the connection mid-reply; the pass is retried (only when nothing side-effectful ran) |
Compaction floor raised to ~N tokens β¦ (β, once) | Information, not a fault: your "Compact down to" % is smaller than the system prompt + summary budget + kept-verbatim need (a tools provider's schemas alone can exceed 30% of a 16k window), so compaction targets the raised floor. /usage shows both numbers. |
Compaction cannot get below its trigger β¦ (β) | The raised floor is at or above the trigger, so compaction would run every turn: raise the model's context length, or lower "Recent context kept verbatim" or "Summary budget" |
context-compressor needs a real model as the token source | A generator plugin is selected as the model; pick a real model |
| Meter says one thing, LM Studio's ring another | The ring counts the visible transcript (which never shrinks); the meter counts what the model actually receives β see FAQ |
The plugin registers an LM Studio prediction loop handler: each turn it receives the full chat, maps it to a compressed view, and runs your selected model over that view.
/compress does the lot.[system prompt + summary (merged into one system message) + recent tail] streams through your model with tools passed through and results rendered back into the chat.npm run bench:static # structural/determinism checks, no model needed npm run bench # full run against your local LM Studio model
Measures seeded-fact recall from the compacted view (and again after a forced
consolidation, to quantify drift), prompt reduction, per-chunk latency,
structural integrity, and cache determinism across four synthetic fixtures
(coding agent, research, contradictory updates, tool spam). Results are
stamped with the model id and committed under bench/results/ β
see bench/README.md for metric definitions and caveats.
npm install npm test # 308 unit tests (vitest), written test-first npm run typecheck lms dev # hot-reload dev server
Pure logic (hashing, cut rules, chunk planning, truncation, caching) is fully unit-tested; the LM Studio integration layer is deliberately thin.
Free for personal and internal professional use β use it, modify it, self-host it at home or at work at no cost.
Commercial embedding requires a license: incorporating this software (or a derivative) into a product or service that people pay for requires a separate commercial agreement with the author β contact via GitHub or the LM Studio Hub profile. See LICENSE for the full terms. (Hub revisions 1β15 were published under MIT; that grant remains valid for those copies.)
what the model receives what you see on screen
ββββββββββββββββββββββββββ ββββββββββββββββββββββββββ
β system prompt β β every message you ever β
β + task-aware summary β βββ β sent, untouched, fully β
β + recent messages β β scrollable β
ββββββββββββββββββββββββββ ββββββββββββββββββββββββββ
~33k tokens ~645k tokens