AGENTS.md is the main instruction file loaded as context in every OpenCode session. It tells the agent how to work in your project.
Run /init in OpenCode to generate one automatically. It analyzes your codebase and creates an AGENTS.md at the project root.
OpenCode looks for these filenames (first match wins per directory):
AGENTS.md(preferred)CLAUDE.md(compatibility)CONTEXT.md(deprecated)
OpenCode walks up from the working directory to the git worktree root. All AGENTS.md files found along the way are loaded.
project/
├── AGENTS.md # Project-wide (always loaded)
├── packages/
│ ├── frontend/
│ │ └── AGENTS.md # Frontend-specific
│ └── backend/
│ └── AGENTS.md # Backend-specific
└── tests/
└── AGENTS.md # Test-specific
Subdirectory AGENTS.md files are also loaded dynamically when the agent reads a file in that directory.
| Location | Description |
|---|---|
~/.config/opencode/AGENTS.md |
Global instructions (all projects) |
The instructions field in opencode.json adds more instruction sources:
{
"instructions": [
"docs/coding-guidelines.md",
"https://example.com/team-rules.md"
]
}There is no enforced schema -- it's free-form Markdown. The /init command generates these sections:
## Build & Test
- Build: `npm run build`
- Lint: `npm run lint`
- Test all: `npm test`
- Test single file: `npm test -- path/to/file.test.ts`
- Test single case: `npm test -- -t "test name"`## Code Style
- Imports: use named imports, no default exports
- Formatting: 2-space indentation, no semicolons
- Types: prefer interfaces over type aliases
- Naming: camelCase for variables, PascalCase for types
- Error handling: use Result types, no try/catch for control flow## Rules
- Never modify generated files in `src/generated/`
- Always run migrations with `npm run db:migrate`
- Use the `Effect.gen` pattern for async operationsPlace instructions as close to the relevant code as possible:
- Root
AGENTS.md-- Project-wide conventions (style, commands, architecture) - Package
AGENTS.md-- Package-specific rules (framework conventions, test patterns) - Directory
AGENTS.md-- Narrow instructions (generated code warnings, special test setup)
- Keep it under ~150 lines per file
- Focus on what an agent needs to know, not what a human developer already knows
- Include the exact command to run a single test (agents use this constantly)
- Use
/initto bootstrap, then manually refine - The
/learncommand can extract learnings from a session into the appropriateAGENTS.md
- init.md -- Generate AGENTS.md with
/init - configuration.md --
instructionsconfig key