r/ContextEngineering • u/FantasticYoung3109 • 2d ago
Keeping coding agents’ context useful: bounded tool output, exact retrieval and LSP navigation
/r/google_antigravity/comments/1y7c49t/keeping_coding_agents_context_useful_bounded_tool/A test command can produce thousands of lines when the useful evidence is a failed assertion, a stack trace, and a few lines around it.
I maintain Straitjacket, an open-source CLI/MCP sidecar for coding agents. Its Antigravity integration targets the agy CLI.
The workflow is straightforward: capture command output locally, return a bounded digest, then retrieve exact lines when the agent needs them.
With Python 3.11+, run this in a repository that has a pytest suite:
python -m pip install 'ctx-harness==0.5.0'
ctx run -- python -m pytest -q
The result includes a retrieval handle. Use the actual handle from your run:
ctx search 'run:YOUR_HANDLE#stdout' 'AssertionError'
ctx get 'run:YOUR_HANDLE#stdout' --lines 120:136
Choose the line range returned by search, and use #stderr where appropriate.
In our local replay, a 20,001-line fixture contained 302,628 o200k_base tokens. The canonical digest was 531 tokens. The test verified the stored bytes, retained a quiet anomaly, and retrieved an omitted line exactly. It made zero model calls.
That measures representation size and evidence retrieval. It does not establish how many extra successful turns you get before compaction, or whether your provider bill falls.
A few practical lessons:
- Bound large results before they enter history. This does not shrink messages already in the conversation.
- Keep retrieval addresses and relevant source references in task handoffs.
- Use symbol lookup for symbols and text search for arbitrary strings. Replacing every grep with a reference query can lose useful matches.
- Keep selected tools and instructions stable during a session, then measure actual cache reads and writes.
The repository also includes capability inventory and pruning: choosing which optional tools and skills to expose before launching a supported host. That is separate from summarizing old conversation messages.
Captures are local plaintext, with a default 64 MiB cap per stream. The digest declares discarded regions. Small outputs can acquire wrapper overhead, so wrapping everything is not automatically useful.
Code and reproduction instructions:
https://github.com/vamsiramakrishnan/straitjacket
If you have a sanitized build/test log where the digest misses the important clue or retrieval causes extra loops, I would like to reproduce that case.
1
u/FantasticYoung3109 2d 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.