Start free
Guide Memory

How to give Gemini CLI better memory

Updated 4 min read

The short answer

Gemini CLI keeps information across sessions with GEMINI.md context files, which are concatenated and sent to the model with every prompt (Gemini CLI docs). A separate Memory tool persists durable facts, user preferences, and project details by editing Markdown memory files directly (Memory tool docs). For access to saved reading, decisions, and playbooks, you can also add the KnowMan MCP server, which exposes kb_memories, kb_ask, and kb_search (KnowMan MCP guide).

On this page8 sections
  1. GEMINI.md: the context file
  2. Where context files live and when they load
  3. Just-in-time context
  4. Inspect and manage memory
  5. The Memory tool for persistent memories
  6. What this memory is built for
  7. Where KnowMan fits
  8. Questions people ask

GEMINI.md: the context file

Context files use the default name GEMINI.md and exist to provide instructional context to the Gemini model (Gemini CLI docs). Use them for project-specific instructions, a persona definition, or coding style guides, so responses are more accurate and tailored (Gemini CLI docs). Instead of repeating instructions in every prompt, define them once in a context file (Gemini CLI docs).

Where context files live and when they load

The global context file is ~/.gemini/GEMINI.md, in your home directory, and provides default instructions for all your projects (Gemini CLI docs). The CLI also searches for GEMINI.md files in configured workspace directories and their parent directories (Gemini CLI docs). It loads context files from several locations, concatenates the contents of all found files, and sends them to the model with every prompt (Gemini CLI docs). The footer shows the number of loaded context files, a quick cue of the active instructional context (Gemini CLI docs).

Just-in-time context

When a tool accesses a file or directory, the CLI automatically scans for GEMINI.md files in that directory and its ancestors, up to a trusted root (Gemini CLI docs). The docs call this just-in-time context. It lets the model discover highly specific instructions for particular components only when they are needed (Gemini CLI docs). For broad guidance, the global file at ~/.gemini/GEMINI.md provides default instructions for all your projects (Gemini CLI docs).

Inspect and manage memory

/memory show displays the full, concatenated content of the current hierarchical memory, and /memory reload forces a re-scan and reload of all GEMINI.md files from all configured locations (Gemini CLI docs). Large files can be broken into smaller components by importing content from other files with the @file.md syntax, which supports relative and absolute paths (Gemini CLI docs). To use a different name, set context.fileName in settings.json; it accepts a list of names such as AGENTS.md and CONTEXT.md (Gemini CLI docs). Files can also be ignored to exclude their content from the context system (Gemini CLI docs).

The Memory tool for persistent memories

Besides context files, Gemini CLI documents a separate Memory tool for saving persistent memories (Gemini CLI docs). It persists durable facts, user preferences, and project details by editing Markdown memory files directly, using write_file or replace (Memory tool docs). The agent routes what it saves: shared project instructions to repository GEMINI.md files, private project notes to a per-project private memory folder, and cross-project personal preferences to the global ~/.gemini/GEMINI.md (Memory tool docs). Stored facts are automatically included in the hierarchical context system for all future sessions (Memory tool docs).

What this memory is built for

Documented use cases are persisting user preferences (for example, "I prefer functional programming"), saving project-wide architectural decisions, and storing frequently used aliases or system configurations (Memory tool docs). The guidance is to keep durable instructions concise and avoid duplicating the same fact across memory tiers (Memory tool docs). In short, this is memory for how you work and how a project is built. If you also want an agent to draw on what you have read, that reading needs a home of its own. See give your AI context.

Where KnowMan fits

KnowMan saves articles and links, reads and tags them, answers questions with citations, and keeps memories: claims, decisions, and playbooks (KnowMan guide). Its MCP server is a local stdio server, started with npx -y @knowman/mcp, and exposes kb_memories for saved claims, decisions, and playbooks, kb_ask for answers with citations, and kb_search for searching saved items by keyword or meaning. Gemini CLI's own memory keeps handling how you work; KnowMan holds what you have read and decided. For background, read persistent memory for AI agents and the MCP server knowledge base guide.

Questions people ask

Where does Gemini CLI store memory?

The global context file is ~/.gemini/GEMINI.md, and the CLI also loads GEMINI.md files from workspace directories and their parents (Gemini CLI docs). All found files are concatenated and sent with every prompt. The Memory tool additionally persists durable facts, user preferences, and project details by editing Markdown memory files directly (Memory tool docs).

How do I check what memory Gemini CLI has loaded?

/memory show displays the full, concatenated content of the current hierarchical memory, and /memory reload forces a re-scan of all configured locations (Gemini CLI docs). The CLI footer also displays the number of loaded context files (Gemini CLI docs).

Can Gemini CLI remember things on its own?

Yes, through the Memory tool, which persists durable facts, user preferences, and project details by editing Markdown memory files directly (Memory tool docs). Stored facts are automatically included in the hierarchical context system for all future sessions (Memory tool docs).

Can I give Gemini CLI memory of what I read?

KnowMan's MCP server exposes kb_memories for saved claims, decisions, and playbooks, kb_ask for answers with citations, and kb_search for searching saved items by keyword or meaning. Gemini CLI's own Memory tool, meanwhile, persists durable facts, user preferences, and project details in Markdown memory files (Memory tool docs). For the server side of the connection, see the MCP server knowledge base guide.

Remember what you read

Try KnowMan Pro for 14 days with no credit card. Create your account

Start free

Every new account starts with 14 days of Pro. No credit card.