r/opencode • u/FantasticYoung3109 • 17h ago
Straitjacket : keep large command results outside the conversation and retrieve exact lines in OpenCode
There are three separate context-management decisions:
- How much new tool output enters history.
- How much recent history compaction preserves.
- 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.


