OpenCode executes bunfig.toml preload scripts from the working directory #3454

Open
opened 2026-02-16 17:40:08 -05:00 by yindo · 6 comments
Owner

Originally created by @m1yon on GitHub (Dec 10, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

When starting OpenCode in a directory that contains a bunfig.toml file with a preload configuration, OpenCode incorrectly executes the specified preload scripts. This causes unexpected behavior, such as running setup scripts intended for the project's runtime environment, not the editor/agent environment.

Expected behavior

OpenCode should not load or execute the project's bunfig.toml preload scripts during its own startup. It should run in isolation from the project's runtime configuration.

OpenCode version

1.0.143

Steps to reproduce

  1. Create a project directory with a bunfig.toml file.
  2. Add a preload script to bunfig.toml:
preload = ["./src/setup.ts"]
  1. Create the corresponding script (e.g., src/setup.ts) with some side effects (e.g., logging, network requests, or process.exit()).
  2. Start OpenCode in this directory.
  3. Observe that the preload script is executed.

Screenshot and/or share link

No response

Operating System

macOS 15.6.1 (Build 24G90)

Terminal

Ghostty

Originally created by @m1yon on GitHub (Dec 10, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description When starting OpenCode in a directory that contains a `bunfig.toml` file with a `preload` configuration, OpenCode incorrectly executes the specified preload scripts. This causes unexpected behavior, such as running setup scripts intended for the project's runtime environment, not the editor/agent environment. ### Expected behavior OpenCode should not load or execute the project's bunfig.toml preload scripts during its own startup. It should run in isolation from the project's runtime configuration. ### OpenCode version 1.0.143 ### Steps to reproduce 1. Create a project directory with a `bunfig.toml` file. 2. Add a `preload` script to `bunfig.toml`: ```toml preload = ["./src/setup.ts"] ``` 3. Create the corresponding script (e.g., src/setup.ts) with some side effects (e.g., logging, network requests, or `process.exit()`). 4. Start OpenCode in this directory. 5. Observe that the preload script is executed. ### Screenshot and/or share link _No response_ ### Operating System macOS 15.6.1 (Build 24G90) ### Terminal Ghostty
yindo added the help-wantedbug labels 2026-02-16 17:40:08 -05:00
Author
Owner

@rekram1-node commented on GitHub (Dec 10, 2025):

thanks, will fix

@rekram1-node commented on GitHub (Dec 10, 2025): thanks, will fix
Author
Owner

@rekram1-node commented on GitHub (Dec 18, 2025):

This is weird, I can replicate but I don't know what's causing it, we clearly set the flag here to disable it:
https://github.com/sst/opencode/blob/26d0280f70760a1212636683c1b5753afa4e70d8/packages/opencode/script/build.ts#L118

@rekram1-node commented on GitHub (Dec 18, 2025): This is weird, I can replicate but I don't know what's causing it, we clearly set the flag here to disable it: https://github.com/sst/opencode/blob/26d0280f70760a1212636683c1b5753afa4e70d8/packages/opencode/script/build.ts#L118
Author
Owner

@rekram1-node commented on GitHub (Dec 19, 2025):

Might be a bun bug, adding label if anyoen can investigate this deeper

@rekram1-node commented on GitHub (Dec 19, 2025): Might be a bun bug, adding label if anyoen can investigate this deeper
Author
Owner

@OpeOginni commented on GitHub (Dec 21, 2025):

Did some digging, its a super weird thing. Bun seems to be okay, their tests work.

One thing i notice is that if you run the opencode with any args (doesnt matter if its valid or not), it doesnt run the bunfig.toml.

So opencode calls the preload
opencode . doesnt call the preload
opencode --version doesnt call the preload

@OpeOginni commented on GitHub (Dec 21, 2025): Did some digging, its a super weird thing. Bun seems to be okay, their tests work. One thing i notice is that if you run the `opencode` with any args (doesnt matter if its valid or not), it doesnt run the `bunfig.toml`. So `opencode` calls the preload `opencode .` doesnt call the preload `opencode --version` doesnt call the preload
Author
Owner

@aptor9 commented on GitHub (Jan 18, 2026):

Vide coded this one: https://github.com/anomalyco/opencode/pull/9347. How do I request a code review?

@aptor9 commented on GitHub (Jan 18, 2026): Vide coded this one: https://github.com/anomalyco/opencode/pull/9347. How do I request a code review?
Author
Owner

@OpeOginni commented on GitHub (Jan 19, 2026):

@rekram1-node seems the Bug in Bun has been fixed https://github.com/oven-sh/bun/issues/25640, ill try it out and see if it works.

@OpeOginni commented on GitHub (Jan 19, 2026): @rekram1-node seems the Bug in Bun has been fixed https://github.com/oven-sh/bun/issues/25640, ill try it out and see if it works.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3454