A clean, hierarchical, and opinionated memory system for Grok Build that scales gracefully on long projects.
A lightweight but powerful memory architecture for Grok that uses progressive disclosure, strict decision tracking, and well-timed reminders so the model actually remembers what matters — without bloating every context.
Grok's built-in cross-session memory is powerful, but many users want more control over what gets remembered and how. This project gives you:
- A lightweight index that is automatically injected at the start of every session
- Detailed memory files that are only loaded when needed
- Strong conventions around important decisions (reverse chronological, explicit superseding rules)
- Automatic reminders at good moments (
Stopand especiallyPreCompact)
The result is a memory system that scales well even on long-running projects without bloating every context window.
Important: As of the current version of Grok Build, SessionStart hooks that return additionalInstructions are not yet injected into the model's prompt by the platform (this was confirmed during real testing in the grok-memory-test project).
- Static instructions placed in the root
AGENTS.md(this is the recommended approach) SessionEndhook (records session timestamp)- Memory reminders on
StopandPreCompact
- Dynamic injection via the
SessionStarthook
The template is designed so it works today using the reliable static method, while keeping the hook infrastructure for the future.
.grok/
├── memory.md # Lightweight index (always loaded)
├── AGENTS.md # Project rules + memory system instructions
├── hooks/
│ ├── hooks.json # Hook registration
│ ├── session-start.py # Injects memory index
│ ├── session-end.py # Records session end timestamp
│ └── memory-reminder.py # Gentle reminder on Stop / PreCompact
└── memory/
├── tools.md
├── user-preferences.md
└── important-decisions.md
The easiest and most reliable way to set up the memory system is to use the dedicated installation guide.
-
Copy the
.grok/folder from this repository into your project. -
Open the file
install-memory-system.mdin your project. -
In a Grok Build session, simply tell Grok:
"Please read and follow the instructions in
install-memory-system.mdto set up the modular memory system for this project."
Grok will guide you through the entire process (creating AGENTS.md, the memory files, and optionally installing the hooks).
Important: When following the guide, ask Grok to create any new files that are needed and to adapt their content and structure to match the specific requirements, domain, and context of your project (rather than using generic templates).
The reminder and session tracking hooks are registered globally. This means:
- Once activated for one project, they can become active in other projects as well (this is expected behavior).
- They are safe: the hooks do nothing if the current project does not have a
.grok/memory.mdfile. - When running setup in a new project, Grok should check for existing global hooks from other projects and clearly explain the situation (including that the hooks are harmless without a memory file) before asking how to proceed.
Note on our original intention:
Creating globally registered hooks was not our original plan. We designed the system around local project hooks (stored in .grok/hooks/) for better isolation between projects. However, due to current limitations in the Grok Build TUI, reliable local project hook discovery is not yet supported. The global registration method is currently the only working mechanism available. We hope this will change soon as the application is updated and we can move back to the preferred local hook approach.
The full guide is here: install-memory-system.md
- Creating the root
AGENTS.mdwith the required "Session Start Rule" - Creating the actual memory template files (
memory.md,important-decisions.md,user-preferences.md,tools.md) - Understanding current platform limitations
- Installing the working global hooks (with your explicit consent)
- Verification steps
We strongly recommend using the guided workflow above rather than trying to follow the instructions manually.
- Copy the
.grok/folder into your project. - Follow the steps in
install-memory-system.mdto configure your rootAGENTS.md. - Optionally install the global hooks for automatic reminders and session tracking.
The local SessionStart hook is included in the template for future compatibility but is not registered globally at this time (see the install guide for details).
The best way to validate the memory system is not by asking Grok to clone the repo inside a session.
-
Create a completely fresh test directory (outside this repository):
mkdir ~/test-grok-memory cd ~/test-grok-memory
-
Copy only the
.grok/folder from this repo (or from a fresh clone):cp -r /path/to/grok-modular-memory/.grok . -
Start a brand new Grok Build session in that folder (very important — do not continue an old session).
-
Run
/hooks-trustand reload hooks (Ctrl+L→l). -
Run a structured test:
- Ask Grok to do some real work (refactor something, plan a feature, debug an issue).
- Make at least one explicit decision and ask it to record it in
important-decisions.md. - Do some trivial commands (
ls,cat, etc.) to verify the reminder does not fire on every tool use. - Work until you see the
PreCompactreminder (you can force compaction or just work long enough). - Start a second session later and verify that the memory index + recent decisions are still present.
-
Verify behavior:
- The model should reference the memory rules without you reminding it.
important-decisions.mdshould be maintained in reverse chronological order.- Reminders should only appear at
StopandPreCompact, not on routine tool calls.
This approach gives you the most realistic signal about whether the system actually helps in practice.
The core idea is progressive disclosure:
.grok/memory.mdis small and is loaded on every session.- The detailed files in
.grok/memory/are only read when the model actually needs them. - This keeps token usage low while still giving excellent long-term recall.
The file .grok/memory/important-decisions.md follows strict conventions:
- Reverse chronological order — newest decisions at the top
- Every entry starts with
**YYYY-MM-DD** — Title - Newer decisions supersede older contradictory ones
- If a new decision would contradict an existing one, the model is instructed to ask you for clarification first
This creates a clean, auditable decision log over the life of a project.
- After any significant architectural or technical decision → update
important-decisions.md - Periodically review
.grok/memory.mdand the linked files - Before major compaction (
PreCompact), the system gently reminds you to capture anything important
You can extend this system easily:
- Add new files under
.grok/memory/and link them frommemory.md - Modify the reminder text in
memory-reminder.py - Add more hooks (e.g., on
UserPromptSubmitfor very long sessions)
- Grok Build (the TUI)
- Python 3 (for the hook scripts)
- The project must be trusted for hooks (
/hooks-trust)
MIT — feel free to use this in your own projects.
- Mauricio Longo – Creator and maintainer of the Grok Modular Memory System
- Grok (built by xAI) – Assisted with architecture, documentation, testing workflows, and iterative improvements to the system
Made for people who build ambitious things with Grok and want their context to actually remember what matters.