agent-history-mcp
Local memory search for Codex and Claude Code conversations. It keeps history on your machine, builds a local graph index, and returns compact evidence from past sessions.
README
agent-history-mcp
Local memory search for Codex and Claude Code conversations.
agent-history-mcp is a local MCP server that lets coding agents search your past AI coding sessions across OpenAI Codex CLI and Claude Code. It keeps the history on your machine, builds a local graph index, and returns compact evidence instead of dumping full conversations into context.
Why This Exists
Coding agents solve useful problems in one-off chats, then that knowledge disappears into JSONL history. This project turns those old sessions into a searchable local memory layer:
- find previous fixes, commands, APIs, errors, and file paths
- search Codex history from Claude Code, and Claude history from Codex-compatible MCP clients
- use graph search for "similar problem" retrieval when exact keywords differ
- surface repeated workflows that could become reusable skills
No chat history is uploaded. Codex and Claude history files are read-only; only the derived local index is written.
Features
- Hybrid search: SQLite FTS5 keyword search plus fuzzy fallback.
- Local graph search: extracted relationships between sessions, messages, topics, commands, APIs, paths, and errors.
- Skill suggestions: evidence-backed ideas for reusable skills based on repeated chat patterns.
- Incremental indexing: changed JSONL files are parsed on demand; no background daemon required.
- Privacy-first: no network calls or model calls are used for indexing.
Quick Start
1. Install
From GitHub:
pip install git+https://github.com/monishkumarvr/agent-history-mcp.git
From a local clone:
git clone https://github.com/monishkumarvr/agent-history-mcp.git
cd agent-history-mcp
pip install .
2. Register With Claude Code
Add this to ~/.claude/.mcp.json:
{
"mcpServers": {
"agent-history": {
"command": "python3",
"args": ["-m", "agent_history_mcp"]
}
}
}
Claude Code starts the server automatically when needed.
3. Run Your First Query
Ask Claude Code:
Search my history for CUDA illegal address
Other useful prompts:
Use graph search for a similar Redis migration timeout
Did I solve a similar HMAC issue before?
Suggest skills I should create from my recent chats
List my recent Codex sessions
Get the full session where I fixed the GStreamer pipeline stall
4. Optional: Rebuild The Derived Index
refresh_history_index(rebuild=true)
This deletes and recreates only the derived SQLite graph database. It never modifies Codex or Claude history files.
Tools
| Tool | What it does |
|---|---|
search_history |
Hybrid search across past sessions. Uses keyword/fuzzy search plus graph relevance. |
search_graph |
Relationship-oriented graph search for related bugs, APIs, commands, files, and topics. |
suggest_skills |
Proposes evidence-backed reusable skill ideas from repeated chat patterns. |
list_sessions |
Lists sessions with titles, dates, sources, and message counts. |
get_session |
Retrieves a bounded portion of a specific session. |
refresh_history_index |
Manually refreshes or rebuilds the derived local graph index. |
Example Outputs
search_history
Found 2 session(s) matching "CUDA illegal address":
-- Result 1 ------------------------------------------
Source : CODEX
Session: Fix CUDA kernel crash
Date : 2026-05-07
ID : rollout-2026-05-07...
[YOU ASKED]
Fix CUDA illegal address after kernel launch
[ANSWER]
Add synchronization around the kernel launch and rerun the focused pytest case.
search_graph
Found 1 graph result(s) matching "similar Redis migration timeout":
-- Graph Result 1 ------------------------------------
Source : CLAUDE
Session: Redis migration debugging
Why : Matched extracted topics: topic:Redis, error:timeout
Related: command:docker compose logs api, api:redis.asyncio
suggest_skills
1. Azure Deployment Troubleshooting
ID: skill-4f3a1b2c9e10
Slug: azure-deployment-troubleshooting
Confidence: 0.84
When to use: azure deployment, app service logs, az webapp
Evidence: 4 sessions, 2 source(s)
Why: Repeated deployment/debug workflow with recurring commands and failure modes.
Skill suggestions are not generated skill files. They are ranked, evidence-backed ideas that you can review before creating an actual SKILL.md.
Supported History Sources
| Source | Default location |
|---|---|
| OpenAI Codex CLI | ~/.codex/sessions/ |
| Claude Code | ~/.claude/projects/ |
Override defaults with environment variables:
{
"mcpServers": {
"agent-history": {
"command": "python3",
"args": ["-m", "agent_history_mcp"],
"env": {
"CODEX_PATH": "/custom/path/.codex",
"CLAUDE_PATH": "/custom/path/.claude",
"AGENT_HISTORY_GRAPH_DB": "/custom/path/history_graph.sqlite"
}
}
}
}
If AGENT_HISTORY_GRAPH_DB is not set, the graph database is created at:
~/.agent-history-mcp/history_graph.sqlite
How It Works
Claude Code or another MCP client
calls an MCP tool
agent-history-mcp
refreshes the local graph index for changed JSONL files
parses Codex and Claude sessions into one message shape
searches FTS5/fuzzy index
searches persistent graph index
returns concise excerpts, evidence, and graph explanations
The graph index extracts deterministic local entities:
- sessions
- messages and Q/A turns
- technical topics
- file paths
- commands
- package/API names
- error strings
It stores deterministic EXTRACTED relationships:
- session contains message
- message mentions topic/path/command/API/error
- question answered by assistant response
- topics co-occur in a Q/A pair
- sessions relate through shared extracted topics
New Chat Updates
Every MCP tool call performs a lightweight refresh:
- Discover Codex and Claude JSONL files.
- Compare known files by path, size, and modified time.
- Parse only new or changed files into the graph index.
- Remove indexed rows for deleted history files.
- Invalidate the in-memory keyword cache only when files changed.
New chats become searchable the next time Claude or Codex calls one of the MCP tools.
Benchmarks
Run the local benchmark:
python benchmarks/benchmark_retrieval.py
The benchmark compares:
- full JSONL parsing
- in-memory FTS index build and query
- cold graph index build
- warm graph refresh with unchanged files
- graph search query time
- graph-only candidate expansion versus FTS results
- skill suggestion time
Local Benchmark Results
These numbers were measured on one local Windows laptop against its saved Codex/Claude histories. They are useful as a directional signal, not a universal performance claim.
- Corpus: 43 sessions, 2,434 parsed messages, 2,741,934 message characters
- History files seen: 48
- Query repeat count: 5
- Max results per query: 5
| Operation | Mean / elapsed time | Notes |
|---|---|---|
| Parse JSONL sessions | 676.1 ms | Full parser pass over Codex and Claude history |
| Build in-memory FTS index | 28.5 ms | SQLite FTS5 over parsed messages |
| Cold graph index build | 15,958.6 ms | One-time derived graph build for 43 indexed sessions |
| Warm graph refresh | 20.7 ms | Unchanged files checked by metadata; no JSONL reparse |
| Raw JSONL + FTS rebuild + search | 1,324.1 ms | Mean over 3 representative cold queries |
| Skill suggestion pass | 7,376.1 ms | Returned 5 candidates |
| Query | FTS query ms | Graph query ms | FTS hits | Graph hits | Graph-only hits |
|---|---|---|---|---|---|
history search graph |
0.53 | 3.23 | 5 | 5 | 4 |
git push |
0.73 | 22.35 | 5 | 5 | 4 |
permission denied |
0.35 | 12.06 | 5 | 5 | 1 |
pytest fixture |
0.46 | 0.32 | 0 | 0 | 0 |
redis migration timeout |
0.32 | 22.85 | 2 | 5 | 3 |
azure deployment |
0.15 | 0.24 | 3 | 0 | 0 |
CUDA illegal address |
0.31 | 18.13 | 4 | 5 | 4 |
Across these benchmark queries, FTS returned 24 query-result sessions and graph search returned 25. The graph layer added 16 graph-only candidate sessions that keyword search did not return for the same query set.
Interpretation:
- The speed win is not that graph query beats an already-hot FTS query. Hot FTS is extremely fast.
- The practical speed win is warm refresh: repeated MCP calls check unchanged files in about 20 ms instead of reparsing JSONL and rebuilding search state.
- The retrieval win is candidate expansion: graph search can surface related sessions through extracted relationships even when exact keywords differ.
- Graph-only hits are additional evidence-backed candidates, not guaranteed correct answers.
Security And Privacy
- History sources are read-only:
~/.codexand~/.claudeare never modified. - Indexing is local-only: no network calls or model calls are used.
- Credentials are not read:
~/.codex/auth.jsonis never accessed. - The derived graph database can contain extracted terms and message excerpts for local search.
If past conversations contain secrets, search can surface them because it searches your local history.
Limitations
- Deterministic graph extraction can be noisy, especially for broad or generic topics.
- Skill suggestions are candidates, not guaranteed complete skills.
- The first index build may take time on large histories.
- Search quality depends on the structure and content of your saved Codex and Claude JSONL files.
Development
Run tests:
python -m unittest discover -s tests
Compile check:
python -m py_compile src/agent_history_mcp/*.py tests/*.py
Packaging check:
python -m pip install . --dry-run --no-deps
Benchmark check:
python benchmarks/benchmark_retrieval.py
File Structure
agent-history-mcp/
pyproject.toml
README.md
LICENSE
benchmarks/
benchmark_retrieval.py
src/
agent_history_mcp/
__init__.py
__main__.py
graph.py
parsers.py
search.py
server.py
skills.py
tests/
test_graph.py
test_skills.py
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。