๐Ÿง 
Stage 2 ยท Lesson 2 of 4

Structured Memory Folders

The 60-second fix. Replace one file with a folder structure you control.

~20 min read8 walkthrough steps

Here's the fix that changes everything, and it takes about 60 seconds to implement: replace your single MEMORY.md with a memory/ folder containing organized, topic-specific files.

Instead of one monolithic file, you create a directory structure. memory/projects/ holds per-project context. memory/preferences/ holds your tech stack, coding style, and tool preferences. memory/knowledge-base/ holds reference material the agent needs across sessions. Each file is focused, manageable, and independently maintainable.

The magic is in the system prompt instruction. Add one line to your agents.md: "At the end of each session, update the relevant files in the memory/ folder with any new information learned. Create new files for new topics. Remove outdated information from existing files." That's it. Your agent now maintains its own organized memory.

Why does this work so much better than a single file? First, selective loading. Your agent doesn't need to load every memory file for every conversation. Working on Project A? It reads memory/projects/project-a.md. It doesn't load Project B, C, or D. Second, no contradictions. When a fact changes, it gets updated in one specific file, not appended to a growing pile. Third, you can see it. These are plain markdown files on your filesystem. You can read them, edit them, delete them. You're always in control.

This approach is also model-agnostic. It works with any LLM โ€” Claude, GPT, Gemini, local models, anything. There are no plugins to install, no services to configure, no vendor lock-in. It's just files and folders. The simplest solutions are usually the most robust, and this is a perfect example.

Walkthrough

  1. 1
    Create the memory folder structure: mkdir -p memory/projects memory/preferences memory/knowledge-base
  2. 2
    Create your first preference file: memory/preferences/tech-stack.md with your stack choices (language, framework, package manager, etc.)
  3. 3
    Create a project file: memory/projects/[your-project-name].md with key context
  4. 4
    Add to your agents.md: 'At the end of each session, update relevant files in the memory/ folder. Create new files for new topics. Remove outdated information.'
  5. 5
    Also add: 'At the start of each session, read the memory/preferences/ folder to load my preferences.'
  6. 6
    Run a session, discuss something new, then ask the agent to update memory
  7. 7
    Verify: check the memory files to see what the agent wrote
  8. 8
    Start a new session and confirm the agent loads the correct context

Checkpoint

You have a working memory/ folder structure with at least a preferences file and a project file. Your agent's system prompt instructs it to maintain these files. Cross-session memory is working.