feat(hook): add OpenCode TUI stats panel with rtk init installation
Nobody has claimed this yet.
- 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:
~/.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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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