rtk-ai / rtk-ai/rtk

feat(hook): add OpenCode TUI stats panel with rtk init installation

Open
#1,925 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:cli area:ui enhancement help wanted priority:low
Dominant language
Rust
Stars
81k
Forks
5.1k
Avg merge
4d 21h
Merged PRs (30d)
35

Description

Description

RTK already has an OpenCode core plugin (rtk init -g --opencode) that hooks into tool execution to rewrite commands. What's missing is visibility into the token savings — users currently have to run rtk gain manually to see how much they're saving.
This feature adds a TUI stats panel for OpenCode that shows real-time token savings in the IDE sidebar, installed automatically alongside the core plugin.

Proposed behavior

TUI plugin (rtk-stats.tsx)

A sidebar widget (sidebar_content slot, order: 40) showing:

  • Header: RTK version with GitHub release check (✓/⚠)
  • Stats (expandable): total commands, input/output tokens, tokens saved (green), average savings rate
  • Efficiency meter: visual progress bar (████████░░░░ 96.4%)
  • Refresh: every 30 minutes (background info, not real-time monitor)
  • Per-project badge: shows project name when project-scoped stats exist
  • Graceful degradation: if RTK is not installed, shows "RTK not present" — never crashes the UI
Installation (rtk init -g --opencode)

The existing rtk init -g --opencode command should install both:

  1. ~/.config/opencode/plugins/rtk.ts (core plugin — auto-rewrite) — already exists
  2. ~/.config/opencode/tui-plugins/rtk-stats.tsx (TUI stats panel) — new
  3. Auto-patch ~/.config/opencode/tui.json to register the TUI plugin — new
    Properties:
  • Idempotent: re-running the command is a no-op if content is unchanged
  • Graceful: if tui.json is missing → creates it; if malformed → rebuilds it
  • Atomic writes via NamedTempFile + .persist()
Data sources
  • rtk gain -f json — overall stats
  • rtk gain --project -f json — project-scoped stats (when applicable)
  • rtk gain --quota — quota information (text parsed)
  • GitHub releases API — version check

Files changed

File Change
hooks/opencode/rtk-stats.tsx New — TUI stats panel (SolidJS + OpenTUI)
src/hooks/init.rs Add TUI plugin installation + tui.json patching
src/hooks/constants.rs Add TUI_PLUGIN_SUBDIR, OPENCODE_TUI_PLUGIN_FILE, TUI_JSON
src/main.rs No changes needed (reuses --opencode flag)

Estimated token savings

The panel itself doesn't save tokens (it's visual), but it surfaces the savings data that RTK already collects, making users more aware of the value. Reduces friction by removing the need to run rtk gain manually.

Implementation status

Already implemented and tested on a fork. Ready for review.

Environment

  • RTK version: 0.28.x+
  • OpenCode: any version with TUI plugin support

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing OpenCode installation path in src/hooks/init.rs and related constants in src/hooks/constants.rs, then inspect hooks/opencode/rtk-stats.tsx. Verify the described panel states and the rtk init -g --opencode installation behavior, including idempotent, malformed, missing, and atomic tui.json handling; done means the plugin is installed and registered without breaking when RTK is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, rust, typescript
Domain
cli, developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.