opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Can't run tools in OpenCode Desktop - tools executed from / instead of project cwd

Open iliferov opened this issue 21 hours ago • 2 comments

Description

In OpenCode Desktop, tools are executed as if the working directory is / (system root), not the current project directory. This breaks tools that rely on relative paths (e.g. .opencode/tool/**). In OpenCode CLI the same tools run correctly.

Plugins

no plugins

OpenCode version

CLI - 1.1.20, Desktop - 1.1.25

Steps to reproduce

  1. Create an empty project folder.
  2. In the project folder create the tool files: .opencode/tool/python-add.ts
import {tool} from "@opencode-ai/plugin"
import path from "path"
export default tool({
  description: "Add two numbers using Python",
  args: {
    a: tool.schema.number().describe("First number"),
    b: tool.schema.number().describe("Second number"),
  },
  async execute(args) {
    const cwd = process.cwd()
    const script_path = path.resolve(".opencode/tool/add.py")
    const p = Bun.spawn(
      ["python3", script_path, String(args.a), String(args.b)],
      { stdout: "pipe", stderr: "pipe" }
    )
    const stdout = await new Response(p.stdout).text()
    const stderr = await new Response(p.stderr).text()
    const exitCode = await p.exited
    return [
      "===TOOL_RAW===",
      JSON.stringify({ cwd, script_path, stdout, stderr, exitCode }, null, 2),
      "===/TOOL_RAW===",
    ].join("\n")
  }
})

.opencode/tool/add.py

import sys
a = float(sys.argv[1])
b = float(sys.argv[2])
print(a + b)
  1. Open this project in OpenCode Desktop.
  2. Run the prompt: Use python-add tool (provide any arguments) and print verbatim everything between TOOL_RAW markers
  3. Observe the tool output:
    • Desktop sets cwd to /
    • script_path resolves to /.opencode/tool/add.py
    • Python fails with "No such file or directory"

Screenshot and/or share link

✅ Expected behavior (OpenCode CLI)

Tools run with cwd set to the project directory, so .opencode/tool/** resolves correctly. Image

❌ Actual behavior (OpenCode Desktop)

Tools run with cwd set to / (system root). Relative path lookups fail, so the tool cannot be found.

Image

Operating System

macOS Tahoe 26.1

Terminal

Terminal (macOS)

iliferov avatar Jan 17 '26 12:01 iliferov