Skip to content

[FEATURE]: Session context usage (similar to /context in Claude) #6152

Closed

Description

@mtymek

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

I would like to implement a simple tool - TUI dialog - that displays a breakdown of the current session's context window usage, answering the question "what is eating my context window". A feature similar to /context command in Claude Code, but leveraging TUI dialog to avoid obstructing the chat log.
Its purpose is to optimize the context usage by understanding what exactly is consuming it.

I build a quick PoC, and while the real token usage is difficult to get, the estimations seem good enough to be useful.

Would you be interested in having such feature in the core?

Here's the PoC implement as a dialog:
Image

How does it work?

  • It exposes new server endpoint - /session/:sessionID/context that it then loaded in TUI when <leader>i key combo is pressed.
  • Token usage is estimated (4 characters per token) and then "calibrated" against the the actual total token usage reported by LLM provider. This is probably over-complicated, so I will play around with the methodology if this gets accepted.

It could be placed in the sidebar:
Image

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Dec 25, 2025
  2. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Dec 25, 2025
  3. github-actions commented on Dec 25, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if your specific case differs from these existing requests.

  4. ramarivera commented on Dec 25, 2025

    @ramarivera

    I was just about to raise a feature request for this and found yours, amazing :D

  5. mtymek commented on Jan 4, 2026

    @mtymek
    ContributorAuthor

    @thdxr seems there is some interest for this. Would you accept the PR?

  6. tebayoso commented on Jan 10, 2026

    @tebayoso

    We need this feature because some times the agent generates chunks of code that just breaks the context, for example taking a screenshot on a model that don't support vision, or reading a whole react site and using it as context. Being able to edit/update/modify context after this happens is a must.

  7. eparreno commented on Jan 12, 2026

    @eparreno

    Love this!!!

  8. DeveloperJose commented on Jan 18, 2026

    @DeveloperJose

    I'm working on this, you can see here how it looks like to analyze the context of your last sent message. You can also see what opencode sends and to what models when it wants a title or summary generated.

    Image
  9. nesk commented on Feb 17, 2026

    @nesk

    I would be really interested to have this feature. It's not always easy to understand how much enabling or disabling an MCP server can impact the context.

  10. 0xGurg commented on Mar 11, 2026

    @0xGurg

    +1 to this feature request.

  11. AvatarGanymede commented on Mar 11, 2026

    @AvatarGanymede

    I really need this feature to judge my skill and mcp costs

  12. jonathan5p commented on Mar 13, 2026

    @jonathan5p

    Already waiting for this feature to be included 🙏🏼

  13. Ciantic commented on Mar 16, 2026

    @Ciantic

    I would also like to see what the context was, not just the costs and usages. E.g. I want to drill down exact conversation, so I can see context bloat.

  14. AvatarGanymede commented on Mar 16, 2026

    @AvatarGanymede

    Is anyone working on this issue? I plan to develop this feature 'cause I really really need it

  15. 1 remaining item

  16. alxark commented on Mar 27, 2026

    @alxark

    Would like to see this feature in OpenCode (especially side bar stat).

  17. Djordje-Stojanovic commented on Apr 13, 2026

    @Djordje-Stojanovic

    This would be a truly useful feature that would make me switch to Opencode from claude directly. I would love to see the usage per file.

  18. Alezander9 commented on Apr 13, 2026

    @Alezander9

    Hello, I am bumping this issue and voicing my support for this feature request

  19. removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on May 3, 2026
  20. mikhailfur commented on May 31, 2026

    @mikhailfur

    This feature is important not only for context management, but also for cost control with OpenRouter / token-billed providers.

    Right now OpenCode users cannot clearly see whether context is consumed by chat history, file attachments, tool results, MCP schemas, or system/provider metadata. For models like Kimi via OpenRouter, this can directly turn one task into a $1+ request.

    Even an estimated context breakdown would be very useful:

    • model context limit
    • estimated context used
    • remaining context
    • chat/history tokens
    • attached file tokens
    • tool result tokens
    • MCP/tool schema tokens
    • compaction status
    • last provider-reported token usage

    A TUI panel/sidebar would be ideal, but even a /context command would already solve a big part of the problem.

  21. rhmndnt commented on Jun 12, 2026

    @rhmndnt

    What make us delay this feature? So much needed for my context anxiety. Please.

  22. theabecaster commented on Jun 20, 2026

    @theabecaster

    There've been a few takes on this already (#24210 most recently) that got auto-closed without ever being reviewed. Before I redo that work, is this something you'd actually accept, and is there a shape you want?

    I went digging through the code first and a decent chunk already exists: GET /api/session/:sessionID/context gives you the messages after the last compaction, and every assistant message already stores the provider's real token counts (input/output/cache). So the accurate total and the % used are basically free.

    The part that has to be estimated is the per-category split: system, tools, chat history, tool results, file reads. I'd estimate those roughly (chars/4) and then get the system+tools overhead by subtracting the estimated history from the real input total the provider already reported. That way the overhead number stays grounded and I don't have to rebuild the whole system prompt to measure it.

    Shape I had in mind: compute it in core (new context-usage.ts), put it on a sibling endpoint, TUI dialog on /context plus a leader keybind, and the desktop sidebar can reuse the same endpoint later.

    One thing I'd want your call on: is an estimate (chars/4) fine for v1, or do you want a real tokenizer? I'd rather not pull tiktoken in just for this.

    Happy to put up a small PR if the shape sounds right.

  23. enesgur commented on Aug 2, 2026

    @enesgur

    +1 to this feature.

  24. JakobHavtorn commented on Aug 6, 2026

    @JakobHavtorn

    Any activity on this issue? It would be a very welcomed feature.

  25. ZackarySantana commented on Aug 7, 2026

    @ZackarySantana

    I really liked context menus in other harnesses, so I built this extension in the meantime for opencode.

  26. tuan2linh commented on Oct 4, 2026

    @tuan2linh

    Real-world case for why context visibility + management matters

    @tebayoso's comment above already nails this:

    We need this feature because some times the agent generates chunks of code
    that just breaks the context, for example taking a screenshot on a model
    that don't support vision, or reading a whole react site and using it as
    context. Being able to edit/update/modify context after this happens is a
    must.

    Hit basically that exact scenario on opencode v2.0.18 (Desktop app, Windows),
    confirmed by pulling raw message history via
    opencode api get /api/session/{id}/message:

    1. Agent's own tool-result screenshot persists and gets reused silently.
      The agent called browser.screenshot (via Code Mode execute) to inspect
      a running Electron desktop app. That screenshot is a tool-result file part,
      rendered in the Desktop app transcript only inside a collapsible tool-call
      row -- not as a visible chat image like a user-pasted attachment. Many
      turns later, discussing an unrelated topic, the agent reused that stale
      screenshot (combined with a Get-Process timestamp) to make a UI claim,
      worded as if it were current. A later attempt to take a fresh screenshot
      failed ([browser.operation_failed] browser.screenshot failed. Screenshot needs a visible tab...), and the agent fell back to the stale cached
      image without flagging that explicitly.

    2. User-pasted images from earlier turns get referenced in later unrelated
      turns without being resent.
      Several images were pasted across different
      user turns (files: 1 each, confirmed via the message API). On a later
      turn with files: 0, the agent's reply said "latest image" / "the image
      you sent", reusing an earlier turn's image. Technically correct (full
      history is resent every call), but there's no way to tell which earlier
      image is being referenced, and no way to drop a specific stale image once
      it's no longer relevant -- short of a new session or a full /compact
      (lossy for everything else too).

    Without a /context view, there was no way to even confirm that this was
    happening -- I had to query the message API by hand to prove the stale image
    was still being resent. A context viewer (this issue) is the prerequisite for
    any kind of selective cleanup (the related ask in #7712, now closed as
    not-planned/duplicate -- but the underlying need is very much still live, see
    this thread and #3759).

    Environment:

    • opencode version: 2.0.18
    • OS: Windows_NT 10.0.26200 (win32 x64)
    • Client: Desktop app
    • Active plugins: opencode-browser
  27. dppalomar commented on Oct 9, 2026

    @dppalomar

    I totally agree that this /context command is necessary. Why OpenCode core developers don't consider this?

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