# OpenCode Memory: AGENTS.md, Compaction and Hindsight

> 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.

Source: https://aiagentmemory.org/articles/opencode-memory/ · Updated 2026-12-02 · aiagentmemory.org


## 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:

| File | Applies to | When it loads |
|---|---|---|
| `~/.config/opencode/AGENTS.md` | You, in every project | Every session |
| `AGENTS.md` at the project root | Everyone who works in the repo | Every session |
| `AGENTS.md` in a subfolder, such as `packages/web/` | Only that folder | When the agent reads a file there |
| `CLAUDE.md` | The folder with no `AGENTS.md` | Used 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:

```jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "instructions": [
    "CONTRIBUTING.md",
    "docs/guidelines/*.md",
    "~/rules/opencode.md",
    "https://example.com/instructions.md"
  ]
}
```

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](/articles/ai-coding-agent-memory/),
[Claude Code memory](/articles/claude-code-memory/) and [Codex memory](/articles/codex-memory/).

## Sources

- OpenCode rules: https://opencode.ai/docs/rules/ (read 2 December 2026)
- OpenCode compaction: https://opencode.ai/docs/compaction/ (read 2 December 2026)
- Hindsight Coding Agents, OpenCode entry: https://hindsight.vectorize.io/sdks/integrations/coding-agents (read 2 December 2026)
- Hindsight Coding Agents 0.9.0: https://hindsight.ai/oss/blog/2026/11/30/coding-agents-090 (30 November 2026)


## FAQ

### Does OpenCode have memory?

OpenCode does not have an automatic memory store in the docs we read on 2 December 2026. It carries project rules through AGENTS.md files, which it loads at the start of each session, and it keeps a session going with compaction summaries. Anything that must grow across sessions needs a plugin or a memory server.

### Where does OpenCode read AGENTS.md from?

It loads ~/.config/opencode/AGENTS.md, then every AGENTS.md from the current folder up to the project root, and nested AGENTS.md files when the agent reads that area. If a folder has no AGENTS.md, OpenCode reads CLAUDE.md instead.

### How do I add Hindsight memory to OpenCode?

Run npx @vectorize-io/hindsight-coding-agents install opencode. It adds a plugin entry to ~/.config/opencode/opencode.json and needs no MCP server. Memory goes to Hindsight Cloud, a server you run, or a local daemon.

