[Feature Request] Allow for setting read-only files and directories. #1000

Open
opened 2026-02-16 17:29:03 -05:00 by yindo · 6 comments
Owner

Originally created by @Axenide on GitHub (Jul 30, 2025).

Originally assigned to: @thdxr on GitHub.

Hi, thank you for this awesome project — I’ve never been happier with a coding agent!

I’ve been working on a project where I need to reference other projects, so I keep them in the same directory and often ask things like: “Implement Project A’s feature into the current project.” That generally works well, but sometimes the models start modifying the referenced project instead.

A similar issue happens when working with certain files, like JSON files. If the model can’t get the code to work with a given JSON, it sometimes changes the JSON itself to make it work. Of course, this isn’t opencode’s fault.

That’s why I think it would be great to have a way to define specific files or directories as read-only — so the model can access and understand their contents, but not edit them. This would also be helpful when working with documentation or reference material you want to keep untouched.

Once again, thank you for such an amazing project! :)

Originally created by @Axenide on GitHub (Jul 30, 2025). Originally assigned to: @thdxr on GitHub. Hi, thank you for this awesome project — I’ve never been happier with a coding agent! I’ve been working on a project where I need to reference other projects, so I keep them in the same directory and often ask things like: *“Implement Project A’s feature into the current project.”* That generally works well, but sometimes the models start modifying the referenced project instead. A similar issue happens when working with certain files, like JSON files. If the model can’t get the code to work with a given JSON, it sometimes changes the JSON itself to make it work. Of course, this isn’t opencode’s fault. That’s why I think it would be great to have a way to define specific files or directories as **read-only** — so the model can access and understand their contents, but not edit them. This would also be helpful when working with documentation or reference material you want to keep untouched. Once again, thank you for such an amazing project! :)
Author
Owner

@thdxr commented on GitHub (Aug 4, 2025):

if you hit tab you can switch to plan mode - does this help?

but yeah we should figure this out

@thdxr commented on GitHub (Aug 4, 2025): if you hit tab you can switch to plan mode - does this help?<br><br>but yeah we should figure this out
Author
Owner

@Axenide commented on GitHub (Aug 4, 2025):

Yup, I use plan mode for this kind of things now and works very well, but I think it would be good to have this option. Just to make sure it won't happen even if the model hallucinates a lot.

@Axenide commented on GitHub (Aug 4, 2025): Yup, I use plan mode for this kind of things now and works very well, but I think it would be good to have this option. Just to make sure it won't happen even if the model hallucinates a lot.
Author
Owner

@matleh commented on GitHub (Sep 4, 2025):

I am in a similar position - however I have my reference project at another location, not as a subdirectory of the current project. The reference project is mentioned in the AGENTS.md file. Up until recently, that worked very well, but now opencode can not read the files of the reference project anymore, as it's only allowed to read files in the current directory.

Is there a configuration option to allow read access to other location?
Or maybe I should use a MCP server for this use-case?


I found a solution to my scenario: use a MCP server.
I added opencode.json to my project root with something like this:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "reference": {
      "type": "local",
      "command": ["docker",
        "run",
        "-i",
        "--rm",
        "--mount",
        "type=bind,src=/Users/path/to/some/project1,dst=/reference/project1,ro",
        "--mount",
        "type=bind,src=/some/other/project,dst=/reference/project2,ro",
        "mcp/filesystem",
        "/reference"
      ]
    }
  }
}

and then in AGENTS.md I added instructions to use the reference MCP server to read the source code of related projects.

@matleh commented on GitHub (Sep 4, 2025): I am in a similar position - however I have my reference project at another location, not as a subdirectory of the current project. The reference project is mentioned in the AGENTS.md file. Up until recently, that worked very well, but now opencode can not read the files of the reference project anymore, as it's only allowed to read files in the current directory. Is there a configuration option to allow read access to other location? Or maybe I should use a MCP server for this use-case? --- I found a solution to my scenario: use a MCP server. I added `opencode.json` to my project root with something like this: ```json { "$schema": "https://opencode.ai/config.json", "mcp": { "reference": { "type": "local", "command": ["docker", "run", "-i", "--rm", "--mount", "type=bind,src=/Users/path/to/some/project1,dst=/reference/project1,ro", "--mount", "type=bind,src=/some/other/project,dst=/reference/project2,ro", "mcp/filesystem", "/reference" ] } } } ``` and then in `AGENTS.md` I added instructions to use the *reference* MCP server to read the source code of related projects.
Author
Owner

@taqtiqa-mark commented on GitHub (Sep 28, 2025):

but yeah we should figure this out

I wonder if the idiomatic way to achieve this is by becoming a little more opinionated about the best-practice use case for opencode. Specifically, that OC is used within a rootless container/namespace. Specifically, encapsulate opencode in a rootless container (podman runtime in my case, but others will work too).

Alternatively stated, this is an implementation detail/choice for the IDE? In the following my IDE is Zellij.

Of course this introduces some overhead to tradeoff against the added isolation (I treat the oc shim as a sunk cost since it is a one-off cost that is shared across all projects).

@Axenide use case would then simply involve mounting the folder as RO, rather than RW.

@matleh use case is handled the same way as nested projects:

In a nested scenario /root/ServiceA and /root/ServiceB running in a separate containers (both mounted to /app in their respective containers) with the TUI attached to a common server (http://127.0.0.1:4096).
Ideally they should be able to share sessions with each other across the isolated (container) network.

But right now selfhosted shared sessions appear to be only for enterprise?
https://opencode.ai/docs/share#for-enterprises

For users who adopt this type of pattern (isolated containers), some things become trivial (RO vs RW), nested/monrepos vs isolated/dedicated-repos. However, shared sessions become more important, where they are shared locally.

Thoughts on any other tradeoffs to this adoption pattern.

@taqtiqa-mark commented on GitHub (Sep 28, 2025): > but yeah we should figure this out I wonder if the idiomatic way to achieve this is by becoming a little more opinionated about the best-practice use case for opencode. Specifically, that OC is used within a rootless container/namespace. Specifically, encapsulate opencode in a rootless container (podman runtime in my case, but others will work too). Alternatively stated, this is an implementation detail/choice for the IDE? In the following my IDE is Zellij. Of course this introduces some overhead to tradeoff against the added isolation (I treat the oc shim as a sunk cost since it is a one-off cost that is shared across all projects). @Axenide use case would then simply involve mounting the folder as RO, rather than RW. @matleh use case is handled the same way as nested projects: In a nested scenario /root/ServiceA and /root/ServiceB running in a separate containers (both mounted to /app in their respective containers) with the TUI attached to a common server (http://127.0.0.1:4096). Ideally they should be able to share sessions with each other across the isolated (container) network. But right now selfhosted shared sessions appear to be only for enterprise? https://opencode.ai/docs/share#for-enterprises For users who adopt this type of pattern (isolated containers), some things become trivial (RO vs RW), nested/monrepos vs isolated/dedicated-repos. However, shared sessions become more important, where they are shared locally. Thoughts on any other tradeoffs to this adoption pattern.
Author
Owner

@adilovcode commented on GitHub (Nov 28, 2025):

We are using opencode's UI for our project, I wanna say first of all, THAN YOU guys for this project.
And I think this feature would make the life easy, if we would have ability to pass

permissions.read_only - array of files which should stay untouched.

That would be amazing. What do you guys think ?

@adilovcode commented on GitHub (Nov 28, 2025): We are using opencode's UI for our project, I wanna say first of all, THAN YOU guys for this project. And I think this feature would make the life easy, if we would have ability to pass `permissions.read_only` - array of files which should stay untouched. That would be amazing. What do you guys think ?
Author
Owner

@taqtiqa-mark commented on GitHub (Nov 29, 2025):

@adilovcode, i wonder if the proposal to adopt an Aider style /add won't address some part of your use case. Only files that are /added are within the scope of the LLM.

See: discussion around https://github.com/sst/opencode/issues/1990#issuecomment-3399894873

@taqtiqa-mark commented on GitHub (Nov 29, 2025): @adilovcode, i wonder if the proposal to adopt an Aider style `/add` won't address some part of your use case. Only files that are `/add`ed are within the scope of the LLM. See: discussion around https://github.com/sst/opencode/issues/1990#issuecomment-3399894873
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1000