Skip to main content
You can provide custom instructions to opencode by creating an 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 new AGENTS.md file, you can run the /init command in opencode.
You should commit your project’s AGENTS.md file to Git.
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 an AGENTS.md file.
AGENTS.md
We are adding project-specific instructions here and this will be shared across your team.

Types

opencode also supports reading the AGENTS.md file from multiple locations. And this serves different purposes.

Project

Place an AGENTS.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.md in your project directory (used if no AGENTS.md exists)
  • Global rules: ~/.claude/CLAUDE.md (used if no ~/.config/opencode/AGENTS.md exists)
  • Skills: ~/.claude/skills/ — see Agent Skills for details
To disable Claude Code compatibility, set one of these environment variables:

Precedence

When opencode starts, it looks for rule files in this order:
  1. Local files by traversing up from the current directory (AGENTS.md, CLAUDE.md)
  2. Global file at ~/.config/opencode/AGENTS.md
  3. Claude Code file at ~/.claude/CLAUDE.md (unless disabled)
The first matching file wins in each category. For example, if you have both 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 your opencode.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
You can also use remote URLs to load instructions from the web.
opencode.json
Remote instructions are fetched with a 5 second timeout. All instruction files are combined with your AGENTS.md files.

Glob patterns

The instructions field supports glob patterns:
opencode.json
This is especially useful for monorepos where different packages have their own rules.

What to include

Your AGENTS.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 in AGENTS.md, you can achieve similar functionality in two ways:

Using opencode.json

The recommended approach is to use the instructions field in opencode.json:
opencode.json

Manual Instructions in AGENTS.md

You can teach opencode to read external files by providing explicit instructions in your AGENTS.md. Here’s a practical example:
AGENTS.md
This approach allows you to:
  • 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
For monorepos or projects with shared standards, using opencode.json with glob patterns (like packages/*/AGENTS.md) is more maintainable than manual instructions.

Best Practices

Be specific

Provide concrete examples instead of vague guidelines:

Bad

Use good practices

Include rationale

Explain why rules exist:

Document exceptions

Monorepo structure

For monorepos, combine global and package-specific rules: Root AGENTS.md:
opencode.json:
Package-specific packages/api/AGENTS.md:

Version control

Commit AGENTS.md to share with your team:
Include it in PR reviews when project conventions change.

Global Rules

Use ~/.config/opencode/AGENTS.md for personal preferences:
~/.config/opencode/AGENTS.md
Global rules apply to all projects but are overridden by project-specific rules when there’s a conflict.

Migration from Cursor

If you’re migrating from Cursor, OpenCode can read your existing .cursorrules file:
  1. Rename to AGENTS.md (recommended):
  2. Or reference it in opencode.json:
  3. 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.log for normal output
  • Use console.error for 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