# How to give Gemini CLI better memory

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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). A separate Memory tool persists [durable facts](https://www.knowman.io/guides/ai-agent-memory), user preferences, and project details by editing Markdown memory files directly ([Memory tool docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/tools/memory.md)). For access to [saved reading](https://www.knowman.io/guides/ai-article-saver), decisions, and playbooks, you can also add the KnowMan MCP server, which exposes `kb_memories`, `kb_ask`, and `kb_search` ([KnowMan MCP guide](https://www.knowman.io/guides/mcp-server-knowledge-base)).

## GEMINI.md: the context file

Context files use the default name `GEMINI.md` and exist to provide [instructional context](https://www.knowman.io/guides/teach-gemini-cli-your-knowledge) to the Gemini model ([Gemini CLI docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). Use them for project-specific instructions, a persona definition, or coding style guides, so responses are more accurate and tailored ([Gemini CLI docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). Instead of repeating instructions in every prompt, define them once in a context file ([Gemini CLI docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)).

## 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). The CLI also searches for `GEMINI.md` files in configured workspace directories and their parent directories ([Gemini CLI docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). The footer shows the number of loaded context files, a quick cue of the active instructional context ([Gemini CLI docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)).

## 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). For broad guidance, the global file at `~/.gemini/GEMINI.md` provides default instructions for all your projects ([Gemini CLI docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)).

## 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). Files can also be ignored to exclude their content from the context system ([Gemini CLI docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)).

## The Memory tool for persistent memories

Besides context files, Gemini CLI documents a separate Memory tool for saving persistent memories ([Gemini CLI docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). It persists durable facts, user preferences, and project details by editing Markdown memory files directly, using `write_file` or `replace` ([Memory tool docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/tools/memory.md)). 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/tools/memory.md)). Stored facts are automatically included in the hierarchical context system for all future sessions ([Memory tool docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/tools/memory.md)).

## 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/tools/memory.md)). The guidance is to keep durable instructions concise and avoid duplicating the same fact across memory tiers ([Memory tool docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/tools/memory.md)). 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](https://www.knowman.io/guides/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](https://www.knowman.io/guides/mcp-server-knowledge-base)). Its MCP server is a local [stdio server](https://www.knowman.io/guides/what-is-an-mcp-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](https://www.knowman.io/guides/how-to-save-articles) by [keyword or meaning](https://www.knowman.io/guides/ai-knowledge-base). 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](https://www.knowman.io/guides/persistent-memory-for-ai-agents) and the [MCP server knowledge base guide](https://www.knowman.io/guides/mcp-server-knowledge-base).

## Questions

### 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/tools/memory.md)).

### 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)). The CLI footer also displays the number of loaded context files ([Gemini CLI docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/cli/gemini-md.md)).

### 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/tools/memory.md)). Stored facts are automatically included in the hierarchical context system for all future sessions ([Memory tool docs](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/tools/memory.md)).

### 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](https://raw.githubusercontent.com/google-gemini/gemini-cli/main/docs/tools/memory.md)). For the server side of the connection, see the [MCP server knowledge base guide](https://www.knowman.io/guides/mcp-server-knowledge-base).

## Related guides

- [Connect your knowledge base through KnowMan's MCP server](https://www.knowman.io/guides/mcp-server-knowledge-base)

- [Persistent Memory for AI Agents](https://www.knowman.io/guides/persistent-memory-for-ai-agents)

- [How to Give Your AI Context from What You Read](https://www.knowman.io/guides/give-your-ai-context)

- [How to Give ChatGPT Memory](https://www.knowman.io/guides/how-to-give-chatgpt-memory)

## More in this topic

- [How to give Hermes Agent better memory](https://www.knowman.io/guides/hermes-memory)
- [How to give Goose better memory](https://www.knowman.io/guides/goose-memory)
- [How to set up JetBrains AI Assistant rules](https://www.knowman.io/guides/jetbrains-memory)

## More for Gemini CLI

- [Connect KnowMan to Gemini CLI](https://www.knowman.io/integrations/gemini-cli)
- [How to teach Gemini CLI your knowledge](https://www.knowman.io/guides/teach-gemini-cli-your-knowledge)

## Remember what you read

Try KnowMan Pro for 14 days with no credit card. [Create your account](https://app.knowman.io/signup)

[Start free](https://app.knowman.io/signup)

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

Source: https://www.knowman.io/guides/gemini-cli-memory
