AGENTS.md file. This is similar to Cursor’s rules. It contains instructions that will be included in the LLM’s context to customize its behavior for your specific project.
Initialize
To create a newAGENTS.md file, you can run the /init command in opencode.
This will scan your project and all its contents to understand what the project is about and generate an AGENTS.md file with it. This helps opencode to navigate the project better.
If you have an existing AGENTS.md file, this will try to add to it.
Example
You can also just create this file manually. Here’s an example of some things you can put into anAGENTS.md file.
AGENTS.md
Types
opencode also supports reading theAGENTS.md file from multiple locations. And this serves different purposes.
Project
Place anAGENTS.md in your project root for project-specific rules. These only apply when you are working in this directory or its sub-directories.
Global
You can also have global rules in a~/.config/opencode/AGENTS.md file. This gets applied across all opencode sessions.
Since this isn’t committed to Git or shared with your team, we recommend using this to specify any personal rules that the LLM should follow.
Claude Code Compatibility
For users migrating from Claude Code, OpenCode supports Claude Code’s file conventions as fallbacks:- Project rules:
CLAUDE.mdin your project directory (used if noAGENTS.mdexists) - Global rules:
~/.claude/CLAUDE.md(used if no~/.config/opencode/AGENTS.mdexists) - Skills:
~/.claude/skills/— see Agent Skills for details
Precedence
When opencode starts, it looks for rule files in this order:- Local files by traversing up from the current directory (
AGENTS.md,CLAUDE.md) - Global file at
~/.config/opencode/AGENTS.md - Claude Code file at
~/.claude/CLAUDE.md(unless disabled)
AGENTS.md and CLAUDE.md, only AGENTS.md is used. Similarly, ~/.config/opencode/AGENTS.md takes precedence over ~/.claude/CLAUDE.md.
Custom Instructions
You can specify custom instruction files in youropencode.json or the global ~/.config/opencode/opencode.json. This allows you and your team to reuse existing rules rather than having to duplicate them to AGENTS.md.
Example:
opencode.json
opencode.json
AGENTS.md files.
Glob patterns
Theinstructions field supports glob patterns:
opencode.json
What to include
YourAGENTS.md file should contain information that helps the LLM work effectively with your codebase.
Project overview
Directory structure
Code conventions
Architecture patterns
Database
- Schema definitions in
db/schema.ts - Migrations in
db/migrations/ - Use snake_case for database columns
- Use camelCase in TypeScript
State Management
- Use React Context for global state
- Use URL state for filters/pagination
- Use local state for component-specific data
Deployment info
Common operations
Database migrations
Deployment
External resources
Referencing External Files
While opencode doesn’t automatically parse file references inAGENTS.md, you can achieve similar functionality in two ways:
Using opencode.json
The recommended approach is to use theinstructions field in opencode.json:
opencode.json
Manual Instructions in AGENTS.md
You can teach opencode to read external files by providing explicit instructions in yourAGENTS.md. Here’s a practical example:
AGENTS.md
- Create modular, reusable rule files
- Share rules across projects via symlinks or git submodules
- Keep AGENTS.md concise while referencing detailed guidelines
- Ensure opencode loads files only when needed for the specific task
Best Practices
Be specific
Provide concrete examples instead of vague guidelines:Bad
Use good practicesInclude rationale
Explain why rules exist:Document exceptions
Link to examples
Monorepo structure
For monorepos, combine global and package-specific rules: RootAGENTS.md:
opencode.json:
packages/api/AGENTS.md:
Version control
CommitAGENTS.md to share with your team:
Global Rules
Use~/.config/opencode/AGENTS.md for personal preferences:
~/.config/opencode/AGENTS.md
Migration from Cursor
If you’re migrating from Cursor, OpenCode can read your existing.cursorrules file:
-
Rename to
AGENTS.md(recommended): -
Or reference it in
opencode.json: -
Update formatting (optional):
- Cursor rules are plain text
- AGENTS.md supports markdown formatting
- Add headers, code blocks, lists for clarity
Examples from Real Projects
Next.js SaaS
AGENTS.md
Express API
AGENTS.md
Database
- Queries in
src/db/queries/ - Use transactions for multiple operations
- Always use parameterized queries (Drizzle handles this)
Testing
- Unit tests for utilities
- Integration tests for routes
- Use test database
- Mock external services
Output
- Use
console.logfor normal output - Use
console.errorfor errors - Use chalk for colors:
chalk.green('Success') - Use spinners for long operations
Error Handling
- Catch errors and show user-friendly messages
- Exit with code 1 on error
- Use —verbose flag for debug output
Config
- Read from
~/.config/tool-name/config.json - Support .env files
- Allow config overrides via flags