opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Automatically load @ referenced files in AGENTS.md into context

Open tobias-walle opened this issue 4 months ago • 7 comments

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.

tobias-walle avatar Aug 24 '25 17:08 tobias-walle

I tend to agree, especially to be consistent

rekram1-node avatar Aug 24 '25 19:08 rekram1-node

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 avatar Sep 21 '25 15:09 mannp

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

rekram1-node avatar Sep 21 '25 15:09 rekram1-node

@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 avatar Sep 21 '25 16:09 mannp

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 avatar Sep 21 '25 17:09 rekram1-node

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 avatar Sep 21 '25 19:09 mannp

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 avatar Dec 01 '25 23:12 mlanza