save_memory tool allows the Gemini agent to persist specific facts, user preferences, and project details across sessions by saving them to your global GEMINI.md file.
Overview
When Gemini needs to remember something for future sessions—like your coding preferences, project conventions, or frequently referenced information—it uses thesave_memory tool to append that information to your global context file.
Memory is automatically loaded in all future sessions as part of the hierarchical context system.
How It Works
Agent identifies important information
During conversation, Gemini recognizes facts worth preserving (e.g., “User prefers functional programming”)
Fact is appended
The information is added to
## Gemini Added Memories section in ~/.gemini/GEMINI.mdTechnical Reference
A clear, self-contained statement in natural language describing the information to remember
~/.gemini/GEMINI.md (global context file)
Format: Bulleted list items under the ## Gemini Added Memories heading
Loading: Automatically included in the hierarchical context for all future sessions
Use Cases
User Preferences
“I prefer functional programming over OOP”“Always use TypeScript for new projects”
Project Conventions
“This codebase uses React hooks exclusively”“Follow the company’s security review checklist”
Environment Details
“Database runs on port 5433, not default 5432”“Use staging API key for testing”
Aliases & Shortcuts
“User’s git alias: ‘gp’ means ‘git push’”“npm run dev:local includes hot reload”
Examples
Saving a preference
~/.gemini/GEMINI.md:
Saving project information
Managing Saved Memories
You can view and edit saved memories by:-
Viewing with
/memory showThis displays the full hierarchical context including saved memories -
Editing directly
Open
~/.gemini/GEMINI.mdin your editor and modify the## Gemini Added Memoriessection -
Refreshing context
After manual edits, use
/memory refreshto reload the context
Best Practices
Keep memories concise and specific
Keep memories concise and specific
Each memory should be a single, clear statement. Avoid long paragraphs.Good: “User prefers tabs over spaces (4-space width)”Bad: “The user mentioned they like tabs better than spaces, and specifically they want 4 spaces worth of width when tabs are displayed…”
Avoid duplicates
Avoid duplicates
Gemini usually checks before saving duplicate information, but you can manually clean up the
GEMINI.md file if needed.Use for persistent information only
Use for persistent information only
Don’t save temporary task details. Use checkpoints or chat history instead.
Related Tools
GEMINI.md Reference
Learn about the hierarchical context system
Context Management
Understand how context files work
Memory Command
View and manage memories with /memory
Checkpointing
Save conversation state for later