OpenCode plugin that automatically injects AGENTS.md files from nested folders when an agent reads files.
OpenCode automatically loads the root AGENTS.md file to give the AI context about your project. But what about folder-specific instructions?
Large codebases often have different conventions, patterns, or rules for different parts of the project:
- 📁
src/api/- REST endpoint conventions, authentication patterns - 📁
src/components/- React component guidelines, styling rules - 📁
src/database/- Migration patterns, naming conventions - 📁
tests/- Testing standards, mocking strategies
Without this plugin, you'd need to either:
- Cram everything into the root
AGENTS.md(becomes unwieldy) - Manually tell the agent to read folder-specific docs (easy to forget and agents get confused)
This plugin solves that by automatically injecting relevant AGENTS.md files when the agent reads files in those directories similar to .cursorrules.
- 🎯 Automatic injection - No manual intervention needed
- 🚫 No duplicates - Each
AGENTS.mdis injected only once per session - ⚡ Smart skipping - Ignores root
AGENTS.md(OpenCode handles it) - 📂 Hierarchical - Injects all parent
AGENTS.mdfiles up to (but not including) root
Add to your opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@qforge/opencode-agents-explorer"]
}When an agent reads a file at path a/b/c.json, the plugin:
- Searches for
a/AGENTS.mdanda/b/AGENTS.md - If any exist, reads their contents and injects them into the session context
- Skips the root
AGENTS.md(OpenCode already handles it automatically) - Tracks which
AGENTS.mdfiles have been added to avoid duplicates within a session
Given this file structure:
project/
AGENTS.md # ⏭️ Skipped (handled by OpenCode)
src/
AGENTS.md # ✅ Injected when reading files in src/
components/
AGENTS.md # ✅ Injected when reading files in src/components/
Button.tsx
When the agent reads src/components/Button.tsx, the plugin will inject:
src/AGENTS.mdsrc/components/AGENTS.md
monorepo/
AGENTS.md # General project context
packages/
api/
AGENTS.md # "Use Express patterns, validate with Zod"
src/
routes/
AGENTS.md # "All routes must have auth middleware"
web/
AGENTS.md # "Use Next.js App Router, Tailwind CSS"
src/
components/
AGENTS.md # "Components must be server-first"
Now when the agent works on packages/api/src/routes/users.ts, it automatically gets context about:
- Express patterns and Zod validation (
packages/api/AGENTS.md) - Auth middleware requirements (
packages/api/src/routes/AGENTS.md)
MIT