Skip to content

How to Install RTK with OpenCode: A Step-by-Step Guide

I wanted to add token counting to my OpenCode setup. RTK (Rust Token Killer) seemed like the right tool, but I couldn’t find clear installation instructions. The README mentioned OpenCode support, but didn’t explain how to actually enable it.

After some trial and error, I figured it out. Here’s what worked.

The Problem

RTK v0.29.0 added OpenCode support, but the documentation is sparse. I found a Reddit thread confirming the feature exists, but no step-by-step guide. The key comment was:

“at least we can clone and built it ourself or just take the rtk.ts and put them to opencode plugin folder then call the function name inside opencode.json to activate the plugin” - Ang_Drew

This gave me the basic idea, but I still needed to figure out the exact steps.

What I Tried First

I cloned the repo and looked for documentation:

Terminal window
git clone https://github.com/rtk-ai/rtk.git
cd rtk

The README had general installation instructions, but nothing specific to OpenCode integration. I noticed two branches: dev and master. Which one should I use?

Mistake #1: I initially tried the dev branch, thinking it would have the latest features. The plugin file was there, but it caused errors in my OpenCode setup.

Mistake #2: I tried building from source without checking if pre-built releases existed.

The Working Solution

After checking the releases page, I found v0.29.0 already included the OpenCode plugin. Here’s what actually worked:

Step 1: Download the Release

Terminal window
wget https://github.com/rtk-ai/rtk/releases/download/v0.29.0/rtk-0.29.0.tar.gz
tar -xzf rtk-0.29.0.tar.gz

The release package includes rtk.ts in the root directory—this is the OpenCode plugin file.

Step 2: Copy to OpenCode Plugin Folder

Your OpenCode plugin location may vary. Check your OpenCode configuration:

Terminal window
# For global installation
cp rtk.ts ~/.opencode/plugins/
# Or for project-specific:
cp rtk.ts ./opencode/plugins/

I initially put it in the wrong folder and couldn’t figure out why it wasn’t loading. Make sure to verify your actual plugin path.

Step 3: Register in opencode.json

This is the step I almost missed. Copying the file alone won’t activate the plugin. You need to register it:

{
"plugins": {
"rtk": {
"path": "plugins/rtk.ts",
"enabled": true
}
}
}

The key is the enabled: true field. Without it, the plugin sits there doing nothing.

Step 4: Verify It Works

Restart OpenCode and check if the plugin loaded:

# In OpenCode console or settings
# Look for RTK plugin status

Try a token counting operation to confirm functionality.

Why This Works

RTK uses a TypeScript plugin architecture for OpenCode integration. The rtk.ts file exports functions that OpenCode can call when you request token counting. By registering it in opencode.json, you’re telling OpenCode where to find these functions and that it should load them.

The plugin pattern looks like this:

OpenCode
|
v
opencode.json (registration)
|
v
rtk.ts (plugin code)
|
v
RTK Core (token counting logic)

Common Pitfalls

  1. Wrong version: Versions before v0.29.0 don’t have OpenCode support. Check your version.

  2. Missing registration: The plugin file exists, but OpenCode doesn’t know about it. Always add the opencode.json entry.

  3. Incorrect path: OpenCode can’t find rtk.ts if the path in opencode.json doesn’t match the actual file location.

  4. Plugin disabled: Forgetting enabled: true means the plugin won’t load even if registered.

When to Use RTK vs Alternatives

RTK shines when you need:

  • Accurate token counting for LLM prompts
  • Rust-based performance for large files
  • OpenCode integration

Consider alternatives if:

  • You don’t need token counting
  • Your OpenCode version doesn’t support this plugin architecture
  • You prefer a different tokenization method

Summary

Installing RTK with OpenCode requires:

  1. Download v0.29.0+ release
  2. Copy rtk.ts to your plugin folder
  3. Register it in opencode.json with enabled: true
  4. Restart and verify

The whole process takes about 5 minutes once you know the steps. The lack of documentation made this harder than it needed to be, but the Reddit thread pointed me in the right direction.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments