Skip to content

feat(opencode): add /ctx slash command to TUI for session stats#935

Open
bulutmuf wants to merge 1 commit into
mksglu:nextfrom
bulutmuf:feature/opencode-tui-ctx
Open

feat(opencode): add /ctx slash command to TUI for session stats#935
bulutmuf wants to merge 1 commit into
mksglu:nextfrom
bulutmuf:feature/opencode-tui-ctx

Conversation

@bulutmuf

@bulutmuf bulutmuf commented Jul 8, 2026

Copy link
Copy Markdown

This PR introduces the /ctx slash command to the OpenCode adapter, allowing users to view context-mode usage statistics directly from the OpenCode TUI interface.

What does this PR do?

  • Creates a new tui.ts module for the OpenCode adapter that exposes a TUI plugin via default export.
  • Registers the /ctx (with aliases ctx-stats, context-mode) slash command in OpenCode's palette namespace.
  • Displays a clean, dual-pane DialogAlert featuring:
    • Current Session: active session event counts, token estimates, and savings.
    • Lifetime: all-time session/event counts and top categories, rendered cleanly with ASCII progress bars.
  • Adds conditional SQLite backend resolution (bun:sqlite for Bun runtime in the TUI, falling back to better-sqlite3 for Node).
  • Updates README.md to instruct OpenCode and KiloCode users to register "context-mode/tui" in their tui.json.

Why is this needed?

  • OpenCode isolates TUI plugins from backend server plugins. While the context-mode MCP server starts correctly via opencode.json, users had no UI to monitor their token savings. This brings the terminal ctx stats functionality native to the OpenCode GUI.

How to test:

  1. Check out this branch.
  2. Build the project: npm run build
  3. Link the package locally (npm link) or run from the source directory.
  4. Add "context-mode/tui" to ~/.config/opencode/tui.json.
  5. Open OpenCode, type /ctx, and press Enter.

Affected Platforms

  • OpenCode (Node / Bun TUI)
  • KiloCode (Node / Bun TUI)
  • Claude Desktop (Electron / Node)
  • Standard MCP (smithery, etc.)

Checklist

  • I have tested these changes on the affected platforms.
  • My code follows the project's style guidelines.
  • npm test passes (or the failure is a known upstream issue).
  • npm run typecheck passes.
  • Cross-platform paths are handled correctly (no hardcoded Windows \ backslashes).
  • Documentation (README.md / SKILL.md) has been updated if applicable.

Registers a /ctx slash command (aliases: ctx-stats, context-mode) in the
OpenCode TUI that displays real-time and lifetime context-mode savings.

Implementation details:
- src/adapters/opencode/tui.ts: new TUI module exported as default
  { id: 'context-mode-tui', tui }. Queries SessionDB directly using
  bun:sqlite at runtime (since Bun TUI cannot load better-sqlite3).
- Displays a clean key:value layout with total events, estimated USD saved,
  and ASCII progress bars for the top 4 categories.
- package.json: added './tui' export pointing to tui.bundle.mjs; added
  tui.ts esbuild step to the bundle script (external: better-sqlite3, bun:sqlite).
- README.md: updated OpenCode and KiloCode installation guides to document
  registering 'context-mode/tui' in tui.json.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant