Gemini CLI Setup
Give Gemini CLI persistent memory across sessions.Gemini CLI starts every session from scratch. Claude-mem changes that by capturing observations, decisions, and patterns — then injecting relevant context into each new session.
How it works: Claude-mem installs lifecycle hooks into Gemini CLI that capture tool usage, agent responses, and session events. A local worker service extracts semantic observations and injects relevant history at session start.
Prerequisites
- Gemini CLI installed and configured
- Node.js 18+
- The
~/.geminidirectory must exist (created by Gemini CLI on first run)
Installation
Step 1: Install claude-mem
- Auto-detect Gemini CLI (checks for
~/.geminidirectory) - Prompt you to select Gemini CLI from the IDE picker
- Install 8 lifecycle hooks into
~/.gemini/settings.json - Inject context configuration into
~/.gemini/GEMINI.md - Start the worker service
Step 2: Configure an AI provider
Claude-mem needs an AI provider to extract observations from your sessions. Choose one:- Gemini API (Free)
- Claude SDK
- OpenRouter
The simplest option — use Gemini’s own API for observation extraction:
- Get a free API key from Google AI Studio
- Add it to your settings:
Step 3: Verify installation
Step 4: Start using Gemini CLI
Launch Gemini CLI normally. Claude-mem works in the background:What gets captured
Claude-mem registers 8 of Gemini CLI’s 11 lifecycle hooks:| Hook | Purpose |
|---|---|
| SessionStart | Injects memory context into the session |
| SessionEnd | Marks session complete, triggers summary |
| PreCompress | Captures session summary before compression |
| Notification | Records system events (permissions, etc.) |
| BeforeAgent | Captures user prompts |
| AfterAgent | Records full agent responses |
| BeforeTool | Logs tool invocations before execution |
| AfterTool | Captures tool results after execution |
Troubleshooting
Hooks not firing
-
Verify hooks exist in settings:
You should see entries like
"SessionStart","AfterTool", etc. with claude-mem commands. - Restart Gemini CLI after installation.
-
Re-run the installer:
Worker not running
No context appearing at session start
- Ensure the worker is running (check http://localhost:37777)
- You need at least one previous session with observations for context to appear
- Check your AI provider is configured in
~/.claude-mem/settings.json
Raw escape codes in output
If you see characters like[31m or [0m in the session context, your claude-mem version may need updating:
Uninstalling
~/.gemini/settings.json and cleans up ~/.gemini/GEMINI.md.
Next Steps
- Gemini Provider — Configure the Gemini AI provider for observation extraction
- Configuration — All settings options
- Search Tools — Search your memory from within sessions
- Troubleshooting — Common issues and solutions

