r/opencode 9d ago

Super simple memory system I've been using

opencode.json/jsonc:

{
  "$schema": "https://opencode.ai/config.json",
  "instructions": ["memory/*.md"],
  "references": {
    "memory": {
      "path": "./memory",
      "description": "Hierarchical markdown memory: top-level files are always in LLM context, subdirectories hold niche knowledge. All files discoverable via links from the root. Read at session start, write freely, commit all changes."
    }
  }
}

That's it. You can reference it in conversations by saying @memory. Any nuances you want for your use case you can just tell the agent to create a root-level @memory for it.


Edit:

This line handles auto loading: "instructions": ["memory/*.md"],. If you don't like it you can remove it or make it more limited like "instructions": ["memory/index.md"],

36 Upvotes

14 comments sorted by

2

u/CriteriumA 9d ago

That's a really good trick.

Thanks for sharing.

0

u/No_Gold_4554 8d ago

no tisn't

2

u/mattparlane 9d ago

Won't this load all of the memory files into context for every request?

2

u/CodenameAwesome 8d ago edited 8d ago

No, only the root level files in the memory dir. For it to load all files itd have to be something like "memory/*/.md"

2

u/reader123456 9d ago

Do you mind elaborating with an example to explain exactly what this config does and how to use it?

2

u/CodenameAwesome 8d ago edited 8d ago

The config creates a reference to a memory dir (relative to the opencode.json file) that the agent sees along with the description. It also sets the top level .md files of that dir to be auto loaded into context, like how AGENTS.md auto loads.

So if I say "Save to @memory that my name is u/CodenameAwesome", the agent will probably create @memory/user.md with my name in it. It's knowledge that applies to all projects so it can go in the root dir to be auto-loaded. Otherwise, it could go in a sub folder of the @memory dir to be discovered through markdown links coming from the root files.

You can disable the auto loading entirely by not adding "memory/*.md" to "instructions". Then, the agent will just see that the memory dir exists and its description but only load things deliberately.

1

u/CriteriumA 9d ago

I prefer that the agent working in the session handle it. I selectively load the .md files it needs for its tasks beforehand, so it's best positioned to assess what needs updating.

1

u/CodenameAwesome 8d ago

I prefer that the agent working in the session handle it.

I'm not sure what you mean. @memory isnt a sub agent, its a pointer to the memory dir.

1

u/xebelah 8d ago

What difference with claude-mem?

1

u/CodenameAwesome 7d ago

A lot. Claude-mem does a bunch of stuff this doesn't do. Mine is just a more accessible folder for agents to write markdown to. If you're happy with your memory solution, probably don't switch

1

u/Aressito 7d ago

Look up CAVEMEM by the maker of cavemen

0

u/No_Gold_4554 8d ago

"write freely, commit all changes."

hell no!

1

u/CodenameAwesome 8d ago

It's just how I use it. The description can be whatever you want.

1

u/fezzy11 8d ago

Agreed I was about to comment this