Skip to content

OpenCode Desktop does not detect rtk when launched from macOS GUI #2039

Closed as duplicate

Description

@gokhancvs

Problem

RTK works when OpenCode is started from a terminal, but it does not work when using OpenCode Desktop launched normally.

This suggests the OpenCode Desktop runtime may not be loading the same environment as the user’s shell session. As a result, the RTK OpenCode plugin may fail to detect or execute the rtk binary even though RTK is installed and available in the terminal.

Expected Behavior

OpenCode Desktop should load the RTK plugin.

Actual Behavior

  • Starting OpenCode from terminal: RTK works.
  • Starting OpenCode Desktop normally: RTK does not appear to run.

Possible Cause

The Desktop app may be running with a different environment than the user’s login shell, especially a different PATH. The RTK plugin currently depends on resolving rtk from the runtime environment, so it may disable itself if the binary is not discoverable there.

Reproduction

  1. Install and configure RTK for OpenCode.
  2. Confirm RTK works when OpenCode is launched from terminal.
  3. Launch OpenCode Desktop normally.
  4. Run a command that should be rewritten by RTK.
  5. Observe that RTK is not used.

Activity

  1. added
    bug
    help wanted
    on May 27, 2026
  2. pszymkowiak commented on May 27, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 88%

    Summary

    OpenCode Desktop on macOS doesn't inherit shell PATH, causing RTK binary detection to fail; needs GUI app PATH resolution fix.


    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. alexandre-leites commented on Jun 2, 2026

    @alexandre-leites

    Any workaround while this is not merged?

  4. ishrakr commented on Jun 11, 2026

    @ishrakr

    bump. Looking for workarounds for this as well.

  5. foch01 commented on Jun 22, 2026

    @foch01

    Here is the plugin modification I mentioned that I made so that it would work on my Mac.

    import type { Plugin } from "@opencode-ai/plugin"
    import { existsSync } from "fs"
    import { spawn } from "child_process"
    
    // RTK OpenCode plugin — rewrites commands to use rtk for token savings.
    // Requires: rtk >= 0.23.0 installed at a known path.
    //
    // This is a thin delegating plugin: all rewrite logic lives in `rtk rewrite`,
    // which is the single source of truth (src/discover/registry.rs).
    // To add or change rewrite rules, edit the Rust registry — not this file.
    
    const RTK_CANDIDATES = [
      "/opt/homebrew/bin/rtk",
      "/usr/local/bin/rtk",
      (process.env.HOME ?? "") + "/.local/bin/rtk",
    ]
    
    function findRtk(): string | null {
      for (const candidate of RTK_CANDIDATES) {
        if (existsSync(candidate)) return candidate
      }
      return null
    }
    
    function rtkRewrite(bin: string, command: string): Promise<string> {
      return new Promise((resolve) => {
        const proc = spawn(bin, ["rewrite", command])
        let out = ""
        proc.stdout.on("data", (d) => { out += d })
        proc.on("close", () => resolve(out.trim()))
        proc.on("error", () => resolve(""))
      })
    }
    
    export const RtkOpenCodePlugin: Plugin = async () => {
      const rtkBin = findRtk()
      if (!rtkBin) {
        console.warn("[rtk] rtk binary not found — plugin disabled")
        return {}
      }
    
      return {
        "tool.execute.before": async (input, output) => {
          const tool = String(input?.tool ?? "").toLowerCase()
          if (tool !== "bash" && tool !== "shell") return
          const args = output?.args
          if (!args || typeof args !== "object") return
    
          const command = (args as Record<string, unknown>).command
          if (typeof command !== "string" || !command) return
    
          const rewritten = await rtkRewrite(rtkBin, command)
          if (rewritten && rewritten !== command) {
            ;(args as Record<string, unknown>).command = rewritten
          }
        },
      }
    }

    Here's the quick win I found :

    • $ (shell Bun) is not available in tool.execute.before, nor for detecting the binary at startu. Replaced by the native existsSync and spawn.

    • execFile rejected exit code 3 from rtk rewrite as an error — replaced by spawn, which ignores the exit code.

  6. pkorecki commented on Jun 23, 2026

    @pkorecki

    Hello, is this defect to be fixed in RTK plugin or more in OpenCode Desktop app?

  7. trongnsiwa commented on Jun 26, 2026

    @trongnsiwa

    I have same issue

  8. nusbru commented on Aug 13, 2026

    @nusbru

    Same issue using linux OpenCode Desktop application.

  9. KuSh commented on Sep 26, 2026

    @KuSh
    Collaborator

    Closing as a duplicate of #3326. The linked fix work (#2153) showed that OpenCode Desktop runs the plugin under Node, where the Bun $ helper is missing, and the plugin reports that as 'not found in PATH'. #3326 tracks that same failure, plus the Windows which case, and has the open fixes linked. Please follow up there, especially if your Desktop setup still fails once $ is replaced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:configbughelp wantedplatform:macospriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions