nameforjt-afk/session-knowledge
Turn your Claude Code session history into a searchable local knowledge base — 13 MCP tools, pure stdlib, nothing leaves your machine
session-knowledge — What It Does
session-knowledge is a tool that makes all your past Claude Code sessions searchable, so you can find answers, decisions, and commands you've already used — even when you're working in a different project directory.
Claude Code (an AI coding assistant) saves a transcript of every session you run, but that history is only accessible from the exact folder where it was created. If you switch directories, that memory is effectively lost. This project indexes all those transcripts and gives Claude Code 13 new tools to search them, so you can ask questions like:
- "What was the retry logic in that deploy script?"
- "Which DATABASE_URL did I actually use for staging?"
- "Has anyone here already done payment auth?"
It runs entirely on your machine — no third-party dependencies, no API calls, no data leaves your computer.
The Problem It Solves
- "Have I already built this?" — You can search by external service (e.g., "Stripe") instead of needing to know the exact function name. This works even if you don't remember the internal variable names.
- "How did we decide this?" — Full-text search over all past instructions, filterable to just your own.
- "How did that command go again?" — Every Bash and MCP call is recorded with arguments and results. You can filter to only the ones that failed to recall past mistakes.
- "Which value does this key take?" — When the same variable name has multiple real values (dev vs prod, different apps), it returns all candidates ranked, with the call site each came from, instead of silently picking one.
How It Works
- Claude Code already writes transcripts as JSONL files in
~/.claude/projects/**/*.jsonl. - On each Claude Code start, a hook refreshes the index incrementally (async, non-blocking, usually 1–2 seconds).
- The index is stored in
~/.claude/session-index/and contains three SQLite databases:index.db— full-text search (redacted)vault.db— plaintext credentials (mode 0600)code.db— code symbols and capability tags
- Redaction: Before writing to the full-text index, common credential shapes (API keys, Bearer tokens, JWTs, GitHub PATs, passwords in connection strings) are replaced with
⟦SECRET:fingerprint⟧. Plaintext lives only invault.dband is only returned by an explicitcreds getcommand. - CJK support: For Chinese/Japanese/Korean text, it uses bigram pre-tokenization because FTS5's built-in trigram can't match two-character Chinese words.
Key Features
Search & Retrieval
search_sessions— full-text search across every sessionget_session— page through one session's full transcriptlist_sessions— session metadata (title, project, date, turns)get_timeline— chronological reconstruction of one topicsynthesize_topic— curated excerpts across sessions for summarizingtrack_evolution— how a decision or standard changed, bucketed by monthfind_tool_call— past Bash/MCP calls with arguments;errors_onlyto recall traps
Code Index
find_implementation— existing code by symbol or by external-service tag (e.g., "stripe")list_duplication— what got implemented N times, and which "projects" are forks
Credentials
list_credentials— variable-name registry (never returns values)get_credential— the actual values, all candidates ranked by trustworthinesslookup_secret— resolve a⟦SECRET:fp⟧fingerprint back to its variable name
Index Health
index_stats— coverage and freshness
CLI Commands
You can also use the command line directly:
python3 -m sessionmcp.cli index # incremental refresh
python3 -m sessionmcp.cli stats # index health check
python3 -m sessionmcp.cli search "deploy timeout" # full text (multi-word = AND)
python3 -m sessionmcp.cli tool "stripe" --errors # only failed commands
python3 -m sessionmcp.cli timeline "that migration" # reconstruct how it unfolded
python3 -m sessionmcp.cli code find --capability stripe # who implemented payment auth
python3 -m sessionmcp.cli creds get DATABASE_URL # all candidates, ranked
python3 -m sessionmcp.cli verify-redaction # confirm no plaintext in the index
Search is AND — more words means fewer hits. Use the 2–3 words you would actually have typed back then.
Security & Privacy
- The index directory is restricted to mode 0700; every generated SQLite database, WAL/SHM sidecar, and refresh log is mode 0600.
- Plaintext credentials are stored in
vault.db(mode 0600) — that's the precondition for "which key did I use here" to work. - Never commit or sync the index directory — it contains sensitive data. The repo's
.gitignorecovers the default location. - Redaction is pattern matching, not magic — custom-format secrets can slip through. Run
verify-redactionperiodically. - The
creds forgetcommand permanently blacklists a fake credential (e.g., doc examples) so it won't reappear after re-scanning.
Known Limits
- Only works with Claude Code transcripts — not Cursor, not Copilot.
- Redaction is not perfect — custom secret formats may leak.
- Code index reads only Python/JS/TS (
.py .js .ts .tsx .mjs .jsx). - JS/TS extraction is partial — regex misses some arrow functions and typed declarations.
- First full index of a few hundred sessions takes 1–3 minutes; incremental after that is 1–2 seconds.
- Requires Python 3.10+ with FTS5 compiled into the bundled sqlite3 (macOS system Python sometimes lacks it).
Configuration
Most users need none. To tune, edit sessionmcp/config.py:
CODE_CAPABILITY_PATTERNS— the most useful setting: service tags that drive "find existing implementations by service".PRIVATE_TITLES— session titles to exclude from search._PRIVATE_KEYWORDS— heuristic for personal content.CODE_PROJECT_*— which directories the code index scans.
Which directories get code-indexed? Auto-derived: working directories with ≥2 sessions in the last 45 days, top 30 by session count. If you're new and every project has one session, override with:
export SESSION_KNOWLEDGE_PROJECT_DIRS="~/proj-a:~/proj-b"
Claiming a canonical implementation: You can declare which file is the canonical version of a capability in ~/.claude/knowledge/canonical.json. The generator never overwrites it.
Installation & Uninstall
git clone https://github.com/nameforjt-afk/session-knowledge.git
cd session-knowledge
bash install.sh
Restart Claude Code. Done.
Uninstall:
bash uninstall.sh # remove MCP + hook, keep the index
bash uninstall.sh --purge # remove the index too
License
MIT — see LICENSE.
Related
- Project
- Project
- Project
- Dispatch
- Project