Grok Build CLI: Cross-Session Memory
By default every Grok session starts fresh. Memory changes that. With it enabled, Grok remembers project conventions, decisions, and debugging workflows across separate sessions, and recalls the relevant ones automatically. It is experimental and off by default, so here is how to turn it on and use it well.
Starting out? Read Grok Build CLI: Zero to Hero (Start Here) first.
Turn it on
Enable memory per session with a flag, for your whole shell with an env var, or permanently in config.toml. The --no-memory flag always wins if you need to force it off.
Remember, forget, recall
Once on, you talk to memory in plain language. Tell Grok to remember a preference and it writes a durable line under an organized heading. Tell it to forget and it finds and removes the entry. Ask what it knows and it summarizes across all your memory files.
Two commands do the heavier lifting. /flush triggers an LLM summary of the current session and writes it to a dated log, perfect right before compaction. /dream consolidates scattered session logs into clean, deduplicated topics so search quality improves over time.
How it is stored
Memory is just Markdown under ~/.grok/memory/: a global file for cross-project facts, a per-workspace file for project conventions, and dated session logs. A workspace is keyed by a hash of its git remote, so all clones and worktrees of the same repo share one memory directory. An SQLite index gives fast hybrid search, full-text plus optional vector similarity.
Manage it from the CLI
You do not need the TUI to work with memory. Edit the files in your editor, check the index stats, or wipe it clean.
How it reaches the model
On the first turn of a session, Grok searches memory for content relevant to the current project and injects it as context, so it starts already knowing what past sessions learned. Memory is searched again after auto-compaction to recover context that compression dropped. Session memories decay over time so recent work is prioritized, while curated global and workspace notes do not.
Use /flush at the end of a productive debugging session. Future-you will be grateful when the same gnarly bug resurfaces.
Continue the series
The full series
- Grok Build CLI: Zero to Hero (Start Here)
- Grok Build CLI: Sessions, Rewind and Compaction
- Grok Build CLI: Slash Commands and Keyboard Mastery
- Grok Build CLI: Teaching Grok Your Project (AGENTS.md)
- Grok Build CLI: Models and Custom Endpoints
- Grok Build CLI: Extending Grok with MCP, Skills, Plugins and Hooks
- Grok Build CLI: Cross-Session Memory (you are here)
- Grok Build CLI: Subagents, Plan Mode and Background Work
- Grok Build CLI: Headless Mode and Automation
- Grok Build CLI: Sandbox and Permissions
- Grok Build CLI: IDE Integration with ACP
- Grok Build CLI: The Evolution (Power-User Version History)