Skip to content

[FEATURE]:Context-Aware Proxy Middleware: intercept requests before LLM to reduce token costs 96–99% via MemPalace + SocratiCode #26685

Closed as not planned

Description

@MaikiOS

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

Related issues: #5148 #14451 #21240

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?

Activity

  1. github-actions commented on May 10, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • 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:

    If you believe this was flagged incorrectly, please let a maintainer know.

  2. added
    needs:complianceThis means the issue will auto-close after 2 hours.
    and removed
    needs:complianceThis means the issue will auto-close after 2 hours.
    on May 10, 2026
  3. github-actions commented on May 10, 2026

    @github-actions
    Contributor

    Thanks for updating the issue! It now meets our contributing guidelines. We appreciate you taking the time to provide the additional context.

  4. github-actions commented on Jul 10, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions