CompactBench
Your agent compacts its context before it runs out of room. Does it keep what matters? CompactBench is the benchmark that finds out.
Long-running LLM agents compact their history — summarize it, extract state, keep a ledger — and then carry on with only the compacted version. CompactBench gives your compactor a long, adversarial conversation, compacts it again and again as the conversation continues, and after every compaction asks a fixed reader model structured questions about what survived.
What makes it different:
- It measures the compaction layer, not the model. The reader only ever sees your artifact.
- Real multi-cycle drift. After the first compaction your method gets only its previous artifact plus the new turns — never the old turns again — while rules change, decisions get overridden, and ownership moves.
- Adversarial by construction. Wrong answers are built from the conversation itself: the superseded decision, the rule for another project, the look-alike colleague, the runner-up vendor.
- No LLM judge. Every answer is an option letter or an exact value, scored mechanically, with confidence intervals.
- Controls.
--controlsscores the same questions from the full conversation (ceiling) and from nothing (floor); every season publishes both, so a score is always readable. - Any model. Your method can call any hosted model or your own OpenAI-compatible endpoint; one fixed reader grades everyone the same way.
- Hidden ranked set. Public Starter and Practice suites for development; ranked scores come from a hidden Elite set generated fresh for each run.
30-second try
In your browser: open notebooks/try_compactbench.ipynb in Colab (direct link) — no local install, runs on Groq's free tier.
Locally:
pip install 'compactbench[providers]'
export COMPACTBENCH_ANTHROPIC_API_KEY=...
compactbench run --method built-in:hybrid-ledger --suite starter \
--provider anthropic --model claude-haiku-5-5 --controls
compactbench score --results results.jsonl
Built-in methods: naive-summary, sectioned-summary, structured-state, hierarchical-summary, hybrid-ledger, extractive (no model calls), Anthropic's server-side compaction (anthropic-compaction), the default compaction of Codex CLI (codex-cli) and LangChain's summarization middleware (langchain-summarization) reproduced from their open-source code, plus the controls oracle, null and truncate-last-n. Providers: Anthropic, OpenAI (and any OpenAI-compatible server), Groq, Google AI Studio, Ollama.
Suites
| Suite | What it is | Opening conversation | Drift cycles |
|---|---|---|---|
starter |
Smoke test — check your method runs end to end | ~1.5k tokens | 2 |
practice |
Public twin of the ranked Elite set: mixed sessions, same difficulty | ~32k tokens | 4 |
drills |
One family per case at Elite difficulty, to work on one failure mode | ~32k tokens | 4 |
| Elite (hidden) | The ranked set: mixed sessions in private worlds, a fresh sample per run | ~32k tokens | 4 |
The public suites are also on Hugging Face as compactbench/compactbench (load_dataset("compactbench/compactbench", "practice")), built by scripts/hf_dataset.py.
A mixed session puts every family into one conversation under one token budget. Eight families, each a different way compaction fails: buried_constraint, decision_override, entity_confusion, reference_resolution, numeric_precision, conditional_scope, task_continuity and provenance_authority. List them with compactbench families list, or read one with compactbench generate --family decision_override --seed 7 --text.
Writing your own compactor
from typing import ClassVar
from compactbench.compactors import Compactor
from compactbench.contracts import CompactionArtifact, CompactionRequest
from compactbench.providers import CompletionRequest
from compactbench.rendering import render_request
class MyCompactor(Compactor):
name: ClassVar[str] = "my-method"
version: ClassVar[str] = "0.1.0"
async def compact(self, request: CompactionRequest) -> CompactionArtifact:
# cycle 0: request.turns is the whole conversation.
# later: request.previous_artifact + only the new turns.
response = await self.provider.complete(
CompletionRequest(
model=self.model,
prompt="Update the summary:\n\n" + render_request(request),
max_tokens=8_000, # room for thinking on reasoning models
reasoning_effort="low",
)
)
return CompactionArtifact(summaryText=response.text.strip())
compactbench run --method path/to/my_compactor.py:MyCompactor --suite practice \
--provider anthropic --model claude-haiku-5-5 --controls --traces traces.jsonl
compactbench qualify --results results.jsonl
Already running LangChain or LlamaIndex? Wrap it with compactbench.integrations (pip install 'compactbench[langchain]' or [llamaindex]). See writing a compactor and integrations.
Forget less
Season 1 shows what makes a compaction summary hold up: fixed sections, replacing changed facts instead of keeping both, and tracking tasks with their status. Forget less turns that into instructions you can paste into Claude Code, Codex, LangChain or LlamaIndex, and shows how to measure them on your own setup.
Claude Code plugin
The compactbench plugin brings this into Claude Code: a forget-less skill that writes evidence-based compact instructions for your CLAUDE.md (or your agent's summarization prompt), and a measure-compaction skill that benchmarks a compaction method on your own keys and can set up the CI check below.
/plugin install compactbench --marketplace compactbench/compactbench
(Or /plugin marketplace add compactbench/compactbench, then /plugin install compactbench@compactbench.)
Check your method in CI
compactbench check runs a small, fixed Practice sample of your method with your keys and fails when the score drops below a saved baseline. The GitHub Action wraps it and posts the report on the pull request:
- uses: compactbench/compactbench@main # pin a release tag or commit SHA
with:
method: my_compactor.py:MyCompactor
baseline: .compactbench/baseline.json
comment: true
env:
COMPACTBENCH_ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
See checking in CI.
Leaderboard
Season 1's reference baselines are on the leaderboard (data: docs/data/leaderboard.json).
Ranked submissions are open at compactbench.com/submit: sign in with GitHub, upload your method (or pick a reference method and benchmark your model), and bring your own API keys; it runs sandboxed on a fresh sample of the hidden Elite set and publishes itself when it qualifies. Develop against the public practice suite — it's the same difficulty — and check your run with compactbench qualify first. See submitting.
Project status
0.3 is benchmark v2 — a rewrite of case generation, scoring and the compaction loop. It replaces 0.2's templates and scorer, and scores are not comparable across the two. See CHANGELOG.md and the methodology.
Contributing
Bug reports, new scenario families, and new compactors are welcome. See CONTRIBUTING.md and our Code of Conduct.
License
Apache License 2.0 — see LICENSE.
Metadata
Release files for compactbench 0.3.0
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 | Actions |
|---|---|---|---|---|
| compactbench-0.3.0.tar.gz | 170.3 kB | With provenance | Details for compactbench-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| compactbench-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for compactbench-0.3.0-py3-none-any.whl |
Total release size: 380.6 kB
Release files / compactbench-0.3.0.tar.gz
| Download URL | compactbench-0.3.0.tar.gz |
|---|---|
| Size | 170.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49dbec6c9b791f1b6dd206051cd1e9fd7f6234943d27fe282c07aee754444fe0
|
|
BLAKE2b-256 checksum How to use checksums |
cc3df7a18ad3661bf4a4ce9beaccb487e7ef9391c99a271b50c93ba0a9d34be8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 16, 2026.
Transparency logRelease files / compactbench-0.3.0-py3-none-any.whl
| Download URL | compactbench-0.3.0-py3-none-any.whl |
|---|---|
| Size | 210.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
450ac020fe5c0cddd6d57c9301bd5add20ccfde160151ce57988af5216b94d7e
|
|
BLAKE2b-256 checksum How to use checksums |
9f55cf986c4ab228a24ac3a23be510d317fa035b3fa1cc4b9c3ec98aa99446eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 16, 2026.
Transparency logSecurity for compactbench 0.3.0
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
Both files in this release have been uploaded with provenance metadata.
Attestation for compactbench-0.3.0.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 Nov 16, 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.