# How to teach opencode your knowledge

Create an `AGENTS.md` file for [project instructions](https://www.knowman.io/guides/opencode-memory), or use `~/.config/opencode/AGENTS.md` for personal rules across sessions ([OpenCode rules](https://docs.opencode.ai/docs/rules/)). KnowMan's MCP server can search [saved items](https://www.knowman.io/guides/how-to-save-articles) and save URLs, but its documented setup covers Claude Desktop, Claude Code, and Cursor, not OpenCode ([KnowMan MCP guide](https://www.knowman.io/guides/mcp-server-knowledge-base)).

## Add project instructions with AGENTS.md

Create `AGENTS.md` in your project root to give OpenCode instructions for that project and its subdirectories. These instructions enter the model context and customize its behavior ([OpenCode rules](https://docs.opencode.ai/docs/rules/)).

You can create the file yourself or run `/init`. OpenCode says `/init` scans important repository files, may ask targeted questions, and creates or updates concise project guidance. If the file already exists, it improves it in place. OpenCode recommends committing a project `AGENTS.md` to Git ([OpenCode rules](https://docs.opencode.ai/docs/rules/)).

## Keep personal rules separate

For rules that should apply across your OpenCode sessions and stay personal, use `~/.config/opencode/AGENTS.md`. OpenCode recommends this location because it is not committed to Git or shared with the team ([OpenCode rules](https://docs.opencode.ai/docs/rules/)).

OpenCode searches local rule files upward from the current directory, then checks its global file and Claude Code files in the documented order. Within each category, the first matching file wins. If both `AGENTS.md` and `CLAUDE.md` are present, `AGENTS.md` takes precedence ([OpenCode rules](https://docs.opencode.ai/docs/rules/)).

## Load reusable reference files

OpenCode does not automatically parse file references inside `AGENTS.md`. The recommended way to load external reference files is the `instructions` field in `opencode.json` or the global `~/.config/opencode/opencode.json` ([OpenCode rules](https://docs.opencode.ai/docs/rules/)).

That field can list local files and glob patterns, such as `docs/development-standards.md` or `packages/*/AGENTS.md`. OpenCode combines configured instruction files with `AGENTS.md` files. It can also load instructions from remote URLs, with a five-second fetch timeout ([OpenCode rules](https://docs.opencode.ai/docs/rules/)).

## Use AGENTS.md for task-based references

Alternatively, write explicit instructions in `AGENTS.md` telling OpenCode to read referenced files with its Read tool. OpenCode documents a lazy approach: load references when relevant to the task, treat loaded content as mandatory instructions, and follow references recursively when needed ([OpenCode rules](https://docs.opencode.ai/docs/rules/)).

This keeps the main [instruction file](https://www.knowman.io/guides/give-your-ai-context) concise while detailed rules load only when needed. For monorepos or shared standards, OpenCode says `opencode.json` glob patterns can be more maintainable ([OpenCode rules](https://docs.opencode.ai/docs/rules/)).

## Where KnowMan fits

KnowMan saves articles and links, reads and tags them, [answers questions with citations](https://www.knowman.io/guides/knowledge-base-for-ai-agents), and [keeps memories](https://www.knowman.io/guides/ai-agent-memory) such as claims, decisions, and playbooks. Its MCP server is a local [stdio server](https://www.knowman.io/guides/what-is-an-mcp-server), and the documented client configurations cover Claude Desktop, Claude Code, and Cursor. [OpenCode setup](https://www.knowman.io/integrations/opencode) and the behavior of its `kb_search`, `kb_get_item`, `kb_ask`, and `kb_save` tools are not documented.

See [the KnowMan MCP server guide](https://www.knowman.io/guides/mcp-server-knowledge-base) for its documented setup, or [learn how to give your AI context](https://www.knowman.io/guides/give-your-ai-context).

## Questions

### How do I create project instructions for OpenCode?

Create an `AGENTS.md` file in the project root, or run `/init` to create or update one. The file gives OpenCode project-specific instructions ([OpenCode rules](https://docs.opencode.ai/docs/rules/)).

### Where should I put personal OpenCode rules?

Use `~/.config/opencode/AGENTS.md` for personal rules across OpenCode sessions. OpenCode recommends it because the file is not committed to Git or shared with the team ([OpenCode rules](https://docs.opencode.ai/docs/rules/)).

### How can OpenCode load detailed reference files?

List files or glob patterns in the `instructions` field of `opencode.json`, or add explicit instructions in `AGENTS.md` to read references when needed. OpenCode combines configured instruction files with `AGENTS.md` files ([OpenCode rules](https://docs.opencode.ai/docs/rules/)).

### Can I connect KnowMan to OpenCode?

KnowMan's MCP server is local stdio, but its documented client configurations do not include OpenCode. OpenCode connection steps and tool behavior are not documented.

## Related guides

- [Connect your knowledge base through KnowMan's MCP server](https://www.knowman.io/guides/mcp-server-knowledge-base)

- [How to Give Your AI Context from What You Read](https://www.knowman.io/guides/give-your-ai-context)

- [What Is a Knowledge Base for AI Agents?](https://www.knowman.io/guides/knowledge-base-for-ai-agents)

- [Give Claude Code a knowledge base built from your reading](https://www.knowman.io/guides/claude-code-knowledge-base)

## More in this topic

- [How to teach VS Code your knowledge](https://www.knowman.io/guides/teach-vscode-your-knowledge)
- [How to teach Qwen Code your knowledge](https://www.knowman.io/guides/teach-qwen-code-your-knowledge)
- [How to teach Roo Code your knowledge](https://www.knowman.io/guides/teach-roo-code-your-knowledge)

## More for opencode

- [KnowMan MCP server for OpenCode](https://www.knowman.io/integrations/opencode)
- [How to give opencode context with AGENTS.md](https://www.knowman.io/guides/opencode-memory)

## Keep your knowledge close

Try KnowMan Pro for 14 days with no credit card. [Create your account](https://app.knowman.io/signup)

[Start free](https://app.knowman.io/signup)

Every new account starts with 14 days of Pro. No credit card.

Source: https://www.knowman.io/guides/teach-opencode-your-knowledge
