opencode reads agents.md from parent directories #4013

Open
opened 2026-02-16 17:42:17 -05:00 by yindo · 5 comments
Owner

Originally created by @eislambey on GitHub (Dec 30, 2025).

Originally assigned to: @thdxr on GitHub.

Description

When launching opencode in a directory, it searches for and reads an agents.md file located two levels up in the directory hierarchy.

OpenCode version

1.0.208

Steps to reproduce

  1. Go to a project directory, e.g., ~/Projects/my-cool-project
  2. Ensure there is no agents.md file in this directory
  3. Place an agents.md file in ~/
  4. Run opencode from ~/Projects/my-cool-project
  5. Observe that opencode reads the configuration/content from ~/agents.md

Screenshot and/or share link

https://opncd.ai/share/aMV0hXIo

Operating System

Fedora 43

Terminal

Gnome Terminal

Note: No .git folders exist in both directories.

Originally created by @eislambey on GitHub (Dec 30, 2025). Originally assigned to: @thdxr on GitHub. ### Description When launching opencode in a directory, it searches for and reads an agents.md file located two levels up in the directory hierarchy. ### OpenCode version 1.0.208 ### Steps to reproduce 1. Go to a project directory, e.g., ~/Projects/my-cool-project 2. Ensure there is no agents.md file in this directory 3. Place an agents.md file in ~/ 4. Run opencode from ~/Projects/my-cool-project 5. Observe that opencode reads the configuration/content from ~/agents.md ### Screenshot and/or share link https://opncd.ai/share/aMV0hXIo ### Operating System Fedora 43 ### Terminal Gnome Terminal **Note:** No .git folders exist in both directories.
Author
Owner

@github-actions[bot] commented on GitHub (Dec 30, 2025):

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

  • #4479: Configurable instruction file search boundary and file types - discusses the same issue with AGENTS.md being found in parent directories
  • #6316: Context Auto-Discovery: Load AGENTS.md from Directories - related feature request about AGENTS.md search behavior in monorepos

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

@github-actions[bot] commented on GitHub (Dec 30, 2025): This issue might be a duplicate of existing issues. Please check: - #4479: Configurable instruction file search boundary and file types - discusses the same issue with AGENTS.md being found in parent directories - #6316: Context Auto-Discovery: Load AGENTS.md from Directories - related feature request about AGENTS.md search behavior in monorepos Feel free to ignore if none of these address your specific case.
Author
Owner

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

This is actually intentional behavior, why would u have an AGENTS.md that doesnt apply to children?

@rekram1-node commented on GitHub (Dec 30, 2025): This is actually intentional behavior, why would u have an AGENTS.md that doesnt apply to children?
Author
Owner

@eislambey commented on GitHub (Dec 31, 2025):

Reading agents.md from my home directory doesn't feel like the correct behavior. Since it's my home directory, I can put anything there.

@eislambey commented on GitHub (Dec 31, 2025): Reading agents.md from my home directory doesn't feel like the correct behavior. Since it's my home directory, I can put anything there.
Author
Owner

@m10rten commented on GitHub (Jan 5, 2026):

Question @eislambey, would this config fix it for you?

"permission": {
  "external_directory": "deny"
},

If so I'd consider that a workaround for your expected behaviour.

Can be debated weither an OC opened in /users/my-user/my-project should use the /users/AGENTS.md and /users/my-user/AGENTS.md files as this can cause strange behaviour as not clearly stated in documentation (see: https://opencode.ai/docs/rules/).

@m10rten commented on GitHub (Jan 5, 2026): Question @eislambey, would this config fix it for you? ```json "permission": { "external_directory": "deny" }, ``` If so I'd consider that a workaround for your expected behaviour. Can be debated weither an OC opened in `/users/my-user/my-project` should use the `/users/AGENTS.md` and `/users/my-user/AGENTS.md` files as this can cause strange behaviour as not clearly stated in documentation (see: https://opencode.ai/docs/rules/).
Author
Owner

@eislambey commented on GitHub (Jan 6, 2026):

@m10rten

tried it. still same

@eislambey commented on GitHub (Jan 6, 2026): @m10rten tried it. still same
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4013