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

Closed
opened 2026-02-16 18:04:41 -05:00 by yindo · 6 comments
Owner

Originally created by @iliferov on GitHub (Jan 17, 2026).

Originally assigned to: @adamdotdevin on GitHub.

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)

Originally created by @iliferov on GitHub (Jan 17, 2026). Originally assigned to: @adamdotdevin on GitHub. ### 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` ```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` ```ts import sys a = float(sys.argv[1]) b = float(sys.argv[2]) print(a + b) ``` 3. Open this project in OpenCode Desktop. 4. Run the prompt: `Use python-add tool (provide any arguments) and print verbatim everything between TOOL_RAW markers` 5. 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. <img width="2442" height="1958" alt="Image" src="https://github.com/user-attachments/assets/281b9328-6806-471e-bfc3-64d506da7fe4" /> #### ❌ Actual behavior (OpenCode Desktop) Tools run with cwd set to / (system root). Relative path lookups fail, so the tool cannot be found. <img width="2814" height="2088" alt="Image" src="https://github.com/user-attachments/assets/1cdc31c8-4eb7-4c7c-9e75-53b27b9bcbfc" /> ### Operating System macOS Tahoe 26.1 ### Terminal Terminal (macOS)
yindo added the bugweb labels 2026-02-16 18:04:41 -05:00
yindo closed this issue 2026-02-16 18:04:42 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 17, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #7143: Desktop Glob searches /xxx path from root directory instead of project directory - appears to be the same underlying issue affecting file operations
  • #6697: Session switching doesn't change working directory context - broader issue affecting all file tools and shell execution with incorrect cwd
  • #8389: EACCES permission denied, mkdir /.opencode - symptom showing tools trying to write to root directory instead of project

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 17, 2026): This issue might be a duplicate of existing issues. Please check: - #7143: Desktop Glob searches /xxx path from root directory instead of project directory - appears to be the same underlying issue affecting file operations - #6697: Session switching doesn't change working directory context - broader issue affecting all file tools and shell execution with incorrect cwd - #8389: EACCES permission denied, mkdir /.opencode - symptom showing tools trying to write to root directory instead of project Feel free to ignore if none of these address your specific case.
Author
Owner

@neriousy commented on GitHub (Jan 17, 2026):

I'll try to fix it

@neriousy commented on GitHub (Jan 17, 2026): I'll try to fix it
Author
Owner

@adamdotdevin commented on GitHub (Jan 26, 2026):

@iliferov I think the problem here is that you can't use process.cwd(), you'll need to use ctx.directory (which won't be available until tomorrow's release: https://github.com/anomalyco/opencode/commit/a8c18dba8205d7707a46ec0859db672370be8963)

@adamdotdevin commented on GitHub (Jan 26, 2026): @iliferov I think the problem here is that you can't use `process.cwd()`, you'll need to use `ctx.directory` (which won't be available until tomorrow's release: https://github.com/anomalyco/opencode/commit/a8c18dba8205d7707a46ec0859db672370be8963)
Author
Owner

@pschiel commented on GitHub (Jan 28, 2026):

Using path.resolve will not work on Windows and mixed paths (native, git bash, ..)

#6763 normalization is needed for relative and cross-drive mixed paths

@pschiel commented on GitHub (Jan 28, 2026): Using `path.resolve` will not work on Windows and mixed paths (native, git bash, ..) #6763 normalization is needed for relative and cross-drive mixed paths
Author
Owner

@ualtinok commented on GitHub (Jan 30, 2026):

This issue is closed however opencode desktop app on mac still having this problem. When model doesn't provide the path to a tool like grep or glob, the tool defaults to "/" and searches the whole file system, which causes a lot of file permission requests and a lot of cpu usage.

@ualtinok commented on GitHub (Jan 30, 2026): This issue is closed however opencode desktop app on mac still having this problem. When model doesn't provide the path to a tool like grep or glob, the tool defaults to "/" and searches the whole file system, which causes a lot of file permission requests and a lot of cpu usage.
Author
Owner

@iliferov commented on GitHub (Feb 3, 2026):

@iliferov I think the problem here is that you can't use process.cwd(), you'll need to use ctx.directory (which won't be available until tomorrow's release: a8c18db)

I confirm it works fine with context.directory. So from 1.1.49 the approach to write a custom tool mentioned in docs works as expected in OpenCode Desktop.

Replaced

const cwd = process.cwd()
const script_path = path.resolve(".opencode/tool/add.py")

to

const script_path = path.join(context.directory, ".opencode/tools/add.py")
Image
@iliferov commented on GitHub (Feb 3, 2026): > [@iliferov](https://github.com/iliferov) I think the problem here is that you can't use `process.cwd()`, you'll need to use `ctx.directory` (which won't be available until tomorrow's release: [a8c18db](https://github.com/anomalyco/opencode/commit/a8c18dba8205d7707a46ec0859db672370be8963)) I confirm it works fine with `context.directory`. So from 1.1.49 the approach to write a custom tool mentioned in [docs](https://opencode.ai/docs/custom-tools/#context) works as expected in OpenCode Desktop. Replaced ```python const cwd = process.cwd() const script_path = path.resolve(".opencode/tool/add.py") ``` to ```python const script_path = path.join(context.directory, ".opencode/tools/add.py") ``` <img width="967" height="925" alt="Image" src="https://github.com/user-attachments/assets/3127fc5d-bcc5-47ea-8ad4-19a265302661" />
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6594