straitjacket
A context sidecar for coding agents.
Cut wasteful token spend, reduce turns with LSP, and delay context compaction — without lossy compression.
Straitjacket runs alongside Claude Code, Codex, Antigravity, Hermes, Oh My Pi, OpenCode, and DeepSeek Harness. Your harness keeps running the model, handling auth, and controlling permissions. Straitjacket stores noisy command output locally once, hands the model a compact digest with exact retrieval handles, resolves code structure through reused language servers, and keeps the active transcript lean so sessions stay sharp longer.
Python 3.11+ · ctx-harness v0.45.0 · Apache-2.0 · Documentation
Why without lossy compression matters: on a 20,001-line log replay, head-and-tail truncation cuts the output to 1,219 tokens and silently drops a quiet fallback event at line 14,238. Straitjacket reduces 302,628 tokens to a 531-token canonical digest, keeps line 14,238 intact, stores all captured bytes verbatim on disk, and retrieves any omitted line on demand. This local fixture measures tool-output delivery. End-to-end task success and cost need separate measurements.
Try it on a failing test
In a repository with a pytest suite, run:
uv tool install 'ctx-harness[full]' # or: python -m pip install 'ctx-harness[full]'
ctx setup --global && ctx tools install --auto
ctx run -- pytest -q
For a long failure, ctx stores the full output on disk and returns the failing
test names, a short digest, and a handle. For a failing test command, the digest
records the child exit code and ctx run returns 3. Search the stored stream
and pull only the traceback lines you need:
ctx search run:ba3d1020ee8f#stdout 'AssertionError'
ctx get run:ba3d1020ee8f#stdout --lines 140:180
Replace the sample handle with the one from your run. The default capture limit
is 64 MiB per stream; if output crosses it, the digest explicitly identifies the
discarded middle. To connect your coding harness, run ctx setup and then
ctx doctor. Installation and host setup.
What the sidecar does
| Goal | How Straitjacket helps | Start here |
|---|---|---|
| Cut wasteful token spend | Capture huge logs and test runs once on disk, keep prompt prefixes stable, and trim unused skill/MCP schemas from every turn | How it works · Capability surface |
| Reduce turns with LSP | Query reused language servers for hover, references, fresh diagnostics, and sealed cross-file renames instead of grep-read-edit loops | Language servers (LSP) · Code search |
| Delay context compaction | Keep raw floods out of the transcript, defer dead per-turn schemas, and optionally offload aging tool results into frozen lossless epochs | Lossless rescue · Prompt prefixes |
| Keep every byte recoverable | Never truncate silently or summarize away details; every omitted region keeps an exact handle (and anchored repo: spans follow edits) |
Why straitjacket · Anchored addresses |
| Delegate across harnesses | Route steps across Claude Code, Codex, Antigravity, OpenCode, Hermes, OMP, and DSH over ACP using handles instead of full transcripts | ACP setup · Worker routing |
| Select a Gemini 4 model | Discover and select Hydrogen, Neon, Carbon, or Argon in native Antigravity sessions | Antigravity sessions |
Cut wasteful token spend — without lossy compression
A bulky test log or build output that lands early in a session is not billed once: it
stays in the conversation and gets re-read on every turn that follows. Lossy
compression (head-and-tail truncation, loud-line ERROR filters, or LLM
summarization) trims the byte count by permanently throwing away lines — often
silently dropping the quiet detail you need next.
Straitjacket separates what stays on disk from what enters the prompt:
- Zero silent loss:
ctx runand host hooks persist raw stdout/stderr locally and emit a deterministic, format-aware digest (pytest, logs, JSON, linters, diffs, markdown, structured outlines) with exact handles for omitted regions. Pull any omitted line verbatim withctx searchandctx get. - Trim dead per-turn schema weight: unused MCP servers and skill
descriptions pad every single request. Run
ctx surface inventoryorctx pruneto audit per-turn token overhead, or launch Claude Code withctx wrap claude --surface autoto shorten descriptions for skills your project's history never used. Skill and tool pruning. - Keep prompt prefixes cache-friendly: deterministic local digests keep
earlier transcript bytes stable across turns. For custom model clients,
--cache-prefixplaces fixed reference material ahead of changing questions and selected excerpts:
ctx compress build.log --query 'Which target failed?' --cache-prefix reference.txt
Send cache_wrap.prefix first and cache_wrap.suffix second; identical
reference material yields byte-identical prefixes across questions. Measure real
usage with ctx stats --session and compare runs on task completion, cache
reads/writes, uncached input, output, and total cost. Prompt layout · Session measurement.
Reduce turns intelligently with LSP
Agents waste turns when they navigate code by trial-and-error: recursive grep, reading whole files to find one definition, guessing call sites, and applying manual multi-file edits that leave stale imports or broken references behind.
Straitjacket connects directly to your installed language servers — no extra model or GPU calls — and reuses one server per workspace over a private local Unix socket:
ctx lsp hover src/example.py:4:7
ctx lsp refs repo:src/example.py:Example.method
ctx lsp diagnostics src/example.py:1:1
For multi-file refactors, plan a semantic rename or code action through LSP and
apply it as a hash-sealed ctx edit transaction instead of burning turns
hunting down every call site by hand:
ctx lsp rename src/example.py:4:7 --new-name better_name --out rename-plan.json
ctx edit preview rename-plan.json
ctx edit apply rename-plan.json
- Broad language registry: built-in server definitions for Python,
TypeScript/JavaScript, Go, Rust, C/C++, C#, Java, Kotlin, Lua, PHP, Ruby,
Scala, shell, and Swift (with CI/local replay verified on Pyright,
typescript-language-server,gopls, andrust-analyzer, and custom servers supported viaCTX_LSP_SERVERS). - Fresh post-edit diagnostics: after a
ctx editwrite, available LSP diagnostics run alongside built-in syntax checks and disclose freshness explicitly rather than treating stale or missing reports as clean. - Layered symbol navigation:
ctx refsautomatically tries SCIP, then LSP, then Jedi/textual fallback and labels which engine answered. Pair LSP with fast local lookups when you want a starting point or a bounded slice:
ctx pack "Where does parse_ref validate a run handle?" --files 3
ctx search repo: sym:parse_ref
ctx def repo:src/ctx/refs.py:parse_ref
ctx refs parse_ref --path src/ctx
When files shift mid-session, content-anchored addresses
(--lines 40:52@07407f1c) relocate moved code automatically and refuse if the
underlying lines changed — avoiding wasted turns debugging stale line numbers.
Language servers (LSP) · Code search · Investigation workflows.
Delay context compaction events
Host compaction happens when noisy tool outputs, whole-file reads, and bloated tool schemas fill the context window — forcing the host to summarize older turns and often busting prompt caches. Straitjacket pushes compaction much further out through active, lossless context management:
- Keep floods out from turn one: large command results stay in the local
store behind a compact digest, and follow-up
ctx getreads remain bounded. You carry a few hundred tokens across later turns instead of hundreds of thousands. - Cut fixed per-turn overhead:
ctx pruneandctx wrap claude --surface autokeep unused skills and MCP schemas out of every turn's context budget without deleting anything. - Offload aging tool results without losing them: mark task boundaries with
ctx checkpointor enable opt-in epoch-latched rescue (--rescue-pcton the Claude proxy). When window fullness crosses the threshold, older oversized tool results are persisted to disk and replaced in one frozen, cache-friendly epoch — freeing runway before host compaction triggers, while keeping every original byte recoverable by handle even after compaction runs.
Lossless mid-session rescue · How context stays lean.
Delegate across harnesses (optional)
When you want different coding agents for exploration, implementation, and
verification, ctx orchestrate routes each step over Agent Client Protocol
(ACP) and hands workers compact handles and checkpoints instead of forwarding
entire conversation transcripts. The task ledger tracks attempts and resumes
interrupted runs; the relay passes live handle updates between peers.
ACP setup for all seven harnesses · Worker routing · Task ledger · Relay.
ctx setup --host opencode --acp --acp-model 'provider/model-id'
ctx orchestrate 'Review the current diff' --dry-run
Replace provider/model-id with an ID advertised by that endpoint. Use the
checkout installation for model-free previews of general tasks
and the latest Gemini 4 routing entries. For native Antigravity sessions
(Hydrogen, Neon, Carbon, or Argon), run agy models and pass a listed slug such
as gemini-4-hydrogen-high to --model in ctx collab.
Antigravity guide.
What the measurements show
Straitjacket publishes both delivery measurements and end-to-end agent runs — including small-output cases where adding a wrapper cost more than running natively.
| Workload | Observed result |
|---|---|
| 20,001-line log fixture, replayed November 23 | The raw log took 302,628 o200k_base tokens. The canonical digest took 531; actual counts were 531–537 as opaque run handles changed. It retained the quiet event at line 14,238, preserved the captured bytes exactly, and retrieved an omitted control line. No model ran. |
| 9-file cross-file Python refactor, LSP vs. explicit edits | Controlled model-free replay (3 repeats): LSP semantic rename cut scripted tool calls from 14 to 7, saved 18.7% tool-result tokens (4,295 → 3,491) and 589 argument tokens vs. discovery/read/explicit edits, and left 3 unrelated same-name files untouched. Live agent turns and billing require separate measurement. |
| Source ranges after edits | Across 1,920 lookups, anchored ranges relocated 1,452 times, verified in place twice, refused 466 times, and returned the wrong content zero times. |
| Finding files on 14 DeepSWE tasks | Among the top eight suggestions, ctx pack found 54.0% of existing files touched by the reference fix on average. Ranking by grep count found 42.9%. Grep found at least one relevant file on all 14 tasks, the pack on 12. |
| Three live canary tasks, one run per arm | Both arms solved 3/3. With the wrapper, median cache hit rate rose from 96.5% to 97.5% and total cost rose from $0.67 to $0.92. Small, already-bounded outputs are often cheaper natively. |
| DeepSWE, eight Python tasks, Haiku, 60-turn cap | The wrapped arm passed 177 held-out fail-to-pass test IDs on committed patches versus 54 for plain Claude. The runs cost $5.74 and $5.42 respectively. Neither arm fully resolved a task. |
Integration and storage
The CLI works in any terminal. Claude Code and Codex can replace oversized results after a command runs. Antigravity CLI can rewrite supported calls before execution. Hermes, Oh My Pi, and OpenCode can rewrite arguments and replace text results. DeepSeek Harness can gate calls and replace text results. The host matrix lists version-specific behavior and distinguishes live observations from adapter tests.
Captured artifacts live in a local plaintext store. Model-visible reads follow
the configured redaction policy. Unpinned artifacts become eligible for
collection after 30 days by default and remain until ctx gc runs. Commands
run with the invoking user's permissions. Configuration.
Verified edits · Tool SDK · CLI reference · All guides · Changelog
Development
git clone https://github.com/vamsiramakrishnan/straitjacket.git
cd straitjacket
python -m pip install -e '.[dev]'
pytest
New mechanisms need deterministic output, explicit degradation, and a named evaluation gate. Follow CONTRIBUTING.md.
Useful first contributions: add a digest profile for a command you use, reproduce an output that loses important detail, or add a small-output case where the wrapper costs more than it saves. Include the command, expected detail, and reproduction steps in an issue. The evaluation guide shows how to check delivery without a model.
Related projects
- branchyard. Run coding agents on isolated branches and review their changes.
Metadata
Release files for ctx-harness 0.45.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 |
|---|---|---|---|---|
| ctx_harness-0.45.0.tar.gz | 1.4 MB | With provenance | Details for ctx_harness-0.45.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ctx_harness-0.45.0-py3-none-any.whl | Python 3 | none | any | Details for ctx_harness-0.45.0-py3-none-any.whl |
Total release size: 3.0 MB
Release files / ctx_harness-0.45.0.tar.gz
| Download URL | ctx_harness-0.45.0.tar.gz |
|---|---|
| Size | 1.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3655f5a5cfbb6348a73d3a587dc30d5be080e46f715f6815fbb782f32491b95e
|
|
BLAKE2b-256 checksum How to use checksums |
d3314147d1366a16f62d83d9cc1d730bd29cd26af271dce51a96b6baf977d3ce
|
| 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 Nov 30, 2026.
Transparency logRelease files / ctx_harness-0.45.0-py3-none-any.whl
| Download URL | ctx_harness-0.45.0-py3-none-any.whl |
|---|---|
| Size | 1.5 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8a52d69ba32818ca46e06b6fe6a3518bf584e685a4b3683e8c753db90d66d3db
|
|
BLAKE2b-256 checksum How to use checksums |
80d68b39a265b3c617be16e0abedfcc3ce1bb7393fffce82396bde6c56443af0
|
| 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 Nov 30, 2026.
Transparency logSecurity for ctx-harness 0.45.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 ctx_harness-0.45.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 30, 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.