Persistent memory for Claude Code using mem0.ai - remembers context across conversations.
- Automatic Memory Retrieval: Relevant memories are searched and injected before each prompt
- Conversation Storage: Conversations are automatically saved to mem0 when sessions end
- Semantic Search: Vector-based search for intelligent memory retrieval
- User Scoping: Memories are scoped by user ID for personalized experiences
- Python 3.8+
- Claude Code with plugin support
- mem0 API key (get one here)
# 1. Add plugin to ~/.claude/settings.json
# 2. Install dependency
pip install mem0ai
# 3. Create .env in your project root
echo "MEM0_API_KEY=your-api-key-here" > .env
# 4. Restart Claude CodeAdd to your .claude/settings.json:
{
"plugins": [
"github:0xtechdean/claude-code-mem0"
]
}Or clone locally:
git clone https://github.com/0xtechdean/claude-code-mem0.gitThen add to settings:
{
"plugins": [
"/path/to/claude-code-mem0"
]
}pip install mem0aiCreate a .env file in your project root:
# Required: Get your API key from https://app.mem0.ai
MEM0_API_KEY=your-api-key-here
# Optional: Custom user identifier (default: claude-code-user)
MEM0_USER_ID=your-user-id
# Optional: Number of memories to retrieve (default: 5)
MEM0_TOP_K=5
# Optional: Minimum similarity threshold (default: 0.3)
MEM0_THRESHOLD=0.3
# Optional: Number of messages to save per session (default: 10)
MEM0_SAVE_MESSAGES=10The plugin will be active after restart.
claude-code-mem0/
├── .claude-plugin/
│ └── plugin.json # Plugin metadata
├── commands/
│ └── save.md # /mem0:save command
├── hooks/
│ ├── hooks.json # Hook configuration
│ ├── userpromptsubmit.py # Memory retrieval before prompts
│ ├── stop.py # Memory storage on session end
│ └── save_manual.py # Manual memory save script
├── skills/
│ ├── configure/
│ │ └── SKILL.md # /mem0:configure skill
│ └── status/
│ └── SKILL.md # /mem0:status skill
└── README.md
When you submit a prompt, the plugin:
- Searches mem0 for memories semantically related to your prompt
- Retrieves the top K most relevant memories above the similarity threshold
- Injects them into Claude's context as a system reminder
Example context injection:
## Relevant memories from previous conversations:
- User prefers TypeScript over JavaScript
- Working on an e-commerce platform using Next.js
- Database is PostgreSQL with Prisma ORM
When a session ends, the plugin:
- Extracts the most recent messages from the conversation transcript
- Sends them to mem0 for asynchronous processing
- mem0 automatically extracts key facts and stores them as memories
Note: Memory processing happens asynchronously. New memories may take a few seconds to become searchable.
| Variable | Description | Default |
|---|---|---|
MEM0_API_KEY |
Your mem0 API key (required) | - |
MEM0_USER_ID |
User identifier for memory scoping | claude-code-user |
MEM0_TOP_K |
Number of memories to retrieve | 5 |
MEM0_THRESHOLD |
Minimum similarity score (0-1) | 0.3 |
MEM0_SAVE_MESSAGES |
Messages to save per session | 10 |
MEM0_AUTO_SAVE |
Auto-save each prompt to memory | true |
Manually save memories from the current conversation. Useful when you want to persist important context without ending the session.
Interactive configuration wizard for setting up mem0 credentials.
Check the current configuration status and test the connection.
- Verify
MEM0_API_KEYis set correctly in.env - Check that mem0ai is installed:
pip install mem0ai - Ensure you have existing memories in mem0
- Try lowering
MEM0_THRESHOLDfor broader matches (e.g.,0.1)
- Check the console for error messages
- Verify your API key has write permissions
- Ensure conversations have meaningful content
- Remember that memory processing is asynchronous - wait a few seconds
# Set your API key
export MEM0_API_KEY=your-api-key-here
# Test connection and add a memory
python3 -c "
from mem0 import MemoryClient
client = MemoryClient(api_key='$MEM0_API_KEY')
print('Connection successful!')
# Add a test memory
result = client.add(
messages=[{'role': 'user', 'content': 'Test message'}],
user_id='test-user'
)
print(f'Add result: {result}')
"python3 -c "
from mem0 import MemoryClient
client = MemoryClient(api_key='$MEM0_API_KEY')
results = client.search('test', filters={'user_id': 'test-user'}, top_k=5)
print(f'Found {len(results.get(\"results\", []))} memories')
"- API keys are loaded from environment variables or
.envfiles - Add
.envto your.gitignoreto prevent committing secrets - Memories are scoped by
MEM0_USER_ID- use unique IDs for different projects - Review mem0's privacy policy for data handling
Contributions are welcome! Please open an issue or pull request at github.com/0xtechdean/claude-code-mem0.
Run the test suite:
pip install pytest
python -m pytest hooks/tests/ -vMIT