OpenCode Memory: AGENTS.md, Compaction and Hindsight

4 min read

How OpenCode carries context between sessions: AGENTS.md load order, the CLAUDE.md fallback, the instructions array, compaction defaults, and adding Hindsight memory with one install command.

What is OpenCode memory?

OpenCode remembers project rules through instruction files, not through a memory store. You write AGENTS.md files, and OpenCode sends them to the model at the start of every session. When a chat grows past the context limit, OpenCode writes a compaction summary so the chat can keep going. The OpenCode docs we read on 2 December 2026 describe no automatic notes that carry over between sessions, so for that you add a plugin or a memory server.

Where OpenCode reads its instructions

The docs (opencode.ai/docs/rules, read 2 December 2026) list these sources:

FileApplies toWhen it loads
~/.config/opencode/AGENTS.mdYou, in every projectEvery session
AGENTS.md at the project rootEveryone who works in the repoEvery session
AGENTS.md in a subfolder, such as packages/web/Only that folderWhen the agent reads a file there
CLAUDE.mdThe folder with no AGENTS.mdUsed only as a fallback

The load order is fixed. The selected agent or provider prompt comes first, then the global and project AGENTS.md files, then any files listed in instructions. OpenCode combines them and does not resolve conflicts between them, so keep the rules in one place. Put rules for the whole repo at the root, and rules for one area in that area’s folder.

If you use Claude Code files, OpenCode reads CLAUDE.md in any folder that has no AGENTS.md. Without a global ~/.config/opencode/AGENTS.md, it reads ~/.claude/CLAUDE.md. Set OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1 to skip every CLAUDE.md file.

Edits to a global or project AGENTS.md take effect in a running session before the next model request. Edits to a nested file do not, so start a new session after you change one.

Add more instruction files

The instructions array in opencode.jsonc loads extra files, glob patterns or HTTP(S) URLs after the AGENTS.md files:

1{
2  "$schema": "https://opencode.ai/config.json",
3  "instructions": [
4    "CONTRIBUTING.md",
5    "docs/guidelines/*.md",
6    "~/rules/opencode.md",
7    "https://example.com/instructions.md"
8  ]
9}

A URL that fails to load is skipped, or keeps its last copy. Each URL fetch has a five-second timeout. Keep each file short and specific, so the rules that matter are easy to follow.

How compaction works

Compaction writes a summary of the older chat and keeps the recent part word for word. The compaction docs (opencode.ai/docs/compaction, read 2 December 2026) give these defaults:

  • auto: true. OpenCode compacts near the context limit, and retries once if a provider rejects a request as too long.
  • keep.tokens: 15000. The approximate amount of recent conversation kept beside the summary.
  • buffer: 15% of the model’s window, at least 16k. Free space kept for new work.

The docs say compaction is lossy. If exact recent details matter, raise keep.tokens or compact by hand before the automatic step runs. Compaction works inside one session. It does not carry facts into the next one.

Adding Hindsight to OpenCode

The Hindsight Coding Agents package has an OpenCode entry point. Its docs (hindsight.vectorize.io/sdks/integrations/coding-agents, read 2 December 2026) say the plugin uses native OpenCode tools, so no MCP server is needed.

  1. Run npx @vectorize-io/hindsight-coding-agents install opencode.
  2. The installer adds a plugin entry to ~/.config/opencode/opencode.json.
  3. Work as usual. Capture runs in the background from the repo’s git history and your conversations, with no setup command.

By default each repo gets one bank, coding-agent::{gitProject}. OpenCode, Claude Code and Codex share that bank for the same repo. To split memory per agent, change the bank name to {harness}-{gitProject}.

Coding Agents 0.9.0 (30 November 2026) says memory comes back after a compaction for OpenCode, and that sessionContext pins pages and mental models at the start of a session. Source: hindsight.ai/oss/blog/2026/11/30/coding-agents-090.

Limits:

  • Memory lives in Hindsight Cloud (needs an API key), a server you run, or a local daemon. Pick one before you install.
  • OpenCode 2 has its own command, install opencode2, because it changed the plugin API.
  • We found no independent benchmark of this plugin with OpenCode in the sources we checked, so the page makes no performance claim.

Where this fits

Use AGENTS.md for rules that never change: build commands, code style, folders to avoid. Use a memory bank for facts that come out of the work: past decisions, a bug’s root cause, a setup step that took an hour. The two do different jobs, and a repo can use both.

For the same question on other tools, see AI coding agent memory, Claude Code memory and Codex memory.

Sources