OpenCode plugin that makes AGENTS.md/CLAUDE.md loading behave like Claude Code: every
ancestor directory is loaded, and the file closest to you wins.
Say you keep layered instructions — personal rules in your home directory, conventions per projects folder, specifics in each repo:
/Users/
├── AGENTS.md
└── you/
├── AGENTS.md
└── projects/
├── AGENTS.md
└── my-repo/ ← git repo
├── AGENTS.md
└── sub/ ← you run opencode here
└── AGENTS.md
OpenCode loads only this, after your global config file:
my-repo/sub/AGENTS.mdmy-repo/AGENTS.md— highest weight: the repo root beats the directory you are in
Everything above the git repo is silently skipped, and within the repo the precedence is inverted — the outermost file wins. Claude Code does the opposite on both counts.
With the plugin, the same session loads:
/Users/AGENTS.md/Users/you/AGENTS.md/Users/you/projects/AGENTS.mdmy-repo/AGENTS.mdmy-repo/sub/AGENTS.md— highest weight: the closest file wins, like Claude Code
- Injects missing ancestors — walks from the worktree root's parent up to
/, one file per directory,AGENTS.mdpreferred overCLAUDE.md. - Fixes precedence — reorders all instruction blocks outermost-first, with or without a git repo in the hierarchy.
- Stays out of the way — the global config block is untouched, per-prompt custom system text keeps its position, and any failure degrades gracefully instead of breaking the chat request.
Add the plugin to ~/.config/opencode/opencode.json:
{
"plugin": ["opencode-agents-cascade@git+https://github.com/waldoibarra/opencode-agents-cascade.git"]
}Pin to a tag or commit with #v1.0.0 / #<sha> at the end of the spec. Verified against
OpenCode 1.17.
OpenCode installs git-spec plugins once and never re-fetches them. To pick up a new version, pin a different ref, or clear the cached install and start a new session:
rm -rf ~/.cache/opencode/packages/opencode-agents-cascade*The cache lives under $XDG_CACHE_HOME/opencode/packages/ when that variable is set.
Nothing to configure: start OpenCode inside any project and your ancestor instructions are injected on every chat request. To see it working, ask the model:
What "Instructions from:" headers are in your system prompt, in order?