opencode icon indicating copy to clipboard operation
opencode copied to clipboard

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

Open mtymek opened this issue 1 month ago • 6 comments

Feature hasn't been suggested before.

  • [x] 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

mtymek avatar Dec 25 '25 10:12 mtymek

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

  • #1990: Add User Controls for Context Management - Proposes context management commands including a /tokens command to display token usage breakdown
  • #2995: Feature: status command - Requests a /status command similar to Claude that would show used context breakdown
  • #4659: Sliding window context management for long-running sessions - Proposes an extensive context management system with a TUI context viewer that shows token usage breakdown
  • #3759: More Detailed Subagent's Context - Requests ability to see context size, tool calls, token usage, and context size for optimization

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

github-actions[bot] avatar Dec 25 '25 10:12 github-actions[bot]

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

ramarivera avatar Dec 25 '25 19:12 ramarivera

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

mtymek avatar Jan 04 '26 20:01 mtymek

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.

tebayoso avatar Jan 10 '26 22:01 tebayoso

Love this!!!

eparreno avatar Jan 12 '26 20:01 eparreno