Coding Global Memory
Setup
- Derive
project-name: replace all/in CWD with-. Example:/Users/x/projects/my-app→-Users-x-projects-my-app - Set
MEMORY_DIR=~/.agents/memories/{project-name}/.
All workflows below assume setup is done.
Memory Layout
~/.agents/memories/{project-name}/
├── MEMORY.md # Main file (frontmatter: updated, project, description)
└── {topic}.md # Optional sub-files, split by project's actual modules
Sub-file topics should be derived from the project's real structure — not from a fixed list. Analyze the codebase to determine what modules warrant separate memory files.
MEMORY.md sections: Index (only if sub-files exist), Architecture, Key Decisions, Conventions, Known Issues. Sections are flexible.
Read Memory
- If
MEMORY.mddoes not exist → report "No memory found." and stop. - Read
MEMORY.md. Ifupdatedis older than 30 days, warn about staleness. - Read sub-files only when the current task needs them.
- Summarize relevant facts into working context. Do not paste entire memory.
Write Memory
- Run
mkdir -p $MEMORY_DIR. - If
MEMORY.mdexists → read it first, then merge new stable learnings. Remove outdated statements. - If
MEMORY.mddoes not exist → scan project structure, summarize stable learnings, create new file. - Update the
updateddate in frontmatter. - Write back to
MEMORY.md.
Splitting Rules
If MEMORY.md exceeds ~150 lines:
- Extract stable sections into sub-files.
- Add them to the Index.
- Keep
MEMORY.mdas summary and navigation.
Memory Quality
Write only what is actionable, stable, and non-obvious.
Do not store: full file contents, temporary branch state, scratch notes, generic language/framework knowledge.
Anti-Patterns
- Writing memory before checking if older memory exists.
- Dumping raw code when a short summary suffices.