You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Global AGENTS.md (~/.config/opencode/AGENTS.md) not loaded when project AGENTS.md exists #22020
When both a global ~/.config/opencode/AGENTS.md and a project-level AGENTS.md exist, only the project-level file is loaded. The global rules are silently ignored.
Global: You can also have global rules in a ~/.config/opencode/AGENTS.md file. This gets applied across all opencode sessions.
Precedence: The first matching file wins in each category.
The phrase "in each category" implies that local and global are separate categories that should both load. But in practice, only the project AGENTS.md is loaded.
Steps to Reproduce
Create ~/.config/opencode/AGENTS.md with unique rules (e.g., "Always use rg instead of grep")
Create a project-level AGENTS.md in a git repo with different rules
Start opencode in that project
Ask the agent to recite its instructions — only the project AGENTS.md content is present
Expected Behavior
Both files should be loaded:
Global rules apply to ALL sessions (personal preferences, tool preferences, communication style)
Project rules apply to the specific project (architecture, conventions, build commands)
They serve different purposes and should compose, not override.
Current Workaround
Adding @~/.config/opencode/AGENTS.md to the project AGENTS.md forces loading both, but this:
Requires manual setup in every project
Is not documented as necessary
Defeats the purpose of "global" rules
Environment
OpenCode: latest
OS: Windows 11
Global AGENTS.md at: C:\Users\<user>\.config\opencode\AGENTS.md
I tested exact cases and added a test case. I don't think there is an issue here, if you can show me how you verified (not using llm) it'd be super helpful.
If there were a bug maybe one on windows but unix should all work here.
Read the source code — globalFiles() at line 30 does path.join(Global.Path.config, "AGENTS.md"), and Global.Path.config = path.join(xdgConfig!, "opencode") from global/index.ts line 6.
C:\Users\Sanve\AppData\Roaming\opencode\ exists but contains only runtime data (EBWebView, quotas-debug.log) — no AGENTS.md
C:\Users\Sanve\.config\opencode\AGENTS.md exists with my rules
Confirmed in OpenCode logs — Config loading correctly reads from .config\opencode\ (logs show service=config path=C:\Users\Sanve\.config\opencode\opencode.json loading), meaning the config path resolution has special handling for opencode.json but NOT for AGENTS.md via globalFiles().
Why it works on Unix
On Linux/macOS, xdgConfig resolves to ~/.config/, which matches where users naturally place their config. On Windows, xdgConfig resolves to %APPDATA% instead, creating a mismatch with the ~/.config/opencode/ directory that OpenCode itself creates and uses for other config files.
The Fix
globalFiles() should search additional paths on Windows, or Global.Path.config should be consistent with where OpenCode actually stores its config. Since OpenCode already reads opencode.json from ~/.config/opencode/ on Windows, the AGENTS.md loading should check the same directory.
Both the project AGENTS.md and global AGENTS.md are correctly loaded.
My earlier analysis about xdg-basedir resolving to %APPDATA% on Windows was wrong — I tested with Node.js, but OpenCode runs on Bun where xdgConfig correctly resolves to ~/.config/. This was confirmed by both your screenshot and opencode debug paths on my machine:
config C:\Users\Sanve\.config\opencode
Sorry for the noise. Closing this issue as not a bug.
Are you 100% sure this is not an issue? I just ran into the same thing on Windows.
AGENTS.md in my user folder and AGENTS.md in my project folder (which has no reference to the global user file). Asking about the injected context my global AGENTS.md is totally missing. Until I added this to my global opencode.json config:
"instructions": ["~/.config/opencode/AGENTS.md"],
Now when I ask a model I do get the full context, my full global file and the project file on top. Using just "AGENTS.md" in the config didn't work, it probably pulled in the project file again.
Activity
miguelgmcs commentedon Apr 13, 2026
Same on behavior on Linux Fedora 43
rekram1-node commentedon Apr 13, 2026
Try running opencode through an http proxy and searching for
Instructions from:I think youll find that the llm is just lying to you
rekram1-node commentedon Apr 13, 2026
I tested exact cases and added a test case. I don't think there is an issue here, if you can show me how you verified (not using llm) it'd be super helpful.
If there were a bug maybe one on windows but unix should all work here.
Qiiks commentedon Apr 13, 2026
Verified: Windows-specific bug in
globalFiles()path resolutionI've identified the root cause. As you suspected, this is a Windows-only bug.
The Bug
Global.Path.configinpackages/opencode/src/global/index.tsusesxdg-basedir:On Windows,
xdgConfigresolves to%APPDATA%(C:\Users\<user>\AppData\Roaming), not~/.config/.So
globalFiles()inpackages/opencode/src/session/instruction.ts(line 30) looks for:But my actual AGENTS.md is at:
Non-LLM Verification
Read the source code —
globalFiles()at line 30 doespath.join(Global.Path.config, "AGENTS.md"), andGlobal.Path.config = path.join(xdgConfig!, "opencode")fromglobal/index.tsline 6.Checked xdg-basedir resolution on Windows:
Confirmed filesystem mismatch:
C:\Users\Sanve\AppData\Roaming\opencode\exists but contains only runtime data (EBWebView, quotas-debug.log) — no AGENTS.mdC:\Users\Sanve\.config\opencode\AGENTS.mdexists with my rulesConfirmed in OpenCode logs — Config loading correctly reads from
.config\opencode\(logs showservice=config path=C:\Users\Sanve\.config\opencode\opencode.json loading), meaning the config path resolution has special handling foropencode.jsonbut NOT for AGENTS.md viaglobalFiles().Why it works on Unix
On Linux/macOS,
xdgConfigresolves to~/.config/, which matches where users naturally place their config. On Windows,xdgConfigresolves to%APPDATA%instead, creating a mismatch with the~/.config/opencode/directory that OpenCode itself creates and uses for other config files.The Fix
globalFiles()should search additional paths on Windows, orGlobal.Path.configshould be consistent with where OpenCode actually stores its config. Since OpenCode already readsopencode.jsonfrom~/.config/opencode/on Windows, the AGENTS.md loading should check the same directory.Hona commentedon Apr 13, 2026
Are you using any plugins? Specifically the xdg basedir package we use does as the docs say.
example see a couple tiny repro scripts and the directories that opencode actually uses:
It works on my windows machine with a clean opencode install.
Desktop app or CLI?
Qiiks commentedon Apr 14, 2026
I'm on the CLI but I do have the desktop version installed I'm just not using it
Qiiks commentedon Apr 14, 2026
Correction: Issue is NOT valid — both AGENTS.md files ARE loaded
I installed the
opencode-system-prompt-loggerplugin and ran it from my project directory (F:\ScienceQuest\Science-Quest). The output clearly shows:Both the project AGENTS.md and global AGENTS.md are correctly loaded.
My earlier analysis about
xdg-basedirresolving to%APPDATA%on Windows was wrong — I tested with Node.js, but OpenCode runs on Bun wherexdgConfigcorrectly resolves to~/.config/. This was confirmed by both your screenshot andopencode debug pathson my machine:Sorry for the noise. Closing this issue as not a bug.
Hona commentedon Apr 14, 2026
who would have thought blindly trusting AI and then asking an llm to do 'Non-LLM Verification' would cause issues
Vlyn commentedon May 25, 2026
Are you 100% sure this is not an issue? I just ran into the same thing on Windows.
AGENTS.md in my user folder and AGENTS.md in my project folder (which has no reference to the global user file). Asking about the injected context my global AGENTS.md is totally missing. Until I added this to my global opencode.json config:
"instructions": ["~/.config/opencode/AGENTS.md"],Now when I ask a model I do get the full context, my full global file and the project file on top. Using just "AGENTS.md" in the config didn't work, it probably pulled in the project file again.
feat(task): add dg task context-report (Step 7)