Skip to content

Exclude files from being used #3164

Closed
Closed

Description

@glennvdv

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

Activity

  1. github-actions commented on Oct 14, 2025

    @github-actions
    Contributor

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

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

  2. OpeOginni commented on Oct 14, 2025

    @OpeOginni
    Contributor

    @glennvdv check out the tip here #3124 (comment)

    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

  3. glennvdv commented on Oct 14, 2025

    @glennvdv
    Author

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

  4. OpeOginni commented on Oct 14, 2025

    @OpeOginni
    Contributor

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

  5. rekram1-node commented on Oct 14, 2025

    @rekram1-node
    Collaborator

    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

  6. self-assigned this
    on Oct 14, 2025
  7. rekram1-node commented on Oct 14, 2025

    @rekram1-node
    Collaborator

    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

  8. pjmartos commented on Dec 2, 2025

    @pjmartos

    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.

  9. rekram1-node commented on Dec 2, 2025

    @rekram1-node
    Collaborator

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

  10. pjmartos commented on Dec 2, 2025

    @pjmartos

    @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.

  11. zhabiba24 commented on Feb 4, 2026

    @zhabiba24

    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!

  12. DavidNorena commented on Feb 4, 2026

    @DavidNorena

    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 ?

  13. rekram1-node commented on Feb 4, 2026

    @rekram1-node
    Collaborator

    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

  14. github-actions commented on Apr 6, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions