feat(hook): add OpenCode TUI stats panel with rtk init installation
#1.925 aberto em 16 de mai. de 2026
Métricas do repositório
- Stars
- (48.085 stars)
- Métricas de merge de PR
- (Mesclagem média 11d 1h) (45 fundiu PRs em 30d)
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:
~/.config/opencode/plugins/rtk.ts(core plugin — auto-rewrite) — already exists~/.config/opencode/tui-plugins/rtk-stats.tsx(TUI stats panel) — new- Auto-patch
~/.config/opencode/tui.jsonto register the TUI plugin — new Properties:
- Idempotent: re-running the command is a no-op if content is unchanged
- Graceful: if
tui.jsonis missing → creates it; if malformed → rebuilds it - Atomic writes via
NamedTempFile+.persist()
Data sources
rtk gain -f json— overall statsrtk 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