Skip to content

.env file in project directory triggers Bun ThreadLock panic on Windows (TUI crash) #15015

Closed

Description

@Sundykin

Description

Description

OpenCode TUI crashes immediately on startup with Bun ThreadLock assertion failure when the project directory contains .env files. Removing all .env* files allows OpenCode to
start normally.

Environment

  • OpenCode: 1.2.11
  • Bun: Canary v1.3.10-canary.100 (6b1d6c76) Windows x64 (baseline)
  • OS: Windows 11 Pro 10.0.26200
  • Terminal: PowerShell

Plugins

No response

OpenCode version

1.2.11

Steps to reproduce

Steps to Reproduce

  1. Create a project directory with git init
  2. Add a .env file with any content, e.g.:
    VITE_PORT = 8848
    VITE_HIDE_HOME = false
  3. Run opencode
  4. Observe crash

Expected Behavior

OpenCode TUI starts normally.

Actual Behavior

Bun panics with ThreadLock assertion failure:

panic(thread 31580): Internal assertion failure: ThreadLock is locked by thread 31104, not thread 31580
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

Debugging Details

Through binary search isolation, I confirmed:

Condition Result
Empty directory (with git) ✅ Works
Project files without .env ✅ Works
Same project files + .env ❌ Crash
Only .env file added ❌ Crash
  • opencode --help and opencode run "hello" work fine — crash is TUI-specific
  • opencode --version returns 1.2.11 correctly
  • Crash occurs after config loading, during TUI initialization
  • The .env content doesn't matter — even a minimal .env triggers the crash
  • Attempted BUN_CONFIG_NO_DOTENV=1 and BUN_ENV_FILE="" — neither prevents the crash (Bun loads .env before processing env vars)

Crash Report URL

https://bun.report/1.3.10/ea26b1d6c7kWugogC+iwgN+xxuK4t2wMuqoNkxvNm9mQwwn0eCYKERNEL32.DLLut0LCSntdll.dll4gijBA0eNrzzCtJLcpLzFFILC5OLSrJzM9TSEvMzCktSrVSSAjJKEpNTPHJT85OUMgsVsjJT85OTV
FIqlQoAUsoGBsaGpjoKOTll8BEjA1NLQwAGbocyQ

Workaround

Temporarily rename .env* files before launching OpenCode:

# PowerShell workaround
$envFiles = Get-ChildItem -Filter ".env*" -File -ErrorAction SilentlyContinue
foreach ($f in $envFiles) { Rename-Item $f.FullName "$($f.FullName).__bak" }
try { opencode @args }
finally { foreach ($f in $envFiles) { $bak = "$($f.FullName).__bak"; if (Test-Path $bak) { Rename-Item $bak $f.FullName } } }

Suggestion

Consider passing --env-file "" to the embedded Bun runtime to disable automatic .env loading, or upgrade to a Bun version that fixes the ThreadLock race condition on Windows.  

### Screenshot and/or share link

_No response_

### Operating System

_No response_

### Terminal

_No response_

Activity

  1. github-actions commented on Feb 25, 2026

    @github-actions
    Contributor

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

  2. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Feb 25, 2026
  3. roymasad commented on Feb 25, 2026

    @roymasad

    Same problem here also, after upgrading opencode tui to 1.2.12 it crashes if i open it in a project with an env file

  4. ricred commented on Feb 25, 2026

    @ricred

    still same error here using opencode tui 1.2.13

  5. ramhaidar commented on Feb 25, 2026

    @ramhaidar

    Opencode TUI 1.2.13 Still Same Error

    Image
    ============================================================
    Bun Canary v1.3.10-canary.100 (6b1d6c76) Windows x64 (baseline)
    Windows v.win11_dt
    CPU: sse42 avx avx2 avx512
    Args: "C:\Users\[Redacted]\scoop\apps\opencode\current\opencode.exe" "--user-agent=opencode/1.2.13" "--use-system-ca" "--"
    Features: Bun.stderr(2) Bun.stdin(2) Bun.stdout(2) fetch(2) jsc standalone_executable tsconfig workers_spawned
    Builtins: "bun:ffi" "bun:main" "bun:sqlite" "node:assert" "node:async_hooks" "node:buffer" "node:child_process" "node:console" "node:crypto" "node:dns" "node:events" "node:fs" "node:fs/promises" "node:http" "node:https" "node:module" "node:net" "node:os" "node:path" "node:process" "node:querystring" "node:readline" "node:stream" "node:stream/consumers" "node:stream/promises" "node:string_decoder" "node:timers" "node:timers/promises" "node:tls" "node:tty" "node:url" "node:util" "undici" "node:v8" "node:http2" "node:diagnostics_channel" "node:dgram"
    Elapsed: 566ms | User: 671ms | Sys: 312ms
    RSS: 0.60GB | Peak: 0.60GB | Commit: 0.95GB | Faults: 151537 | Machine: 33.91GB
    
    panic(thread 23284): Internal assertion failure: `ThreadLock` is locked by thread 36600, not thread 23284
    oh no: Bun has crashed. This indicates a bug in Bun, not your code.
    
    To send a redacted crash report to Bun's team,
    please file a GitHub issue using the link below:
    
     https://bun.report/1.3.10/ea26b1d6c7kSugogC+iwgN+xxuK4t2wM8/pM2rmNkxvNm9mQwwn0eCYKERNEL32.DLLut0LCSntdll.dll45mCA0eNrzzCtJLcpLzFFILC5OLSrJzM9TSEvMzCktSrVSSAjJKEpNTPHJT85OUMgsVsjJT85OTVFIqlQoAUsoGJuZGRjoKOTll8BEjIyNLEwAGkMc0Q
    
  6. abakumov-v commented on Feb 25, 2026

    @abakumov-v

    same error on Windows 11 + I have bun 1.2.15 installed, but looks like opencode uses it's own bun instance taken from node_modules

    just happened today accidentially - probably, after auto-updating to 1.2.14 because in the morning it was 1.2.10 (or 1.2.12) and it worked fine

  7. abakumov-v commented on Feb 25, 2026

    @abakumov-v

    ha, this works fine:

    1/ disable auto updates
    2/ run this:

    opencode upgrade v1.2.10
    

    you even don't need to clean ~/.config/opencode/node_modules

  8. Rahullkumr commented on Feb 25, 2026

    @Rahullkumr

    but @abakumov-v how to disable auto updates?

  9. Tantless commented on Feb 26, 2026

    @Tantless

    @Rahullkumr try add "autoupdate": false in ur ~/.config/opencode/opencode.json

  10. Hona commented on Feb 26, 2026

    @Hona
    Member

    please upgrade to latest OpenCode v1.2.15 - and try again.

    There should be no more segfaults/crashes.

    Can you confirm it works fine after the version is >v1.2.15 :)

  11. ramhaidar commented on Feb 26, 2026

    @ramhaidar

    @Hona confirmed its working now, no more sefgaults/crashes!

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)opentuiThis relates to changes in v1.0, now that opencode uses opentuiwindows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions