You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE]:Context-Aware Proxy Middleware: intercept requests before LLM to reduce token costs 96–99% via MemPalace + SocratiCode #26685
The problem:
Yesterday I spent ~$100 in two OpenCode sessions with Claude Opus via OpenRouter.
Looking at the usage logs, every single request was sending 660,000–689,000 input
tokens — the entire chat history and codebase context re-sent from scratch each time.
My actual new message was maybe 100 tokens. The rest was stale history.
What I want:
A way to intercept the messages array before it gets sent to the LLM provider,
so I can strip old history and inject only relevant context retrieved from
tools like MemPalace or SocratiCode instead.
The cleanest solution would be a plugin hook that fires before the provider
call — something like provider.request.before — where the plugin receives
the full messages array and returns a modified (pruned) version.
As a workaround I could run a local OpenAI-compatible proxy that sits between
OpenCode and the real API (by swapping baseURL in opencode.json), but a native
plugin hook would be much cleaner.
Why this matters:
With MemPalace and SocratiCode already installed, the relevant context for any
given question is usually under 10,000 tokens. There's no reason to send 600,000+
tokens every time. Right now there's no way to intercept and replace that context
before it hits the API.
Is a pre-request hook feasible in the current plugin architecture?
The description appears to be AI-generated. It uses an RFC-style document format with emoji headers, elaborate tables, architecture diagrams, code samples in multiple languages, marketing-style savings claims, and a call-for-collaborators section. AI-generated walls of text are not acceptable — please rewrite this in your own words, concisely describing the problem you are experiencing and what you'd like to see changed.
Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
Activity
github-actions commentedon May 10, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
If you believe this was flagged incorrectly, please let a maintainer know.
github-actions commentedon May 10, 2026
Thanks for updating the issue! It now meets our contributing guidelines. We appreciate you taking the time to provide the additional context.
github-actions commentedon Jul 10, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.