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
- Launch an OpenCode Desktop session.
- From any agent, invoke a native file tool, e.g.: -
glob with any pattern - Read on any file - Edit on any file
- 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)
Summary
Under OpenCode Desktop, the built-in native file tools (
Read,Write,Edit,glob,grep) fail immediately with the error stringBun 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.## EnvironmentReproduction
globwith any pattern -Readon any file -Editon any fileBun is not definedNo file content is read or written; the call fails before any filesystem work.## Observed across toolsDirect evidence of failure in sessions on this machine:-
globΓåÆBun is not defined-ReadΓåÆBun is not defined-EditΓåÆBun is not defined``Writeandgrepwere 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, tablepart(each tool call is onepartrow whose
datacolumn is JSON). Aggregated across the full table:Bun is not definedsession.version = "local")All five native file tools are confirmed affected (upgraded from the "assumed" wording
in the original report):
readglobwriteeditgreppartrow 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
read/write/edit): the error isreturned before any filesystem work, consistent with a missing global (
globalThis.Bun)at tool-init time rather than an I/O or permission failure.
PowerShell (
Get-Content/Set-Content/Select-String/Get-ChildItem), after which fileaccess works normally — pointing at the tool implementation/runtime, not the filesystem.
Desktop, not an intermittent fault.
CLI vs Desktop- CLI (
opencodein 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.Bunis 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)
"Bun is not defined",file tool Read Edit Bun,glob grep Bun Windows Desktop, andnative tool undefined Windows(all states). The only directly related issue found was Desktop v1.14.39: Bun-target plugins fail to load (Node.js sidecar lacks Bun APIs) #25880 (third-party plugin load failures under the Desktop Node sidecar). I did not find any existing issue covering native built-in file tools failing with this error, which is why I'm filing this separately rather than commenting on Desktop v1.14.39: Bun-target plugins fail to load (Node.js sidecar lacks Bun APIs) #25880. Happy to consolidate if maintainers prefer.Current workaround
Switch the entire session to PowerShell via the
bashtool (do not retry the native tools per-call — each retry is wasted). Mapping:-Read→Get-Content -Raw-Write→Set-Content -Encoding utf8-Edit→Select-Stringto 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 throwBun is not definedunder 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 (coversBun.file/Bun.write-style usage in native tools), or4. Rewrite native file tools to be runtime-agnostic (noBun.*references).## Related issues- #25880 ΓÇö Desktop v1.14.39: Bun-target plugins fail to load (Node.js sidecar lacks Bun APIs)