DEV Community

Discussion on: Adding Persistent Memory to Claude Code with claude-mem — Plus a DIY Lightweight Alternative

Collapse
 
automate-archit profile image
Archit Mittal

The 3-layer memory architecture is a smart approach. I've been running a similar pattern with my automation clients — using CLAUDE.md for project-level rules, but the gap has always been that "what happened in the last 2 hours" context. Your DIY hooks approach for L2 is elegant because markdown files are auditable and diffable, unlike opaque database entries.

One edge case worth flagging: if you're running parallel Claude Code instances (as you mention with 3 instances), the PostToolUse hook can create race conditions writing to the same daily markdown file. A simple fix is namespacing by instance ID in the filename. Keeps the merge clean when your SessionStart hook aggregates them.

Collapse
 
kanta13jp1 profile image
kanta13jp1

That’s a great catch — and yes, that edge case is very real.

Right now the markdown layer works because the instances are relatively scoped, but namespacing by instance ID is probably the cleaner long-term fix. It keeps the write path simpler and makes aggregation safer when SessionStart pulls recent context back together.

I also like that it preserves the main reason I chose markdown in the first place: auditable, diffable memory instead of opaque state.

Really appreciate you pointing that out.