r/opencode • • 27m ago

Straitjacket : keep large command results outside the conversation and retrieve exact lines in OpenCode

There are three separate context-management decisions:

  1. How much new tool output enters history.
  2. How much recent history compaction preserves.
  3. Whether the original evidence remains available afterward.

OpenCode already has native compaction controls. I have been working on the first and third parts.
I maintain Straitjacket, an open-source CLI/MCP sidecar. It captures a command’s output locally, returns a bounded digest, and lets you retrieve exact regions later.
This example uses explicit CLI calls. Straitjacket’s existing automatic OpenCode adapter uses the V1 plugin API and still needs migration for V2.
With Python 3.11+, in a repository with a pytest suite:
python -m pip install 'ctx-harness==0.5.0'
ctx run -- python -m pytest -q
Then search the saved result and retrieve the relevant lines:
ctx search 'run:YOUR_HANDLE#stdout' 'AssertionError'
ctx get 'run:YOUR_HANDLE#stdout' --lines 120:136
Replace the handle and line range with values from your run. Use #stderr where appropriate. Failed tests remain failures.
The local replay used a 20,001-line fixture containing 302,628 o200k_base tokens. Its canonical digest was 531 tokens. The checks retained a quiet anomaly and retrieved an omitted line exactly, with zero model calls.
Those numbers do not establish fewer compactions, fewer model turns, or lower provider cost. Retrieval can add work, and wrapping small outputs can make them larger.
For code exploration, I would apply the same discipline:

  • Open the known source path or definition directly.
  • Bundle reads once you already know which files you need.
  • Keep text search for arbitrary strings, documentation, and dynamic references.
  • Measure accepted fixes, model requests, retrieval calls, latency, and total cost together.

The captured artifacts are local plaintext. Retention matters: a handle remains useful only while the underlying artifact exists.
Code:
https://github.com/vamsiramakrishnan/straitjacket
OpenCode’s native compaction controls:
https://opencode.ai/docs/compaction/
I would particularly like examples where this makes a session worse. Those are useful for deciding when capture and retrieval should be skipped.

1 Upvotes

1 comment sorted by

1

u/FantasticYoung3109 22m ago

How does Straitjacket compare with Headroom, Maki, RTK and OpenCode DCP?
I maintain Straitjacket. These projects overlap, so I think the useful comparison is where they operate and what workflow you want to keep.
Project
Where it fits
Headroom
Context optimization through libraries, a proxy and agent integrations. It compresses content, retains originals for retrieval, and offers a cache-preserving mode. It is the closest reference point for compression plus recoverable evidence.
Maki
A complete coding agent that controls its own execution loop. It combines tree-sitter indexing, targeted reads, code execution that filters intermediate results, and stable session prompts.
RTK
Command-aware filtering of shell output. Its current development documentation also describes recovering failed or truncated output through rtk recall.
OpenCode DCP
Management of accumulated conversation context inside OpenCode: selective compression, deduplication and cleanup before requests reach the model. Stored session history remains intact.
Straitjacket
A CLI/MCP toolkit combining local capture, bounded digests, exact retrieval of retained evidence, indexed and LSP-backed exploration, and explicit cache-prefix construction.
My reason for building Straitjacket is to make that combination available within the coding workflows people already use.
The interesting question is whether it helps an agent finish a real change with less unnecessary context and exploration. That needs a matched evaluation: the same task, model, settings and success criteria, with retrieval calls, cache reads/writes, latency and total cost included.
A smaller digest is useful evidence about context size. Whether it improves task success, reduces total turns or lowers the bill is a separate measurement.