Unignoring the .gitignore with .ignore should allow reading the file #3112

Open
opened 2026-02-16 17:38:41 -05:00 by yindo · 8 comments
Owner

Originally created by @jcubic on GitHub (Nov 25, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

I'm working on a reproduction of a bug, and created a dummy .env file that was ignored by .gitignore (config from Next.js).

I added the file to .ignore as:

!.env

Now the file is visible in OpenCode. I can select it, but the Agent is not allowed to read that file. I think that it's a bug if I unignore I want the agent to read the file, not only allow to find its name on the file system.

OpenCode version

1.0.110

Operating System

Fedora 43

Terminal

Xfce Terminal (VTE)

Originally created by @jcubic on GitHub (Nov 25, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description I'm working on a reproduction of a bug, and created a dummy `.env` file that was ignored by `.gitignore` (config from Next.js). I added the file to `.ignore` as: ``` !.env ``` Now the file is visible in OpenCode. I can select it, but the Agent is not allowed to read that file. I think that it's a bug if I unignore I want the agent to read the file, not only allow to find its name on the file system. ### OpenCode version 1.0.110 ### Operating System Fedora 43 ### Terminal Xfce Terminal (VTE)
yindo added the opentuibug labels 2026-02-16 17:38:41 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Nov 25, 2025):

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

  • #4694: Files mentioned in .gitignore are not getting ignored

This appears to be related to the same underlying issue where OpenCode doesn't properly respect .gitignore patterns. In #4694, glob tool doesn't honor .gitignore rules (showing .tfvars files even though they're ignored), while in this issue, unignoring a file with ! syntax allows it to be visible but the agent can't read it.

Feel free to ignore if this doesn't address your specific case.

@github-actions[bot] commented on GitHub (Nov 25, 2025): This issue might be a duplicate of existing issues. Please check: - #4694: Files mentioned in .gitignore are not getting ignored This appears to be related to the same underlying issue where OpenCode doesn't properly respect .gitignore patterns. In #4694, glob tool doesn't honor .gitignore rules (showing .tfvars files even though they're ignored), while in this issue, unignoring a file with `!` syntax allows it to be visible but the agent can't read it. Feel free to ignore if this doesn't address your specific case.
Author
Owner

@brechr commented on GitHub (Nov 25, 2025):

afaik .env is kinda hardcoded as ignore pattern for the read tool (with exemption for .env.example) and .gitignore contents aren't considered..
the .ignore appears to be something ripgrep specific (a ripgrep feature) which is used in tools like grep etc. i guess the docs could be more specific here

(pretty amazing to be able to tell opencode to checkout the opencode code and analyze it's own code.. (insert xzibit meme here))

@brechr commented on GitHub (Nov 25, 2025): afaik .env is kinda hardcoded as ignore pattern for the read tool (with exemption for .env.example) and .gitignore contents aren't considered.. the .ignore appears to be something ripgrep specific (a ripgrep feature) which is used in tools like grep etc. i guess the docs could be more specific here (pretty amazing to be able to tell opencode to checkout the opencode code and analyze it's own code.. (insert xzibit meme here))
Author
Owner

@jcubic commented on GitHub (Nov 25, 2025):

Then it should not appear when you type @, it's confusing that you can mention that file, but the Agent can't read it.

Also, this file is only used by JavaScript. IMHO, generic Agent should not ignore random files only by one technology. To remove .env there should be a default config file with list of files that are always ignored and away to change that file.

@jcubic commented on GitHub (Nov 25, 2025): Then it should not appear when you type `@`, it's confusing that you can mention that file, but the Agent can't read it. Also, this file is only used by JavaScript. IMHO, generic Agent should not ignore random files only by one technology. To remove `.env` there should be a default config file with list of files that are always ignored and away to change that file.
Author
Owner

@rekram1-node commented on GitHub (Nov 25, 2025):

Lol thats a good point, ill take a look

@rekram1-node commented on GitHub (Nov 25, 2025): Lol thats a good point, ill take a look
Author
Owner

@rekram1-node commented on GitHub (Nov 25, 2025):

We wanna make it configurable I just blacklisted env for safety but that's a good point

@rekram1-node commented on GitHub (Nov 25, 2025): We wanna make it configurable I just blacklisted env for safety but that's a good point
Author
Owner

@brandtcormorant commented on GitHub (Feb 12, 2026):

I opened a pr that resolves this: #12876

I've made a local build and been testing it for a couple days and it's working great.

@brandtcormorant commented on GitHub (Feb 12, 2026): I opened a pr that resolves this: #12876 I've made a local build and been testing it for a couple days and it's working great.
Author
Owner

@jcubic commented on GitHub (Feb 12, 2026):

I'm not sure if this is needed anymore.

OpenCode now ask you for permission to read .env file.

@rekram1-node For me this can be closed.

@jcubic commented on GitHub (Feb 12, 2026): I'm not sure if this is needed anymore. OpenCode now ask you for permission to read `.env` file. @rekram1-node For me this can be closed.
Author
Owner

@boyter commented on GitHub (Feb 12, 2026):

Just my 2c but id like there to be a .llmignore or such, just in case I wanted to explicitly tell the tool that I don't want something to ever be read, even if its not in .gitignore or .ignore.

.ignore is great for being picked up by most tools such as rg and the like, but sometimes you want to target the specific tool set.

@boyter commented on GitHub (Feb 12, 2026): Just my 2c but id like there to be a `.llmignore` or such, just in case I wanted to explicitly tell the tool that I don't want something to ever be read, even if its not in `.gitignore` or `.ignore`. `.ignore` is great for being picked up by most tools such as `rg` and the like, but sometimes you want to target the specific tool set.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3112