anomalyco / anomalyco/opencode
[FEATURE]: reduce per-turn token accumulation for OpenAI models on Bedrock Mantle
@nexxeln is already working on this.
Since Jul 23, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Long agentic sessions using OpenAI models on Bedrock Mantle (amazon-bedrock/openai.gpt-5.6) accumulate per-turn token costs. In a 34-turn session, input tokens grew from 4K to 95K.
Two causes:
-
Encrypted reasoning blocks are replayed on every turn. With
store: false(hardcoded for Mantle atpackages/opencode/src/provider/transform.ts:1099), every assistant reasoning block is serialized with itsencrypted_contentand replayed on every subsequent turn (packages/llm/src/protocols/openai-responses.ts,lowerMessages). Turn 34 replays encrypted reasoning from all 33 prior turns. -
Tool outputs are not truncated during normal turns. The
truncateToolOutputhelper inpackages/opencode/src/session/message-v2.tsis only called during compaction, not during normal turn message building. Large tool results accumulate turn by turn.
Requested changes:
A. Keep encrypted reasoning only from the last N assistant messages** in --> See my comment below.lowerMessages when store: false. Replace older blocks with item_reference placeholders. (File: openai-responses.ts)
B. Pass toolOutputMaxChars to toModelMessagesEffect during normal turns, not just compaction. Thread a config option through the message building pipeline. (File: message-v2.ts and call sites)
Note: previous_response_id chaining was tested on Bedrock Mantle and does not save tokens (the server still processes and bills the full context). Issue #34133. Per-turn budget can already be controlled by lowering limit.input in opencode.json (overflow.ts:usable() minus compaction buffer), which is separate from A and B.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.