When working in a project that has a .env file, opencode's file search discovers it like any other text file. If the file gets read (manually or by the agent exploring the project), its contents — API keys, database URLs, tokens — end up in the conversation context sent to the model.
.gitignore keeps .env out of version control but has no effect on opencode's file discovery. The built-in ignore list in src/file/ignore.ts filters folders like node_modules and files like *.log, but nothing prevents .env files from being listed, searched, and read.
Steps to reproduce:
- Create a project with a .env containing a secret (e.g. API_KEY=sk-test-1234)
- Open opencode in that directory
- Search for files — .env appears in results
- Read the file or let the agent discover it during exploration
- The secret is now in the conversation context
Expected behavior:
.env and its variants (.env.local, .env.production, etc.) should be excluded from file discovery by default, the same way node_modules and .git are excluded.
Proposed fix:
Add **/.env and **/.env.* to the default ignore patterns in FileIgnore. This covers standard dotenv naming conventions while leaving unrelated files (.envrc, env.ts, environment.yaml) unaffected.
I'd like to submit a PR for this — the change is two patterns in ignore.ts plus tests.
When working in a project that has a .env file, opencode's file search discovers it like any other text file. If the file gets read (manually or by the agent exploring the project), its contents — API keys, database URLs, tokens — end up in the conversation context sent to the model.
.gitignore keeps .env out of version control but has no effect on opencode's file discovery. The built-in ignore list in src/file/ignore.ts filters folders like node_modules and files like *.log, but nothing prevents .env files from being listed, searched, and read.
Steps to reproduce:
Expected behavior:
.env and its variants (.env.local, .env.production, etc.) should be excluded from file discovery by default, the same way node_modules and .git are excluded.
Proposed fix:
Add
**/.envand**/.env.*to the default ignore patterns in FileIgnore. This covers standard dotenv naming conventions while leaving unrelated files (.envrc, env.ts, environment.yaml) unaffected.I'd like to submit a PR for this — the change is two patterns in ignore.ts plus tests.