# How to give opencode context with AGENTS.md

opencode does not document a memory of past sessions; what it documents is rules files, whose instructions are included in the LLM's context ([opencode docs](https://docs.opencode.ai/docs/rules/)). AGENTS.md is the main file, /init can create it, and a global copy at ~/.config/opencode/AGENTS.md applies across all sessions ([opencode docs](https://docs.opencode.ai/docs/rules/)). For [saved articles](https://www.knowman.io/guides/how-to-save-articles), citations and memories held outside the editor, KnowMan offers a personal library with an [MCP server](https://www.knowman.io/guides/mcp-server-knowledge-base) documented for Claude Desktop, Claude Code and Cursor (KnowMan).

## What AGENTS.md does in opencode

opencode takes [custom instructions](https://www.knowman.io/guides/give-your-ai-context) from an AGENTS.md file, which its documentation compares to [Cursor's rules](https://docs.opencode.ai/docs/rules/). The file contains instructions that are included in the LLM's context to customize its behavior for your specific project ([opencode docs](https://docs.opencode.ai/docs/rules/)). A [global rules](https://www.knowman.io/guides/knowledge-base-for-ai-agents) file at ~/.config/opencode/AGENTS.md is applied across all opencode sessions, so the same instructions follow you into every project ([opencode docs](https://docs.opencode.ai/docs/rules/)). The documentation describes instructions included in the model's context, not persistent recall of past sessions.

## Create AGENTS.md with /init

To create a new AGENTS.md, run the /init command inside opencode. It scans the important files in your repo, may ask a couple of targeted questions when the codebase cannot answer them, then writes concise project-specific guidance aimed at future sessions. It focuses on what those sessions are most likely to need: build, lint and test commands, plus project conventions, setup quirks, operational gotchas, and references to existing instruction sources like Cursor or Copilot rules. If an AGENTS.md already exists, /init improves it in place instead of blindly replacing it. ([opencode docs](https://docs.opencode.ai/docs/rules/))

## Project rules, global rules, and CLAUDE.md fallbacks

An AGENTS.md in your project root applies when you work in that directory or its sub-directories. Global rules live at ~/.config/opencode/AGENTS.md and apply across all opencode sessions; since this file is not committed to Git, the docs recommend it for personal rules the LLM should follow. You should commit your project's AGENTS.md to Git. On startup, opencode looks for local files by traversing up from the current directory, then the global file, then Claude Code files: project CLAUDE.md is used if no AGENTS.md exists, and ~/.claude/CLAUDE.md is used if no global AGENTS.md exists. The first matching file wins per category, so with both AGENTS.md and CLAUDE.md present, only AGENTS.md is used. ([opencode docs](https://docs.opencode.ai/docs/rules/))

## Reference other files, and the limits you hit

opencode does not automatically parse file references inside AGENTS.md. The recommended workaround is the instructions field in opencode.json or the global ~/.config/opencode/opencode.json, which supports glob patterns and lets you reuse existing rules instead of duplicating them into AGENTS.md. The field also accepts remote URLs, fetched with a 5 second timeout, and all instruction files are combined with your AGENTS.md files. The alternative is a line in AGENTS.md telling the agent to load referenced files with its Read tool on demand. Claude Code compatibility can be disabled with environment variables such as OPENCODE_DISABLE_CLAUDE_CODE. ([opencode docs](https://docs.opencode.ai/docs/rules/))

## The KnowMan MCP server, separately

Rules files hold what you write in them. KnowMan is a separate tool for the rest: it saves articles and links, reads and tags them, answers questions with citations, and keeps memories of claims, decisions and playbooks ([KnowMan](https://www.knowman.io/guides/ai-knowledge-base)). Its MCP server is available as package @knowman/mcp, started locally with `npx -y @knowman/mcp` on Node 22 or newer (MCP setup), or as a hosted remote server at https://api.knowman.io/mcp. The [local server](https://www.knowman.io/guides/what-is-an-mcp-server) talks to KnowMan's HTTP API with a Bearer key in the environment variable KNOWMAN_API_KEY, created at Settings > Connections > Connect an AI agent, or by running `npx -p @knowman/mcp knowman login` once (MCP setup). The hosted server supports OAuth sign-in on the KnowMan consent page or an API key sent as an `Authorization: Bearer <key>` header.

## The tools the server exposes

The server exposes six tools. kb_memories returns your saved claims, decisions and playbooks. kb_ask answers questions with citations drawn from your library. kb_search finds saved items by keyword or meaning, returning titles, URLs and metadata. kb_get_item, kb_save and kb_recent handle the readable content of one item, saving a URL to Inbox or Knowledge Base with an optional note, and listing [recent items](https://www.knowman.io/guides/personal-knowledge-base) (MCP tools).

## Where KnowMan fits

AGENTS.md and the instructions field are the right place for rules you can write in advance: build and test commands, conventions, quirks. You maintain them yourself, by editing the file or re-running /init ([opencode docs](https://docs.opencode.ai/docs/rules/)). KnowMan fits the other half, the material you cannot pre-write: articles you read, decisions you made, playbooks you settled on ([second brain for AI](https://www.knowman.io/guides/second-brain-for-ai)). KnowMan's documented MCP client configs cover [Claude Desktop](https://www.knowman.io/guides/claude-knowledge-base), [Claude Code](https://www.knowman.io/guides/claude-code-knowledge-base) and Cursor, so start there if you use one of those clients.

## Use the hosted KnowMan server

For opencode clients that support remote MCP servers, add https://api.knowman.io/mcp, then sign in through the KnowMan consent page and approve access. OAuth tokens last one hour and refresh automatically.

You can also create an API key in KnowMan settings and send it as an `Authorization: Bearer <key>` header. The hosted server provides kb_search, kb_ask, kb_get_item, kb_save, kb_recent, and kb_memories. The open-source local client is available at https://github.com/Essatt/knowman-mcp.

## Questions

### Does opencode remember past sessions?

What opencode documents is rules files: AGENTS.md contents are included in the LLM's context, and a global file applies across all sessions ([opencode docs](https://docs.opencode.ai/docs/rules/)). The docs describe instructions included in the model's context, not persistent recall of past sessions. For [saved reading](https://www.knowman.io/guides/ai-article-saver) and decisions, KnowMan's kb_memories tool returns claims, decisions and playbooks (KnowMan).

### Where do opencode global rules live?

At ~/.config/opencode/AGENTS.md. It applies across all opencode sessions and is not committed to Git, so the docs recommend it for personal rules ([opencode docs](https://docs.opencode.ai/docs/rules/)). Project-specific rules go in AGENTS.md at the project root, and you should commit that file to Git ([opencode docs](https://docs.opencode.ai/docs/rules/)).

### Does opencode read CLAUDE.md?

Yes, as a fallback. Project CLAUDE.md is used if no AGENTS.md exists, and ~/.claude/CLAUDE.md is used if no global AGENTS.md exists ([opencode docs](https://docs.opencode.ai/docs/rules/)). When both AGENTS.md and CLAUDE.md are present, only AGENTS.md is used.

### Can AGENTS.md reference other files?

Not automatically; opencode does not parse file references inside AGENTS.md ([opencode docs](https://docs.opencode.ai/docs/rules/)). Use the instructions field in opencode.json, which supports glob patterns and remote URLs fetched with a 5 second timeout, or tell the agent to load files with its Read tool on demand ([opencode docs](https://docs.opencode.ai/docs/rules/)).

## Related guides

- [How Do You Connect AI to Your Notes?](https://www.knowman.io/guides/connect-any-ai-to-your-notes)

- [How to Build a Claude Knowledge Base](https://www.knowman.io/guides/claude-knowledge-base)

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

- [Understand AI knowledge bases through the sources behind an answer](https://www.knowman.io/guides/ai-knowledge-base)

## More in this topic

- [How to give VS Code better memory](https://www.knowman.io/guides/vscode-memory)
- [How to give Qwen Code better memory](https://www.knowman.io/guides/qwen-code-memory)
- [How to give Augment Code better memory](https://www.knowman.io/guides/augment-memory)

## More for opencode

- [KnowMan MCP server for OpenCode](https://www.knowman.io/integrations/opencode)
- [How to teach opencode your knowledge](https://www.knowman.io/guides/teach-opencode-your-knowledge)

## Keep your reading in one place

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/opencode-memory
