Automatically load @ referenced files in AGENTS.md into context #1472

Open
opened 2026-02-16 17:31:08 -05:00 by yindo · 10 comments
Owner

Originally created by @tobias-walle on GitHub (Aug 24, 2025).

Originally assigned to: @thdxr on GitHub.

First of all, thank you for this great project. I really enjoy using it, and it is amazing how fast you improve it!

Claude Code has the very nice feature that you can reference other files using @ in your CLAUDE.md, and it is automatically loaded into the session. This is very helpful to split rules into multiple files or to directly load core files (like the package.json) in every session. With this feature, a minimal instruction file can then look like this:

# Instructions

-  Avoid excessive comments.
-  Prefer a functional approach over classes.
-  Create reusable functions to keep the code clean and readable.

## Relevant Files

-  @./README.md
-  @./package.json
-  @./tsconfig.json
-  @./docs/bun.md

Unfortunately, OpenCode currently doesn't have the same behaviour with AGENTS.md.

It would be great if this could be added and would increase the consistency with the newly added commands feature.

I could also help with a contribution if that would support you.

Originally created by @tobias-walle on GitHub (Aug 24, 2025). Originally assigned to: @thdxr on GitHub. First of all, thank you for this great project. I really enjoy using it, and it is amazing how fast you improve it! Claude Code has the very nice feature that you can reference other files using `@` in your `CLAUDE.md`, and it is automatically loaded into the session. This is very helpful to split rules into multiple files or to directly load core files (like the `package.json`) in every session. With this feature, a minimal instruction file can then look like this: ```md # Instructions - Avoid excessive comments. - Prefer a functional approach over classes. - Create reusable functions to keep the code clean and readable. ## Relevant Files - @./README.md - @./package.json - @./tsconfig.json - @./docs/bun.md ``` Unfortunately, OpenCode currently doesn't have the same behaviour with `AGENTS.md`. It would be great if this could be added and would increase the consistency with [the newly added commands feature](https://opencode.ai/docs/commands/#reference-files). I could also help with a contribution if that would support you.
Author
Owner

@rekram1-node commented on GitHub (Aug 24, 2025):

I tend to agree, especially to be consistent

@rekram1-node commented on GitHub (Aug 24, 2025): I tend to agree, especially to be consistent
Author
Owner

@mannp commented on GitHub (Sep 21, 2025):

First of all, thank you for this great project. I really enjoy using it, and it is amazing how fast you improve it!

I agree, thanks to the devs 👍🏻

I am struggling to get AGENTS.md loaded into content for the project at all, never mind the referenced files.

Is just autoloading AGENTS.md already supported?

@mannp commented on GitHub (Sep 21, 2025): > First of all, thank you for this great project. I really enjoy using it, and it is amazing how fast you improve it! I agree, thanks to the devs 👍🏻 I am struggling to get AGENTS.md loaded into content for the project at all, never mind the referenced files. Is just autoloading AGENTS.md already supported?
Author
Owner

@rekram1-node commented on GitHub (Sep 21, 2025):

@mannp AGENTS.md is automatically loaded. Where is the file located?, where are you running opencode?

@rekram1-node commented on GitHub (Sep 21, 2025): @mannp AGENTS.md is automatically loaded. Where is the file located?, where are you running opencode?
Author
Owner

@mannp commented on GitHub (Sep 21, 2025):

@mannp AGENTS.md is automatically loaded. Where is the file located?, where are you running opencode?

Hi @rekram1-node it is the root of my project folder where I run opencode. These are the first lines of the file;

---
trigger: always_on
---

# 🤖 Agents Configuration - NixOS Configuration Project

## Overview

This document outlines the AI agents used in this comprehensive NixOS
configuration flake with custom packages, modules, and development tools. All
agents must adhere to the development rules and guidelines specified below.

## 📚 Reference Documentation

- **[README Generator Guide](./docs/guides/readme-generator.md)** - Professional
  README.md generation using Best-README-Template structure  
.......

I have been using Grok Code Fast 1 model.

opencode -v
0.10.4


Edited: removed comments on original op request as they seemed to be confusing to others.
@mannp commented on GitHub (Sep 21, 2025): > [@mannp](https://github.com/mannp) AGENTS.md is automatically loaded. Where is the file located?, where are you running opencode? Hi @rekram1-node it is the root of my project folder where I run opencode. These are the first lines of the file; ``` --- trigger: always_on --- # 🤖 Agents Configuration - NixOS Configuration Project ## Overview This document outlines the AI agents used in this comprehensive NixOS configuration flake with custom packages, modules, and development tools. All agents must adhere to the development rules and guidelines specified below. ## 📚 Reference Documentation - **[README Generator Guide](./docs/guides/readme-generator.md)** - Professional README.md generation using Best-README-Template structure ....... ``` `I have been using Grok Code Fast 1 model.` > opencode -v 0.10.4 ``` Edited: removed comments on original op request as they seemed to be confusing to others.
Author
Owner

@rekram1-node commented on GitHub (Sep 21, 2025):

I have tried loading roles using mods

Not really sure what this means

Edit: mmh this seems it might be a claude thing, maybe 'command' is the opencode option here.

Not really following here either...

Are you asking about AGENTS.md? Or slash commands?

@rekram1-node commented on GitHub (Sep 21, 2025): > I have tried loading roles using mods Not really sure what this means > Edit: mmh this seems it might be a claude thing, maybe 'command' is the opencode option here. Not really following here either... Are you asking about AGENTS.md? Or slash commands?
Author
Owner

@mannp commented on GitHub (Sep 21, 2025):

Are you asking about AGENTS.md? Or slash commands?

I am asking for the ops request and merely commented that my AGENTS.md isn't loaded on startup.

@mannp commented on GitHub (Sep 21, 2025): > Are you asking about AGENTS.md? Or slash commands? I am asking for the ops request and merely commented that my AGENTS.md isn't loaded on startup.
Author
Owner

@mlanza commented on GitHub (Dec 1, 2025):

Hi team! I wanted to share some observations about how AGENTS.md and instruction files are being loaded that might help inform this feature request.

I've noticed that while both project and global AGENTS.md files are definitely being read (I can see evidence of their content influencing responses), there seems to be inconsistent behavior with files specified in the instructions property of opencode.json.

My understanding is that these files are likely provided to the model in some kind of initial brief, but whether the model actually chooses to read their content appears to be left up to its discretion. This creates some uncertainty about what context is actually available.

I've been experimenting with progressive disclosure - I don't want everything eager-loaded, but I do need a guaranteed minimum amount of context for consistent operations. I've spent several hours trying to tweak configurations to get reliable loading, and while I can always coax the model into reading the intended files, I don't understand why this coaxing is necessary.

What I'm hoping for is a way to force-feed certain essential rules files into the start of every new session, ensuring a baseline level of context is always available. The @ referencing approach directly in AGENTS.md files could work beautifully for this.

Thank you for all your hard work on this project - it's improving at an amazing clip!

@mlanza commented on GitHub (Dec 1, 2025): Hi team! I wanted to share some observations about how AGENTS.md and instruction files are being loaded that might help inform this feature request. I've noticed that while both project and global AGENTS.md files are definitely being read (I can see evidence of their content influencing responses), there seems to be inconsistent behavior with files specified in the instructions property of opencode.json. My understanding is that these files are likely provided to the model in some kind of initial brief, but whether the model actually chooses to read their content appears to be left up to its discretion. This creates some uncertainty about what context is actually available. I've been experimenting with progressive disclosure - I don't want everything eager-loaded, but I do need a guaranteed minimum amount of context for consistent operations. I've spent several hours trying to tweak configurations to get reliable loading, and while I can always coax the model into reading the intended files, I don't understand why this coaxing is necessary. What I'm hoping for is a way to force-feed certain essential rules files into the start of every new session, ensuring a baseline level of context is always available. The @ referencing approach directly in AGENTS.md files could work beautifully for this. Thank you for all your hard work on this project - it's improving at an amazing clip!
Author
Owner

@phall1 commented on GitHub (Jan 10, 2026):

What would be great is if there was a slash command that just showed you what instruction filed were loaded

@phall1 commented on GitHub (Jan 10, 2026): What would be great is if there was a slash command that just showed you what instruction filed were loaded
Author
Owner

@gavar commented on GitHub (Jan 20, 2026):

loading reference files with @ syntax is much needed, the only thing I see is that the IDE does not recognize these as paths and may not refactor correctly if the file is moved. If we can use .md links with spectial prefix like [@filename](./path/to/file)] that would be much better for bigger projects IMO

@gavar commented on GitHub (Jan 20, 2026): loading reference files with `@` syntax is much needed, the only thing I see is that the IDE does not recognize these as paths and may not refactor correctly if the file is moved. If we can use .md links with spectial prefix like `[@filename](./path/to/file)] ` that would be much better for bigger projects IMO
Author
Owner

@duckytan commented on GitHub (Feb 13, 2026):

补充一个实际使用场景:子项目规则继承

我有这样一个需求:

场景

  • 父项目:my-workspace(包含完整的 AGENTS.md 规则)
  • 子项目:my-workspace/projects/learning-agent(学习项目的专属规则)

当前问题
在子项目创建 CLAUDE.md 时,只能手动复制父项目的规则。如果父项目规则更新,子项目无法自动同步,导致规则不一致。

期望的解决方案
在子项目的 CLAUDE.md 中能够引用父项目的规则文件,例如:

# 子项目规则
@../AGENTS.md  <!-- 引用父项目规则 -->

## 子项目专属规则
...

这样父项目规则更新时,子项目自动生效,无需手动同步。

这个需求与 Issue #6316(目录自动发现)也高度相关,希望能够优先实现层级规则继承机制。

@duckytan commented on GitHub (Feb 13, 2026): ## 补充一个实际使用场景:子项目规则继承 我有这样一个需求: **场景**: - 父项目:`my-workspace`(包含完整的 AGENTS.md 规则) - 子项目:`my-workspace/projects/learning-agent`(学习项目的专属规则) **当前问题**: 在子项目创建 CLAUDE.md 时,只能手动复制父项目的规则。如果父项目规则更新,子项目无法自动同步,导致规则不一致。 **期望的解决方案**: 在子项目的 CLAUDE.md 中能够引用父项目的规则文件,例如: ```markdown # 子项目规则 @../AGENTS.md <!-- 引用父项目规则 --> ## 子项目专属规则 ... ``` 这样父项目规则更新时,子项目自动生效,无需手动同步。 **这个需求与 Issue #6316(目录自动发现)也高度相关**,希望能够优先实现层级规则继承机制。
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1472