Skip to content

[Bug] Native built-in file tools (Read/Write/Edit/glob/grep) return "Bun is not defined" under Desktop #35573

Description

@DaveW001

Summary

Under OpenCode Desktop, the built-in native file tools (Read, Write, Edit, glob, grep) fail immediately with the error string Bun is not defined. This is distinct from #25880, which tracks third-party plugins failing to load under the Node sidecar ΓÇö here the affected components are opencode's own first-party tools, not user-installed plugins.## Environment

  • OS: Windows 11
  • OpenCode CLI: 1.15.10 (installed via npm global; runs under Bun and works fine)
  • OpenCode Desktop: running (Electron app process active)- Bun: 1.3.4 (installed and on PATH)
  • Node.js: v24.12.0

Reproduction

  1. Launch an OpenCode Desktop session.
  2. From any agent, invoke a native file tool, e.g.: - glob with any pattern - Read on any file - Edit on any file
  3. The tool returns the error: Bun is not definedNo file content is read or written; the call fails before any filesystem work.## Observed across tools

Direct evidence of failure in sessions on this machine:- glob → Bun is not defined- Read → Bun is not defined- Edit → Bun is not defined``Write and grep were initially assumed affected; the canonical-database evidence below confirms all of Write, Edit, and grep (across hundreds of sessions).## Concrete evidence (canonical session database)

Captured from OpenCode's authoritative session store — the SQLite database at
<user>/.local/share/opencode/opencode.db, table part (each tool call is one part
row whose data column is JSON). Aggregated across the full table:

Metric Value
Tool-parts returning Bun is not defined 2,611
Distinct sessions affected 494
Date range 2026-05-31 → 2026-07-06 (5+ weeks)
Reproducer environment OpenCode Desktop, local builds (session.version = "local")

All five native file tools are confirmed affected (upgraded from the "assumed" wording
in the original report):

Tool Error occurrences
read 1,622
glob 465
write 241
edit 152
grep 131

part row shape

{ "type":"tool","tool":"<name>","callID":"toolu_…",
  "state":{ "status":"error","input":{…},"error":"Bun is not defined",
            "time":{ "start":…,"end":… } } }

Representative anonymized records

read — fails in ~4 ms; no filesystem access occurs

{ "tool":"read","state":{ "status":"error",
  "input":{ "filePath":"C:\\Users\\<user>\\projects\\<repo>" },
  "error":"Bun is not defined","time":{ "start":1780266435647,"end":1780266435651 } } }

write — fails in ~2 ms (content elided)

{ "tool":"write","state":{ "status":"error",
  "input":{ "filePath":"C:\\Users\\<user>\\projects\\<repo>\\doc.md","content":"…" },
  "error":"Bun is not defined","time":{ "duration_ms":2 } } }

edit — fails in ~3 ms

{ "tool":"edit","state":{ "status":"error",
  "input":{ "filePath":"C:\\Users\\<user>\\.config\\opencode\\opencode.jsonc",
            "oldString":"\"small_model\": \"openai/gpt-5.4-mini\",",
            "newString":"\"small_model\": \"zai-coding-plan/glm-5.1\"," },
  "error":"Bun is not defined","time":{ "duration_ms":3 } } }

glob

{ "tool":"glob","state":{ "status":"error",
  "input":{ "pattern":".opencode/**/*","path":"C:\\Users\\<user>\\projects\\<repo>" },
  "error":"Bun is not defined" } }

grep

{ "tool":"grep","state":{ "status":"error",
  "input":{ "pattern":"session.*name|title.*generat","include":"*.go" },
  "error":"Bun is not defined","time":{ "duration_ms":454 } } }

Observations

  • Failures are synchronous and fast (2–4 ms for read/write/edit): the error is
    returned before any filesystem work, consistent with a missing global (globalThis.Bun)
    at tool-init time rather than an I/O or permission failure.
  • Deterministic per session: every native-file-tool call fails until the agent switches to
    PowerShell (Get-Content/Set-Content/Select-String/Get-ChildItem), after which file
    access works normally — pointing at the tool implementation/runtime, not the filesystem.
  • 494 sessions over 5+ weeks indicates a persistent, reproducer-stable condition under
    Desktop, not an intermittent fault.

CLI vs Desktop- CLI (opencode in PowerShell, Bun runtime): native file tools work.-

Desktop (Electron, Node.js sidecar): native file tools fail with Bun is not defined.

This CLI/Desktop split mirrors the pattern in #25880, which suggests the same underlying root cause: the Desktop sidecar runs Node.js where globalThis.Bun is undefined, and the native tool implementations reference Bun-specific APIs (e.g. Bun.file, Bun.write).

How this differs from #25880

Issue search (prior art)

Current workaround

Switch the entire session to PowerShell via the bash tool (do not retry the native tools per-call — each retry is wasted). Mapping:- Read → Get-Content -Raw- Write → Set-Content -Encoding utf8- Edit → Select-String to locate + literal [string]::Replace() (not regex -replace)- glob → Get-ChildItem -Recurse- grep → Select-StringThis keeps sessions functional but loses the native tools' structured output and forces every file operation through shell quoting, which is higher-variance and hazard-prone (literal structural-character edits, indentation bleed, etc.).

Likely root cause (hypothesis, please confirm)

The Desktop sidecar switched from Bun to Node.js/Electron's bundled Node around v1.14.35 (per #25880). If the native file tool implementations were written against Bun globals (Bun.file / Bun.write / etc.), they will throw Bun is not defined under Node even though Bun is installed on the host ΓÇö because the tool code runs inside the sidecar process, not the host shell.## Suggested fixes (any one)1. Restore the Desktop sidecar to the Bun runtime, or2. Provide a config option to select sidecar runtime (Bun / Node.js), or3. Ship a Bun API polyfill in the Desktop Node sidecar (covers Bun.file/Bun.write-style usage in native tools), or4. Rewrite native file tools to be runtime-agnostic (no Bun.* references).## Related issues- #25880 ΓÇö Desktop v1.14.39: Bun-target plugins fail to load (Node.js sidecar lacks Bun APIs)

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions