Skip to content

feat(init): add --opencode flag for OpenCode plugin install#455

Open
wouter-intveld wants to merge 1 commit intortk-ai:masterfrom
wouter-intveld:feat/opencode-init
Open

feat(init): add --opencode flag for OpenCode plugin install#455
wouter-intveld wants to merge 1 commit intortk-ai:masterfrom
wouter-intveld:feat/opencode-init

Conversation

@wouter-intveld
Copy link

Summary

  • Add rtk init --opencode to install an OpenCode plugin that transparently rewrites bash commands to use rtk
  • The plugin uses OpenCode's tool.execute.before hook — the equivalent of Claude Code's PreToolUse hook
  • Update README Quick Start and Auto-Rewrite Hook sections to include OpenCode alongside Claude Code

How it works

rtk init --opencode

Installs opencode-rtk.js to ~/.config/opencode/plugins/ — OpenCode auto-discovers it on restart. The plugin intercepts bash tool calls, runs rtk rewrite on the command, and mutates the args before execution. The LLM never sees the rewrite, just compressed output.

Changes

File Change
hooks/opencode-rtk.js New — OpenCode plugin (embedded in binary via include_str!)
src/main.rs Add --opencode flag to init subcommand (mutually exclusive with --claude-md, --hook-only)
src/init.rs Add run_opencode_mode() + resolve_opencode_dir()
README.md Add OpenCode to Quick Start + Auto-Rewrite Hook sections

Design decisions

  • Minimal and additive — doesn't touch any existing Claude Code flows
  • No config patching needed — OpenCode auto-discovers plugins from the plugins/ directory (unlike Claude Code's settings.json patching)
  • Reuses existing patternsinclude_str!(), write_if_changed(), resolve_*_dir()
  • Idempotent — safe to run multiple times, only writes if content changed

Validation

  • cargo build passes
  • rtk init --opencode installs the plugin correctly
  • Tested in a live OpenCode session — commands like git status, ls, cargo test are transparently rewritten

Related

Complements #417 (OpenCode discover provider) — that PR adds analytics for missed savings, this PR adds the actual command rewriting.

@bxb1337
Copy link

bxb1337 commented Mar 10, 2026

can we get this faster? It's really good, cant wait to use it in my opencode sessions!

Add rtk init --opencode to install an OpenCode plugin that
transparently rewrites bash commands via the tool.execute.before
hook, equivalent to the existing Claude Code PreToolUse hook.

The plugin is embedded in the binary and written to
~/.config/opencode/plugins/opencode-rtk.js on install.

Complements rtk-ai#417 (OpenCode discover provider).
@pszymkowiak
Copy link
Collaborator

Hi! Thanks for the contribution! Since March 6, all PRs should target the develop branch instead of master (see CONTRIBUTING.md).

Could you update the base branch? Click Edit at the top right of this PR and change it from master to develop.

Thanks!

@pszymkowiak
Copy link
Collaborator

Thanks for the contribution! OpenCode support has been merged into develop via #300 (plugin + init lifecycle). It will be available in the next release once develop is merged to master. This PR is now superseded — if you'd like to contribute further, check the open issues!

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.

3 participants