Buy @ Amazon

Demystifying Memory in Claude Code


If you’ve been using Claude Code for a while, you know it’s more than just a terminal chat interface that codes — it’s an beast of an AI agent that devours tokens and still leave you with work incomplete wondering how your neighbour claims to get things done.

Claude Code is an ecosystem in itself that requires fair bit of understanding of the parts that make it up and this perhaps is the reason Claude has come up with a certification exam to showcase ones expertise on it. This post is about one of the concepts - Memory - in the Claude Code's workflow that should help you in taming the beast that it is in terms of cost and output usefulness. Understanding the distinction between Static (CLAUDE.md) and Auto (MEMORY.md) memory is the key to tailoring Claude to your specific workflow.

1. Static Memory with CLAUDE.md: Your Project’s "Constitution"

  • Think of CLAUDE.md as the permanent rulebook.
  • It lives in your project folder, and is tracked to be version controlled by Git.
  • It is always loaded at the start of every Claude-code session.
  • Best for routine instructions that the all agents should pay heed to.

2. Auto Memory with MEMORY.md: Claude’s "Lab Notebook"

  • As you work, Claude quietly takes notes on things it learns about your environment and its mistakes.
  • This file is stored in your global user directory (e.g., ~/.claude/ on Mac/Linux), meaning it stays on your machine even if you delete the project folder.
  • How it works: Claude looks at the first ~200 lines of this file at the start of a session. It might record things like: "The user prefers early returns in loops" or "The build script fails if the VPN is active."


The Docker Sandbox Challenge

If you run Claude inside a disposable container (e.g., docker sandbox run claude), your MEMORY.md is typically lost when the container exits.
Fix Option 1: If you want Claude to keep its "learned" memory across Docker runs, you must mount your local .claude config directory as a volume: `docker run -v ~/.claude:/home/claude/.claude ...`
Fix Option 2: Stick to CLAUDE.md for everything important. In a world of disposable sandboxes, explicit memory is king.