You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OpenCode crashes when no permissions to read .env in project root #8225
Accepting the fact that one can get around OpenCode's permission settings using CLI commands, I'm running it in a sandbox using Apple's sandbox-exec. (See #2242)
Narrowing down the rules to prevent access to the .env* files by sandbox-exec, I found that a .env file in the project root results in an unexpected error.
For simpler replication, I tried to deny access via file system permissions. Even though cat is not allowed to show the content when executed, OpenCode did not run into the error.
I understand it's quite an edge case, but since it's a sensitive area and hoping handling errors when reading the .env in the project root is simple enough, a fix would be appreciated! Alternatively, a config flag to avoid loading .env files in the project folder would also be great.
Thanks, for this, and the whole OpenCode tool - it's awesome!
Plugins
Standard (opencode-copilot-auth@0.0.11, opencode-anthropic-auth@0.0.8)
OpenCode version
1.1.10
Steps to reproduce
On macOS, set up sandbox-exec ie. by using this config file.
Create an empty folder, and change into that folder
Create a .env file (can be empty)
Start sandboxed OpenCode inside that "project folder" with TMPDIR=/tmp sandbox-exec -f ~/.opencode-sandbox.sb opencode (where ~/.opencode-sandbox.sb is the sandbox config)
The issue should appear immediately
Move the .env into a sub-folder and things should be fine.
This issue appears to be related to .env file permission handling during startup. While there are several existing issues about .env file access (#4969, #5484) and sandboxing (#2242), this specific crash (Worker termination with InvalidStateError) when permission is denied appears to be unique.
The crash occurs specifically when:
A .env file exists in the project root
OpenCode lacks read permissions (e.g., via sandbox-exec)
OpenCode attempts to access this file during initialization
The error should be handled gracefully rather than crashing the Worker process. Consider checking related issues for context:
When I run opencode in the CLI on Windows 11 Ubuntu WSL1, it won't start in an existing project. This is the error I see:
opencode --print-logs
INFO 2026-02-18T04:47:53 +251ms service=default version=1.2.6 args=["--print-logs"] opencode
INFO 2026-02-18T04:47:53 +3ms service=config path=/home/nick/.config/opencode/config.json loading
INFO 2026-02-18T04:47:53 +2ms service=config path=/home/nick/.config/opencode/opencode.json loading
INFO 2026-02-18T04:47:53 +3ms service=config path=/home/nick/.config/opencode/opencode.jsonc loading
ERROR 2026-02-18T04:47:53 +27ms service=default e=Worker has been terminated rejection
ERROR 2026-02-18T04:47:53 +0ms service=default InvalidStateError: Worker has been terminated
The temporary solution I have found thanks to @robbash is to remove the .env file in the project root. When I do this, it starts successfully, but obviously this isn't obvious or practical.
When I run opencode in the CLI on Windows 11 Ubuntu WSL1, it won't start in an existing project. This is the error I see:
opencode --print-logs
INFO 2026-02-18T04:47:53 +251ms service=default version=1.2.6 args=["--print-logs"] opencode
INFO 2026-02-18T04:47:53 +3ms service=config path=/home/nick/.config/opencode/config.json loading
INFO 2026-02-18T04:47:53 +2ms service=config path=/home/nick/.config/opencode/opencode.json loading
INFO 2026-02-18T04:47:53 +3ms service=config path=/home/nick/.config/opencode/opencode.jsonc loading
ERROR 2026-02-18T04:47:53 +27ms service=default e=Worker has been terminated rejection
ERROR 2026-02-18T04:47:53 +0ms service=default InvalidStateError: Worker has been terminated
The temporary solution I have found thanks to @robbash is to remove the .env file in the project root. When I do this, it starts successfully, but obviously this isn't obvious or practical.
Activity
github-actions commentedon Jan 13, 2026
This issue appears to be related to .env file permission handling during startup. While there are several existing issues about .env file access (#4969, #5484) and sandboxing (#2242), this specific crash (Worker termination with InvalidStateError) when permission is denied appears to be unique.
The crash occurs specifically when:
The error should be handled gracefully rather than crashing the Worker process. Consider checking related issues for context:
A fix could include:
nickturrietta commentedon Feb 18, 2026
I'm experiencing a related issue.
When I run opencode in the CLI on Windows 11 Ubuntu WSL1, it won't start in an existing project. This is the error I see:
The temporary solution I have found thanks to @robbash is to remove the .env file in the project root. When I do this, it starts successfully, but obviously this isn't obvious or practical.
nickturrietta commentedon Mar 13, 2026
Solved by upgrading to v1.2.26
github-actions commentedon Jul 6, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.