Exclude files from being used #2094

Open
opened 2026-02-16 17:34:07 -05:00 by yindo · 12 comments
Owner

Originally created by @glennvdv on GitHub (Oct 14, 2025).

Originally assigned to: @rekram1-node on GitHub.

How can we exclude some files from being read? For example password, secret files? Can we use a regex or something?

Originally created by @glennvdv on GitHub (Oct 14, 2025). Originally assigned to: @rekram1-node on GitHub. How can we exclude some files from being read? For example password, secret files? Can we use a regex or something?
Author
Owner

@github-actions[bot] commented on GitHub (Oct 14, 2025):

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

  • #3056: PII/secrets censor - discusses censoring sensitive data using regex patterns for critical sensitive values
  • #3055: Set readonly and not ignore permissions - mentions using .opencodenotignore or config files to prevent certain files from being sent while still allowing reference

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 14, 2025): This issue might be a duplicate of existing issues. Please check: - #3056: PII/secrets censor - discusses censoring sensitive data using regex patterns for critical sensitive values - #3055: Set readonly and not ignore permissions - mentions using .opencodenotignore or config files to prevent certain files from being sent while still allowing reference Feel free to ignore if none of these address your specific case.
Author
Owner

@OpeOginni commented on GitHub (Oct 14, 2025):

@glennvdv check out the tip here https://github.com/sst/opencode/issues/3124#issuecomment-3397705635

you need to set OPENCODE_EXPERIMENTAL_WATCHER to true and then add this to your opencode.json

{
    "$schema": "https://opencode.ai/config.json",
    "watcher": {
      "ignore": ["<file-to-ignore>"]
    }
  }

@rekram1-node could suggest other ways I might not know about

@OpeOginni commented on GitHub (Oct 14, 2025): @glennvdv check out the tip here https://github.com/sst/opencode/issues/3124#issuecomment-3397705635 you need to set `OPENCODE_EXPERIMENTAL_WATCHER` to `true` and then add this to your `opencode.json` ```json { "$schema": "https://opencode.ai/config.json", "watcher": { "ignore": ["<file-to-ignore>"] } } ``` @rekram1-node could suggest other ways I might not know about
Author
Owner

@glennvdv commented on GitHub (Oct 14, 2025):

claude indeed suggested this, but found no offical documentation for it

@glennvdv commented on GitHub (Oct 14, 2025): claude indeed suggested this, but found no offical documentation for it
Author
Owner

@OpeOginni commented on GitHub (Oct 14, 2025):

yeah the docs might need some update with it added, but then again its just experimental

@OpeOginni commented on GitHub (Oct 14, 2025): yeah the docs might need some update with it added, but then again its just experimental
Author
Owner

@rekram1-node commented on GitHub (Oct 14, 2025):

hm @OpeOginni filewatcher shouldnt be relevant

@glennvdv currently the best way to exclude files is to write a simple plugin!

here is an example:

https://opencode.ai/docs/plugins/#env-protection

you can place it in your project:

.opencode/plugin/file-projection.ts

or you can place it globally:

~/.config/opencode/plugin/file-protection.ts

I recommend making the error it throws a bit “prompty” try to really tell the llm to not try to read the files

@rekram1-node commented on GitHub (Oct 14, 2025): hm @OpeOginni filewatcher shouldnt be relevant @glennvdv currently the best way to exclude files is to write a simple plugin! here is an example: https://opencode.ai/docs/plugins/#env-protection you can place it in your project: .opencode/plugin/file-projection.ts or you can place it globally: ~/.config/opencode/plugin/file-protection.ts I recommend making the error it throws a bit “prompty” try to really tell the llm to not try to read the files
Author
Owner

@rekram1-node commented on GitHub (Oct 14, 2025):

you can use ts or js and the win is you can do fairly complex logic, maybe this is too much work and there should just be a config option but we would prolly address that at some point

@rekram1-node commented on GitHub (Oct 14, 2025): you can use ts or js and the win is you can do fairly complex logic, maybe this is too much work and there should just be a config option but we would prolly address that at some point
Author
Owner

@pjmartos commented on GitHub (Dec 2, 2025):

Hi team,
I've built a plugin to support excluding sensitive content from the agent's reach: https://github.com/pjmartos/opencode-leak-proof
It honours .aiexclude files at various locations as well as project-root .gitignore files (.gitignore files in subfolders are still not supported).

It's still in kind of an experimental phase, but early results are encouraging.

I would greatly appreciate any feedback you may have.
Cheers.

@pjmartos commented on GitHub (Dec 2, 2025): Hi team, I've built a plugin to support excluding sensitive content from the agent's reach: https://github.com/pjmartos/opencode-leak-proof It honours `.aiexclude` files at various locations as well as project-root `.gitignore` files (`.gitignore` files in subfolders are still not supported). It's still in kind of an experimental phase, but early results are encouraging. I would greatly appreciate any feedback you may have. Cheers.
Author
Owner

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

@pjmartos does anyone else respect .aiexclude besides google/gemini out of the box?

@rekram1-node commented on GitHub (Dec 2, 2025): @pjmartos does anyone else respect .aiexclude besides google/gemini out of the box?
Author
Owner

@pjmartos commented on GitHub (Dec 2, 2025):

@rekram1-node I did find some proposals in at least three of the tools in the Agent space to either start honouring that filename when/if sensitive content exclusions are implemented, or to rename the vendor-specific files:

Given the lack of standardization, at the end of the day the file name wherein to store the exclusion patterns would have to be chosen somewhat arbitrarily. The alternatives were either a bit too vendor-specific (.geminiignore, .cursorignore), or move away from the well-known glob syntax (e.g. .claude/settings.json, which is also vendor-specific). I just decided to go with the "lesser of many evils" and go for .aiexclude, in the hope that at least some people would benefit from not having to create yet another file 😅

That being said, any filename proposal (or any other proposal of any kind, for that matter) are more than welcome.
Cheers.

@pjmartos commented on GitHub (Dec 2, 2025): @rekram1-node I did find some proposals in at least three of the tools in the Agent space to either start honouring that filename when/if sensitive content exclusions are implemented, or to rename the vendor-specific files: * https://github.com/orgs/community/discussions/11254#discussioncomment-10461122 * https://github.com/openai/codex/issues/2847#issuecomment-3328748560 * https://forum.cursor.com/t/proposal-aiexclude-an-ide-agnostic-cursorignore/36161 Given the lack of standardization, at the end of the day the file name wherein to store the exclusion patterns would have to be chosen somewhat arbitrarily. The alternatives were either a bit too vendor-specific (`.geminiignore`, `.cursorignore`), or move away from the well-known glob syntax (e.g. `.claude/settings.json`, which is also vendor-specific). I just decided to go with the "lesser of many evils" and go for `.aiexclude`, in the hope that at least some people would benefit from not having to create yet another file 😅 That being said, any filename proposal (or any other proposal of any kind, for that matter) are more than welcome. Cheers.
Author
Owner

@zhabiba24 commented on GitHub (Feb 3, 2026):

I think this could really do with a simple file like .opencodeignore similar to .geminiignore or .claudeignore that means certain stuff just never gets read!

@zhabiba24 commented on GitHub (Feb 3, 2026): I think this could really do with a simple file like `.opencodeignore` similar to `.geminiignore` or `.claudeignore` that means certain stuff just never gets read!
Author
Owner

@DavidNorena commented on GitHub (Feb 3, 2026):

or maybe lets start thinking about a standard, i dont know what if every one just embraces .aiignore so you dont have to deal with it in each cli ?

@DavidNorena commented on GitHub (Feb 3, 2026): or maybe lets start thinking about a standard, i dont know what if every one just embraces .aiignore so you dont have to deal with it in each cli ?
Author
Owner

@rekram1-node commented on GitHub (Feb 4, 2026):

We now have more granular permissions so u can exclude dirs, files, etc.

ex:

  read: {
        "*": "allow",
        "*.env": "ask",
        "*.env.*": "ask",
        "*.env.example": "allow",
      },

u can use "deny" to prevent it from being read all together

@rekram1-node commented on GitHub (Feb 4, 2026): We now have more granular permissions so u can exclude dirs, files, etc. ex: ``` read: { "*": "allow", "*.env": "ask", "*.env.*": "ask", "*.env.example": "allow", }, ``` u can use "deny" to prevent it from being read all together
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2094